I need to copy all custom iproperties from main assembly to all lower assemblies in it. if they are not there then add them. been beating my head against the wall with this one. I'm missing something that should be easy to do.
Solved! Go to Solution.
Solved by FINET_Laurent. Go to Solution.
Hi @_bmiller_,
Here is a sample code of mine that would loop through each occurences of an assembly (top node only) and add the custom iProperties of the assembly the rule is fired from. If a property already exists, it skips it, preventing errors & override :
Dim doc As Inventor.AssemblyDocument = ThisApplication.ActiveDocument
Dim acd As Inventor.AssemblyComponentDefinition = doc.ComponentDefinition
For Each p As Inventor.Property In doc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
For Each occ As Inventor.ComponentOccurrence In acd.Occurrences
Dim occDoc As Inventor.Document = occ.ReferencedDocumentDescriptor.ReferencedDocument
Dim cpset As Inventor.PropertySet = occDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
Dim exist As Boolean = False
For Each op As Inventor.Property In cpset
If op.Name = p.Name Then
exist = True
Exit For
End If
Next
If exist = True Then Continue For
cpset.Add(p.Value, p.Name)
Next
Next
Does this suits your needs ?
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"Reading twice, I'm not so sure about your question. Do we have to copy the iProperties only to sub assemblies, or are parts included ? What is the sub assembly has sub-assemblies ? Do we also consider them ?
If we say yes to all questions, here would be the code :
Dim doc As Inventor.AssemblyDocument = ThisApplication.ActiveDocument
Dim acd As Inventor.AssemblyComponentDefinition = doc.ComponentDefinition
For Each p As Inventor.Property In doc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
For Each occDoc As Inventor.Document In doc.AllReferencedDocuments
If occDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Continue For
Dim cpset As Inventor.PropertySet = occDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
Dim exist As Boolean = False
For Each op As Inventor.Property In cpset
If op.Name = p.Name Then
exist = True
Exit For
End If
Next
If exist = True Then Continue For
cpset.Add(p.Value, p.Name)
Next
Next
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"And finally, if we only want to consider the top nodes sub-assemblies, here would be the code :
Dim doc As Inventor.AssemblyDocument = ThisApplication.ActiveDocument
Dim acd As Inventor.AssemblyComponentDefinition = doc.ComponentDefinition
For Each p As Inventor.Property In doc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
For Each occ As Inventor.ComponentOccurrence In acd.Occurrences
Dim occDoc As Inventor.Document = occ.ReferencedDocumentDescriptor.ReferencedDocument
If occDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Continue For
Dim cpset As Inventor.PropertySet = occDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
Dim exist As Boolean = False
For Each op As Inventor.Property In cpset
If op.Name = p.Name Then
exist = True
Exit For
End If
Next
If exist = True Then Continue For
cpset.Add(p.Value, p.Name)
Next
Next
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"this is what i got so far
' Get the main assembly document Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument ' Get the custom properties of the main assembly Dim oMainPropSet As PropertySet oMainPropSet = oAsmDoc.PropertySets.Item("Inventor User Defined Properties") ' Iterate over all the sub-assemblies For Each oSubAsm In oAsmDoc.AllReferencedDocuments ' Skip if the referenced document is not an assembly If oSubAsm.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Continue For End If ' Get the custom properties of the sub-assembly Dim oSubPropSet As PropertySet oSubPropSet = oSubAsm.PropertySets.Item("Inventor User Defined Properties") ' Iterate over all properties in the main assembly For Each oMainProp In oMainPropSet ' Check if the property exists in the sub-assembly Dim oSubProp As [Property] = Nothing Try oSubProp = oSubPropSet.Item(oMainProp.Name) Catch ex As Exception ' Property doesn't exist, do nothing End Try ' If the sub-assembly doesn't have the property, add it If oSubProp Is Nothing Then oSubPropSet.Add(oMainProp.Value, oMainProp.Name) Else ' If the property exists, copy the value from the main assembly oSubProp.Value = oMainProp.Value End If Next Next
, it works for the most part but i get unspecified errors sometimes and cant find the error
Hi @_bmiller_,
By looking at the code you provided us, I can see that you are using try/catches. I would rather use a small check with a loop in the properties to see if we find a match, than intentionally firing an exception. The code I posted above in my thrid post accomplish the exact same as your, with the small improved I'm explaining right now.
Can you test it out and give us feed back?
Thank you & kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"
I just found a small error on line 7. It was different instead of equals. Fixed it :
Dim doc As Inventor.AssemblyDocument = ThisApplication.ActiveDocument
Dim acd As Inventor.AssemblyComponentDefinition = doc.ComponentDefinition
For Each p As Inventor.Property In doc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
For Each occ As Inventor.ComponentOccurrence In acd.Occurrences
Dim occDoc As Inventor.Document = occ.ReferencedDocumentDescriptor.ReferencedDocument
If occDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Continue For
Dim cpset As Inventor.PropertySet = occDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
Dim exist As Boolean = False
For Each op As Inventor.Property In cpset
If op.Name = p.Name Then
exist = True
Exit For
End If
Next
If exist = True Then Continue For
cpset.Add(p.Value, p.Name)
Next
Next
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"That does first layer only, small mod will catch lower layers as well.
thanks
Can't find what you're looking for? Ask the community or share your knowledge.