Change member of iassembly placed within Parent Assembly

Change member of iassembly placed within Parent Assembly

MarkyTomm
Enthusiast Enthusiast
238 Views
2 Replies
Message 1 of 3

Change member of iassembly placed within Parent Assembly

MarkyTomm
Enthusiast
Enthusiast

Hi  again,

 

I am trying to change the member of an iassembly which has been placed into my parent assembly

Just trying to change the member as the moment to row 1

Placed iassembly factory file is name is "Trap iassy.iam"

I am getting a bit wraped up with the nested level of assembly componet definitions etc

My code so far goes like this 

Public Sub ChangeAssemblyMemeber()
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oAssemblyComponent As AssemblyComponentDefinition
    Set oAssemblyComponent = oDoc.ComponentDefinition
    
    Dim oSubAssemblyComponent As AssemblyComponentDefinition
    
    For Each oAssemblyComponent In oDoc.ComponentDefinition.Occurrences
    
        If oAssemblyComponent.IsiAssemblyFactory Then
        Set oSubAssemblyComponent = oAssemblyComponent
        
            If oSubAssemblyComponent.name = "Trap iassy.iam" Then
                oSubAssemblyComponent.ChangeRowOfiAssemblyMember (1)
            End If
        End If
    Next
End Sub

 

Anybody able to point me in the right direction please

 

Regards

MArk

0 Likes
239 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @MarkyTomm.  Try something like this.  This only looks in the top level components for the iAssemblyMember component, but if it finds it, it calls the 'method' that is just for changing which 'row' of its parent iAssemblyFactory it is representing.

 

Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Logger.Debug(iLogicVb.RuleName & " exited (no AssemblyDocument obtained)") : Return
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim oOccs As ComponentOccurrences = oADef.Occurrences
	For Each oOcc As ComponentOccurrence In oOccs
		If oOcc.IsiAssemblyMember AndAlso oOcc.Name.StartsWith("Trap iassy") Then
			oOcc.ChangeRowOfiAssemblyMember(1)
		End If
	Next oOcc
	oADoc.Update2(True)
End Sub

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Oops.  I wrote an iLogic rule, but your original code looks like a VBA macro, so what I posted will not work directly, without a bunch of changes.  You can probably tell the differences in the object types I am working with in this code example though, which is the main thing that would need to be changed in your original code.  The individual components within an assembly are ComponentOccurrence type objects, not AssemblyComponentDefinition objects.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

WCrihfield
Mentor
Mentor

Here is an edited version of your original code, in VBA.  Sorry about that.  I moved all my Inventor automation solutions away from VBA to iLogic and vb.net years ago, due to the multiple factors.

 

Public Sub ChangeAssemblyMemeber()
    Dim oADoc As AssemblyDocument
    Set oADoc = ThisApplication.ActiveDocument

    Dim oADef As AssemblyComponentDefinition
    Set oADef = oDoc.ComponentDefinition

    Dim oOccs As ComponentOccurrences
    Set oOccs = oADef.Occurrences
    
    Dim oOcc As ComponentOccurrence
    For Each oOcc In oOccs
        If oOcc.IsiAssemblyFactory Then
            If Strings.InStr(1, oOcc.Name, "Trap iassy", vbTextCompare) > 0 Then
                Call oOcc.ChangeRowOfiAssemblyMember(1)
            End If
        End If
    Next
End Sub

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes