The code below is sending some iproperties to the different parts of the assembly, now I have placed some sub-assemblies as well but the code is not taking in consideration the parts of those sub-assemblies to send the iproperties, can somebody help me to correct the code so it does that as well. basically to send the iproperties in the code to all parts in the assembly and to all the parts of the different sub-assemblies as well.
Thanks in advance
Here is the code:
SyntaxEditor Code Snippet
Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all Of the occurrences Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) Try 'write to component iprops iProperties.Value(oOccurrence, "Project", "Project") = iProperties.Value("Project", "Project") iProperties.Value(oOccurrence, "Project", "Creation Date") = iProperties.Value("Project", "Creation Date") iProperties.Value(oOccurrence, "Summary", "Title") = iProperties.Value("Summary", "Title") iProperties.Value(oOccurrence, "Summary", "Company") = iProperties.Value("Summary", "Company") iProperties.Value(oOccurrence, "Summary", "Author") = iProperties.Value("Summary", "Author") iProperties.Value(oOccurrence, "Custom", "AVT_NUMBER") = iProperties.Value("Custom", "AVT_NUMBER") Catch 'catch errors MsgBox ("ERROR WHEN MAKING LABEL") End Try Next
Solved! Go to Solution.
Solved by bradeneuropeArthur. Go to Solution.
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all Of the occurrences Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences.AllLeafOccurrences Try 'write to component iprops iProperties.Value(oOccurrence, "Project", "Project") = iProperties.Value("Project", "Project") iProperties.Value(oOccurrence, "Project", "Creation Date") = iProperties.Value("Project", "Creation Date") iProperties.Value(oOccurrence, "Summary", "Title") = iProperties.Value("Summary", "Title") iProperties.Value(oOccurrence, "Summary", "Company") = iProperties.Value("Summary", "Company") iProperties.Value(oOccurrence, "Summary", "Author") = iProperties.Value("Summary", "Author") iProperties.Value(oOccurrence, "Custom", "AVT_NUMBER") = iProperties.Value("Custom", "AVT_NUMBER") Catch 'catch errors MsgBox ("ERROR WHEN MAKING LABEL FOR:" & vblf & oOccurrence.Name) End Try Next
I'll try to upload the model as soon as I can, I really appreciate all of your inputs
I got a more detailed code where everything is well passing from the model properties to his parts custom properties, sadly still not passing to the model sub-assemblies custom properties.
Could you please see how to make it work. Really appreciate your help.
SyntaxEditor Code Snippet
Sub Main 'Gets the Active Document oDoc = ThisDoc.Document 'Saves this document oDoc.Save 'Checks if the active document is an assembly If oDoc.DocumentType = kAssemblyDocumentObject 'Gets the assembly occurrences Dim oOccs As ComponentOccurrences oOccs = oDoc.ComponentDefinition.Occurrences 'Call the subprocedure to traverse the assembly Call TraverseAssembly(oOccs) End If End Sub '*************** Public Sub TraverseAssembly(oOccs As ComponentOccurrences) 'Integer to traverse the assembly occurrences Dim i As Integer For i=1 To oOccs.Count Dim oOcc As ComponentOccurrence oOcc = oOccs.Item(i) If oOcc.Suppressed = False 'Occurrence Name (Display Name) oOccName = oOcc.Name 'Gets the first three leters of the Occurrence Name (e.g. "STK") oOccPrefix = Left(oOccName, 3) If oOccPrefix <> "STK" Try iProperties.Value(oOccName, "Project", "Project") = iProperties.Value("Project", "Project") iProperties.Value(oOccName, "Project", "Creation Date") = iProperties.Value("Project", "Creation Date") iProperties.Value(oOccName, "Summary", "Title") = iProperties.Value("Summary", "Title") iProperties.Value(oOccName, "Summary", "Company") = iProperties.Value("Summary", "Company") iProperties.Value(oOccName, "Summary", "Author") = iProperties.Value("Summary", "Author") iProperties.Value(oOccName, "Custom", "AVT_NUMBER") = iProperties.Value("Custom", "AVT_NUMBER") iProperties.Value(oOccName, "Custom", "CAR_NUMBER") = iProperties.Value("Custom", "CAR_NUMBER") iProperties.Value(oOccName, "Custom", "JOB_NAME") = iProperties.Value("Custom", "JOB_NAME") iProperties.Value(oOccName, "Custom", "ToPrint_AVT_NUMBER") = iProperties.Value("Custom", "ToPrint_AVT_NUMBER") iProperties.Value(oOccName, "Custom", "ToPrint_CAR_NUMBER") = iProperties.Value("Custom", "ToPrint_CAR_NUMBER") iProperties.Value(oOccName, "Custom", "ToPrint_JOB_NAME") = iProperties.Value("Custom", "ToPrint_JOB_NAME") iProperties.Value(oOccName, "Custom", "Path_Amada") = iProperties.Value("Custom", "Path_Amada") iProperties.Value(oOccName, "Custom", "Path_Laser") = iProperties.Value("Custom", "Path_Laser") Catch 'It won't be able to change Read-Only parts (e.g. Content Center) 'MessageBox.Show("This is a content center file: " & oOcc.Name, "Title") End Try End If If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Call TraverseAssembly(oOcc.SubOccurrences) End If End If Next End Sub
sorry it took so long... I was doing other things,
Now I have a code that is passing the main assembly custom properties to the parts, but not to the sub-assembly custom properties,
Can you help me with this? thanks,
Sub Main 'Gets the Active Document oDoc = ThisDoc.Document 'Saves this document oDoc.Save 'Checks if the active document is an assembly If oDoc.DocumentType = kAssemblyDocumentObject 'Gets the assembly occurrences Dim oOccs As ComponentOccurrences oOccs = oDoc.ComponentDefinition.Occurrences 'Call the subprocedure to traverse the assembly Call TraverseAssembly(oOccs) End If End Sub '*************** Public Sub TraverseAssembly(oOccs As ComponentOccurrences) 'Integer to traverse the assembly occurrences Dim i As Integer For i=1 To oOccs.Count Dim oOcc As ComponentOccurrence oOcc = oOccs.Item(i) If oOcc.Suppressed = False 'Occurrence Name (Display Name) oOccName = oOcc.Name 'Gets the first three leters of the Occurrence Name (e.g. "STK") oOccPrefix = Left(oOccName, 3) If oOccPrefix <> "STK" Try iProperties.Value(oOccName, "Project", "Project") = iProperties.Value("Project", "Project") iProperties.Value(oOccName, "Project", "Creation Date") = iProperties.Value("Project", "Creation Date") iProperties.Value(oOccName, "Summary", "Title") = iProperties.Value("Summary", "Title") iProperties.Value(oOccName, "Summary", "Company") = iProperties.Value("Summary", "Company") iProperties.Value(oOccName, "Summary", "Author") = iProperties.Value("Summary", "Author") iProperties.Value(oOccName, "Custom", "AVT_NUMBER") = iProperties.Value("Custom", "AVT_NUMBER") iProperties.Value(oOccName, "Custom", "CAR_NUMBER") = iProperties.Value("Custom", "CAR_NUMBER") iProperties.Value(oOccName, "Custom", "JOB_NAME") = iProperties.Value("Custom", "JOB_NAME") iProperties.Value(oOccName, "Custom", "ToPrint_AVT_NUMBER") = iProperties.Value("Custom", "ToPrint_AVT_NUMBER") iProperties.Value(oOccName, "Custom", "ToPrint_CAR_NUMBER") = iProperties.Value("Custom", "ToPrint_CAR_NUMBER") iProperties.Value(oOccName, "Custom", "ToPrint_JOB_NAME") = iProperties.Value("Custom", "ToPrint_JOB_NAME") iProperties.Value(oOccName, "Custom", "Path_Amada") = iProperties.Value("Custom", "Path_Amada") iProperties.Value(oOccName, "Custom", "Path_Laser") = iProperties.Value("Custom", "Path_Laser") Catch 'It won't be able to change Read-Only parts (e.g. Content Center) 'MessageBox.Show("This is a content center file: " & oOcc.Name, "Title") End Try End If If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Call TraverseAssembly(oOcc.SubOccurrences) End If End If Next End Sub
Sub Main 'Gets the Active Document oDoc = ThisDoc.Document 'Saves this document oDoc.Save 'Checks if the active document is an assembly If oDoc.DocumentType = kAssemblyDocumentObject 'Gets the assembly occurrences Dim oOccs As ComponentOccurrences oOccs = oDoc.ComponentDefinition.Occurrences 'Call the subprocedure to traverse the assembly Call TraverseAssembly(oOccs) End If End Sub '*************** Public Sub TraverseAssembly(oOccs As ComponentOccurrences) 'Integer to traverse the assembly occurrences Dim i As Integer'For i=1 To oOccs.CountDim oOcc As ComponentOccurrence
For Each oOcc in oOccs'oOcc = oOccs.Item(i)If oOcc.Suppressed = False 'Occurrence Name (Display Name) oOccName = oOcc.Name 'Gets the first three leters of the Occurrence Name (e.g. "STK") oOccPrefix = Left(oOccName, 3) If oOccPrefix <> "STK" Try iProperties.Value(oOccName, "Project", "Project") = iProperties.Value("Project", "Project") iProperties.Value(oOccName, "Project", "Creation Date") = iProperties.Value("Project", "Creation Date") iProperties.Value(oOccName, "Summary", "Title") = iProperties.Value("Summary", "Title") iProperties.Value(oOccName, "Summary", "Company") = iProperties.Value("Summary", "Company") iProperties.Value(oOccName, "Summary", "Author") = iProperties.Value("Summary", "Author") iProperties.Value(oOccName, "Custom", "AVT_NUMBER") = iProperties.Value("Custom", "AVT_NUMBER") iProperties.Value(oOccName, "Custom", "CAR_NUMBER") = iProperties.Value("Custom", "CAR_NUMBER") iProperties.Value(oOccName, "Custom", "JOB_NAME") = iProperties.Value("Custom", "JOB_NAME") iProperties.Value(oOccName, "Custom", "ToPrint_AVT_NUMBER") = iProperties.Value("Custom", "ToPrint_AVT_NUMBER") iProperties.Value(oOccName, "Custom", "ToPrint_CAR_NUMBER") = iProperties.Value("Custom", "ToPrint_CAR_NUMBER") iProperties.Value(oOccName, "Custom", "ToPrint_JOB_NAME") = iProperties.Value("Custom", "ToPrint_JOB_NAME") iProperties.Value(oOccName, "Custom", "Path_Amada") = iProperties.Value("Custom", "Path_Amada") iProperties.Value(oOccName, "Custom", "Path_Laser") = iProperties.Value("Custom", "Path_Laser") Catch 'It won't be able to change Read-Only parts (e.g. Content Center) 'MessageBox.Show("This is a content center file: " & oOcc.Name, "Title") End Try End If If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Call TraverseAssembly(oOcc.SubOccurrences) End If End If Next End Sub
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
Hi,
Your thanks are appreciated very much.
Regards,
Autodesk Software: Inventor Professional 2018 | Vault Professional 2018 | Autocad Mechanical 2018
Programming Skills: Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Dimension Component! | Partlist Export! | Derive I-properties! | Vault Prompts Via API! | Vault Handbook/Manual!
Drawing Toggle Sheets! | Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
Can't find what you're looking for? Ask the community or share your knowledge.