Reply
Solved! Go to solution

Item Value of occurence

[ Edited ]

Hello,

 

I am trying to automate replacing parts in an assembly. I have got the basic program down on how to replace a part. The problem I'm currently having is figuring out which item value belongs to a occurence.

since I intent to use this automation on assemblies that do not always have the same layout for the occurences I can't keep it as one single Item value.

 

is there a way to search for a occurence (by file name) in an assembly and retrieve it's item value. so I can use that value to use when replacing it?

 

File locations are retrieved from an excel sheet.

 

Private Sub Update_Click()

Dim objApp As SolidEdgeFramework.Application
Dim objDoc As SolidEdgeAssembly.AssemblyDocument
Dim objVars As Variables
Dim objPart As SolidEdgeAssembly.Occurrence
Dim objParts As SolidEdgeAssembly.Occurrences
Dim ItemNumber As SolidEdgeAssembly.AssemblyProperty
Dim ItemNumbers As SolidEdgeAssembly.AssemblyProperties

Dim GA_Drawing As String
Dim MP2Demper As String
Dim MP3Demper As String
Dim MP4Demper As String
Dim MP5Demper As String
Dim NewPart As String

  GA_Drawing = CStr(Range("B9").Value)
  NewPart = CStr(Range("O29").Value)
  MP2Demper = "MP2.par"
  MP3Demper = "MP3.par"
  MP4Demper = "MP4.par"
  MP5Demper = "MP5.par"
  
  Set objApp = GetObject(, "SolidEdge.Application")

  If Err Then
    Err.Clear
    Set objApp = CreateObject("SolidEdge.Application")
    Set objDoc = objApp.Documents.Add("SolidEdge.AssemblyDocument")

    objApp.Visible = True

  Else
    Set objDoc = objApp.ActiveDocument
  End If
  objApp.DisplayAlerts = False
    
   
    Set objDoc = objApp.Documents.Open(GA_Drawing)
    Set objParts = objDoc.Occurrences
    Set objPart = objDoc.Occurrences.Item(10)
    
    Call objPart.Replace(NewPart, True)
    
  Set objApp = Nothing
  Set objDoc = Nothing
  Set objVars = Nothing
  Set objPart = Nothing
  Set objParts = Nothing

End Sub

 

I hope someone has a solution for this problem Smiley Happy

3 REPLIES

Re: Item Value of occurence

[ Edited ]

When you get the item occurences collection, you will have to loop through them all until you match the one you want.  As this is an API question, you will get better responses by posting to the Solid Edge Developer forum.


Thanks,
Ken

Production: ST9 MP7
Testing: ST10
Solution
Solution
Accepted by topic author Rowan
‎05-03-2016 09:06 AM

Re: Item Value of occurence

You can browse the Occurrences collection queering the "FullName" property of each Item.OccurenceDocument Collection.

 

    Set objParts = objDoc.Occurrences
    
For each Item in objParts
If Item.OccurrenceDocument.FullName = "D:\Parts\MyPart.par" Then
Item.Replace(NewPart, True)
Exit For
End If
Next Item

 

Re: Item Value of occurence

[ Edited ]

Thanks alot! 

 

 

changed it a bit to:

 

 If Item.OccurrenceDocument.Name = "MyPart.par" Then

 

 So it only looks for the actual part name.