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

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

Anonymous
Not applicable
1,920 Views
8 Replies
Message 1 of 9

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

Anonymous
Not applicable

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.

0 Likes
Accepted solutions (1)
1,921 Views
8 Replies
Replies (8)
Message 2 of 9

FINET_Laurent
Advisor
Advisor

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

0 Likes
Message 3 of 9

FINET_Laurent
Advisor
Advisor

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

0 Likes
Message 4 of 9

Anonymous
Not applicable

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 .

0 Likes
Message 5 of 9

Anonymous
Not applicable
Accepted solution

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. 

 

0 Likes
Message 6 of 9

Anonymous
Not applicable

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

0 Likes
Message 7 of 9

Anonymous
Not applicable

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)

...

 

0 Likes
Message 8 of 9

Anonymous
Not applicable

Nevermind sir, I found the solution.

0 Likes
Message 9 of 9

mseveroLXMQ8
Participant
Participant

What's the solution?

0 Likes