Howto Suppress link to derived parts inside assm?

Howto Suppress link to derived parts inside assm?

Anonymous
Not applicable
1,393 Views
10 Replies
Message 1 of 11

Howto Suppress link to derived parts inside assm?

Anonymous
Not applicable
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
0 Likes
1,394 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
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
0 Likes
Message 3 of 11

Anonymous
Not applicable
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
0 Likes
Message 4 of 11

Anonymous
Not applicable
What about using the AllReferencedDocuments property to iterate through all parts at all levels.
0 Likes
Message 5 of 11

Anonymous
Not applicable
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
0 Likes
Message 6 of 11

Anonymous
Not applicable
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
Not applicable
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
Community Manager
Community Manager

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

 


Customer Adoption Specialist: Autodesk Informed Design
Help | Learn | Forum | Blog | Ideas | Sample content | Linkedin 

Message 9 of 11

Anonymous
Not applicable

HI ALL!

 

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

0 Likes
Message 10 of 11

adam.nagy
Autodesk Support
Autodesk Support

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
0 Likes
Message 11 of 11

Anonymous
Not applicable

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