I Have a assembly and I just one to change part number form 00 - 99, with order from up to down (please look at the picture).
I tried the code , but it open all file in assembly with a random order, it's hard to fill all part number. In addition, is there possible to access just top level parts? (Not the parts inside level 2-assembly)
openDoc = ThisApplication.ActiveDocument
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments
Next
Please help.
Solved! Go to Solution.
What do you mean when changing par number?
From what I understand :
Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oOccurrence As ComponentOccurrence Dim iInteger As Integer = 0 Dim oStr As String For Each oOccurrence In oAsmCompDef.Occurrences iInteger = iInteger + 1 oStr = iInteger oOccurrence.Name = oStr Next
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'll add the 00.
Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oOccurrence As ComponentOccurrence Dim iInteger As Integer = 0 Dim oStr As String For Each oOccurrence In oAsmCompDef.Occurrences iInteger = iInteger + 1 If iInteger < 10 Then oStr = "0" & iInteger Else If iInteger > 9 Then oStr = iInteger End If oOccurrence.Name = oStr Next
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"thank you for reply.
I meant I wanted to set part number in order (from up to down). Like 00.01, 00.02, 00.03 ...; But my code access to parts randomly, doesn't go from up to down, and it accesses to all assembly documents and the parts inside them too. I just want to access to all parts on top-level .
Hi @Anonymous . Try this:
Dim oDoc As AssemblyDocument = ThisAssembly.Document Dim newPartNum As Integer = 0 Dim asmDef = oDoc.ComponentDefinition For Each occ As ComponentOccurrence In asmDef.Occurrences Dim occDoc As Document = occ.Definition.Document newPartNum = newPartNum + 1 occDoc.PropertySets("Design Tracking Properties")("Part Number").Value = "Text " & newPartNum & " AnotherText" Next
After running the code, right click the parts and check the iproperties.
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.Property.set_Value(Object )
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
...
Can't find what you're looking for? Ask the community or share your knowledge.