Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ILogic/ VBA, How can I access to all parts properties in assembly from up to down?

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Anonymous
1597 Views, 8 Replies

ILogic/ VBA, How can I access to all parts properties in assembly from up to down?

image.png 

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.

Labels (2)
8 REPLIES 8
Message 2 of 9
FINET_Laurent
in reply to: Anonymous

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"

@LinkedIn     @JohnCockerill

Message 3 of 9

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"

@LinkedIn     @JohnCockerill

Message 4 of 9
Anonymous
in reply to: FINET_Laurent

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 .

Message 5 of 9
Anonymous
in reply to: Anonymous

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. 

 

Message 6 of 9
Anonymous
in reply to: Anonymous

Thank you sir, but your code doesnt work. "part number" cant write on. but thank you anyway.

Message 7 of 9
Anonymous
in reply to: Anonymous

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)

...

 

Message 8 of 9
Anonymous
in reply to: Anonymous

Nevermind sir, I found the solution.

Message 9 of 9
mseveroLXMQ8
in reply to: Anonymous

What's the solution?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report