Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Howto Suppress link to derived parts inside assm?

10 REPLIES 10
Reply
Message 1 of 11
brian
1076 Views, 10 Replies

Howto Suppress link to derived parts inside assm?

Hi Guys,
I am having some trouble with this quick VBA app, I want a utility that can traverse all the parts in a top level assembly and suppress the link to each derived part (multiple) in all the parts in the assembly.

I have played with the following code:

Public Sub SuppressLink()
Dim partdoc As PartDocument
Set partdoc = ThisApplication.ActiveDocument
partdoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1).SuppressLinkToFile = True
End Sub

Which works, but only on one part file, and only on the first derived part. Is there any easy way to make this work on ALL the dervived links and every single part inside an assembly?

Thanks for any help.
Brian Corbin
10 REPLIES 10
Message 2 of 11
Anonymous
in reply to: brian

You can use below VBA sample to traverse all the 2nd level parts in a top
level assembly and suppress the link to each derived part in the 2nd level
parts. You will need to iterate the ComponentOccurrence.SubOccurrences
property to get the deep level documents if you want to suppress the derived
part in deep level parts as well.

Sub SuppressLinkToFile()
' Get the top level assembly document
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

' Set a reference to the assembly component definition
Dim oComp As AssemblyComponentDefinition
Set oComp = oDoc.ComponentDefinition

' Loop each component occurrence to get its document
Dim oOcc As ComponentOccurrence
For Each oOcc In oComp.Occurrences
Dim oPartDoc As Document
Set oPartDoc = oOcc.Definition.Document

If TypeOf oPartDoc Is PartDocument Then
' Set a reference to the part component definition
Dim oPartComp As PartComponentDefinition
Set oPartComp = oPartDoc.ComponentDefinition

' Loop each derived part component in this part document
Dim oDerPartComp As DerivedPartComponent
For Each oDerPartComp In
oPartComp.ReferenceComponents.DerivedPartComponents
oDerPartComp.SuppressLinkToFile = True
Next
End If
Next
End Sub

Thanks,
Frodo

wrote in message news:5792712@discussion.autodesk.com...
Hi Guys,
I am having some trouble with this quick VBA app, I want a utility that can
traverse all the parts in a top level assembly and suppress the link to each
derived part (multiple) in all the parts in the assembly.

I have played with the following code:

Public Sub SuppressLink()
Dim partdoc As PartDocument
Set partdoc = ThisApplication.ActiveDocument
partdoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1).SuppressLinkToFile
= True
End Sub

Which works, but only on one part file, and only on the first derived part.
Is there any easy way to make this work on ALL the dervived links and every
single part inside an assembly?

Thanks for any help.
Brian Corbin
Message 3 of 11
brian
in reply to: brian

Hi Frodo,
I managed to hack this together using the sample files, but when I run it on the top level assm I get the following error message in VBA:

"Runtime error 28"
"Out of stack space"
Any ideas why this does not work? Otherwise I will have to look closer at your code to see how I can keep diggin thru all the sub assms etc.


Public Sub SuppressLink()

Dim assm As AssemblyDocument
Set assm = ThisApplication.ActiveDocument

Dim occ As ComponentOccurrence
Dim derpart As DerivedPartComponent
Dim partdoc As PartDocument

For Each occ In assm.ComponentDefinition.Occurrences
If occ.DefinitionDocumentType = kPartDocumentObject Then
For Each derpart In occ.Definition.ReferenceComponents.DerivedPartComponents
derpart.SuppressLinkToFile = True
Next
ElseIf occ.DefinitionDocumentType = kAssemblyDocumentObject Then
Call processAllSubOcc(occ, derpart) ' subassembly

End If
Next

End Sub
' This function is called for processing sub assembly. It is called recursively
' to iterate through the entire assembly tree.
Private Sub processAllSubOcc(ByVal occ As ComponentOccurrence, derpart As DerivedPartComponent)


Dim oSubCompOcc As ComponentOccurrence
For Each oSubCompOcc In occ.SubOccurrences
' Check if it's child occurrence (leaf node)
If oSubCompOcc.SubOccurrences.Count = 0 Then
For Each derpart In oSubCompOcc.Definition.ReferenceComponents.DerivedPartComponents
derpart.SuppressLinkToFile = True
Next
Else

Call processAllSubOcc(occ, derpart) ' subassembly
End If
Next
End Sub
Message 4 of 11
Patroni
in reply to: brian

What about using the AllReferencedDocuments property to iterate through all parts at all levels.
Message 5 of 11
Anonymous
in reply to: brian

That's because processAllSubOcc will run into dead loop if the top assembly
contains deep level assembly occurrence. Could you try below code instead?

Public Sub SuppressLink()

Dim assm As AssemblyDocument
Set assm = ThisApplication.ActiveDocument

Dim occ As ComponentOccurrence
Dim derpart As DerivedPartComponent
Dim partdoc As PartDocument

For Each occ In assm.ComponentDefinition.Occurrences
If occ.DefinitionDocumentType = kPartDocumentObject Then
For Each derpart In
occ.Definition.ReferenceComponents.DerivedPartComponents
derpart.SuppressLinkToFile = True
Next
ElseIf occ.DefinitionDocumentType = kAssemblyDocumentObject Then
Call processAllSubOcc(occ) ' subassembly
End If
Next

End Sub
' This function is called for processing sub assembly. It is called
recursively
' to iterate through the entire assembly tree.
Private Sub processAllSubOcc(ByRef occ As ComponentOccurrence)

Dim derpart As DerivedPartComponent
Dim oSubCompOcc As ComponentOccurrence
For Each oSubCompOcc In occ.SubOccurrences
' Check if it's child occurrence (leaf node)
If oSubCompOcc.DefinitionDocumentType = kPartDocumentObject Then
For Each derpart In
oSubCompOcc.Definition.ReferenceComponents.DerivedPartComponents
derpart.SuppressLinkToFile = True
Next
ElseIf occ.DefinitionDocumentType = kAssemblyDocumentObject Then
Call processAllSubOcc(occ) ' subassembly
End If
Next

End Sub

Thanks,
Frodo
Message 6 of 11
brian
in reply to: brian

Hi Frodo,
I tried your code but it gave me the same error message. What about the allrefdoc suggestion, would this run the code on all referenced parts?
Message 7 of 11
Anonymous
in reply to: brian

I'm a little bit surprised about that for I've tried the code with a sample
file (with deep assembly occurrence) and it works well. You can attach your
testing file in zip format if possbile, so that I can take a look into the
underlying problem.
Yes, you can run the code on all referenced parts as well, in that way you
don't need to write the iterative function, just one loop should be enough.

Thanks,
Frodo
Message 8 of 11
PaulMunford
in reply to: Anonymous

Thanks very much to both of you for your code.

 

I hacked it into this code - which iterates through the assembly un-suppressing the link, updating the part and then suppressing the link again.

 

It's not pretty but it did the job, if any one has any advice or tips - I'm all ears!

 

Sub Main()
Dim assm As AssemblyDocument
assm = ThisApplication.ActiveDocument

Dim occ As ComponentOccurrence
Dim derpart As DerivedPartComponent
Dim partdoc As PartDocument

For Each occ In assm.ComponentDefinition.Occurrences
If occ.DefinitionDocumentType = kPartDocumentObject Then
For Each derpart In occ.Definition.ReferenceComponents.DerivedPartComponents

'My Code
If derpart.SuppressLinkToFile = True Then
derpart.SuppressLinkToFile= False

Else derpart.SuppressLinkToFile = True

End If

derpart.SuppressLinkToFile = True

iLogicVb.UpdateWhenDone = True

Next
ElseIf occ.DefinitionDocumentType = kAssemblyDocumentObject Then
Call processAllSubOcc(occ) ' subassembly
End If
Next

End Sub


' This function is called for processing sub assembly. It is called recursively
' to iterate through the entire assembly tree.
Sub processAllSubOcc(ByRef occ As ComponentOccurrence)

Dim derpart As DerivedPartComponent
Dim oSubCompOcc As ComponentOccurrence
For Each oSubCompOcc In occ.SubOccurrences
' Check if it's child occurrence (leaf node)
If oSubCompOcc.DefinitionDocumentType = kPartDocumentObject Then
For Each derpart In occ.Definition.ReferenceComponents.DerivedPartComponents
'My Code
If derpart.SuppressLinkToFile = True Then
derpart.SuppressLinkToFile= False

Else derpart.SuppressLinkToFile = True

End If

derpart.SuppressLinkToFile = True

iLogicVb.UpdateWhenDone = True
Next
ElseIf occ.DefinitionDocumentType = kAssemblyDocumentObject Then
Call processAllSubOcc(occ) ' subassembly
End If
Next

End Sub

 

 


Autodesk Industry Marketing Manager UK D&M
Opinions are my own and may not reflect those of my company.
Linkedin Twitter Instagram Facebook Pinterest

Message 9 of 11

HI ALL!

 

Anybody have a code to replace a linking parameter from a part in assemblyPARAMETER LINK.JPG???

Message 10 of 11
adam.nagy
in reply to: ChristinaForest

Hi,

 

I think this question should be logged in a new thread. 🙂

 

And could you mention there what you mean by replace? Do you just want to rename a parameter?

In that case you could simply change it in the part, save it, and then update the assembly.

 

If that's not what you meant, then if you could just tell what you are doing in the user interface to achieve what you need, that would help.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 11 of 11
an2nymous
in reply to: Anonymous

I also have almost the same problem. But I have a little different scenario.

 

I have a sketch based assembly with multiple parts (front). I mirrored the parts on the other side of the assembly (rear). Whatever

changes i do on the front parts, the rear parts just follow. Now, I want to suppress the link between front and the rear parts so that I can make changes to both of them independently. I want to do this to specific parts only in the assembly. However, there will be an instance that I will need to unsuppress the link again.

 

I hope you can help me modify the codes to fit my needs.


@Anonymous wrote:
You can use below VBA sample to traverse all the 2nd level parts in a top
level assembly and suppress the link to each derived part in the 2nd level
parts. You will need to iterate the ComponentOccurrence.SubOccurrences
property to get the deep level documents if you want to suppress the derived
part in deep level parts as well.

Sub SuppressLinkToFile()
' Get the top level assembly document
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

' Set a reference to the assembly component definition
Dim oComp As AssemblyComponentDefinition
Set oComp = oDoc.ComponentDefinition

' Loop each component occurrence to get its document
Dim oOcc As ComponentOccurrence
For Each oOcc In oComp.Occurrences
Dim oPartDoc As Document
Set oPartDoc = oOcc.Definition.Document

If TypeOf oPartDoc Is PartDocument Then
' Set a reference to the part component definition
Dim oPartComp As PartComponentDefinition
Set oPartComp = oPartDoc.ComponentDefinition

' Loop each derived part component in this part document
Dim oDerPartComp As DerivedPartComponent
For Each oDerPartComp In
oPartComp.ReferenceComponents.DerivedPartComponents
oDerPartComp.SuppressLinkToFile = True
Next
End If
Next
End Sub

Thanks,
Frodo

wrote in message news:5792712@discussion.autodesk.com...
Hi Guys,
I am having some trouble with this quick VBA app, I want a utility that can
traverse all the parts in a top level assembly and suppress the link to each
derived part (multiple) in all the parts in the assembly.

I have played with the following code:

Public Sub SuppressLink()
Dim partdoc As PartDocument
Set partdoc = ThisApplication.ActiveDocument
partdoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents.Item(1).SuppressLinkToFile
= True
End Sub

Which works, but only on one part file, and only on the first derived part.
Is there any easy way to make this work on ALL the dervived links and every
single part inside an assembly?

Thanks for any help.
Brian Corbin

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report