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
HI ALL!
Anybody have a code to replace a linking parameter from a part in assembly???
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,
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