iLogic: merge iProperties and add sequence numbers

iLogic: merge iProperties and add sequence numbers

Log0ut
Enthusiast Enthusiast
480 Views
3 Replies
Message 1 of 4

iLogic: merge iProperties and add sequence numbers

Log0ut
Enthusiast
Enthusiast

Hi

I need little bit help here.

I want to merge assembly 'Part Number' and child parts 'Description'.

Example:

Assembly - Part number: '01'

Part - Description: 'side'

Part - Description: 'top'

Part - Description: 'bottom'


Result be '01_01_side'; '01_02_top'; '01_03_bottom'


I have some code together,but if i have two same parts in an assembly, code reads them also twice

(example: 1x top, 1x bottom, 2x side - 01_01_top, 01_02_bottom, 01_04_side)

 

 

 

Dim oOcc As ComponentOccurrence
Dim oAss As AssemblyDocument
oAss = ThisDoc.Document

For Each oOcc In oAss.ComponentDefinition.Occurrences
oPart = oOcc.Name

Description = iProperties.Value(oPart, "Project", "Description")
PartNumber = iProperties.Value(oAss, "Project", "Part Number")
NewName = PartNumber & "_" & oNR & "_" & Description

If Not Description = "" Then
iProperties.Value(oPart, "Project", "Part number") = NewName
End If

oNR = oNR + 1

If oNR < 10 Then
            oNR = "0" + CStr(oNR)
    Else
            oNR = CStr(oNR)
End If

Next

 

 

 

 

0 Likes
481 Views
3 Replies
Replies (3)
Message 2 of 4

Stakin
Collaborator
Collaborator

If Not Description = "" and iProperties.Value(oPart, "Project", "Part number") <> NewName Then

iProperties.Value(oPart, "Project", "Part number") = NewName

End If

0 Likes
Message 3 of 4

WCrihfield
Mentor
Mentor

Just a few general suggestions.

You can move the line that gets the assembly's part number up above the loop, because you only need to get that once.  Also, when using that iLogic snippet to get the iProperty from the main assembly, you don't need to put oAss as the first (of 3) input variables.  If you leave that out, and just use the last two variables, it will by default get that iProperty from the assembly, because it is the 'active' document.  I also noticed that you are incorporating the variable 'oNR' into the 'NewName' variable's value, but that 'oNR' variable has not been created/defined yet at that point in the code, so I suggest creating/defining that variable and setting its initial value, above the loop.  I also agree that the check for the current value of 'Description' may need to be changed a bit too.

Here's a slightly edited version of your code as a suggestion of the things mentioned above.

Dim oAss As AssemblyDocument = ThisDoc.Document
Dim PartNumber As String = iProperties.Value("Project", "Part Number")
Dim oOcc As ComponentOccurrence
Dim oNR As Integer = 1
For Each oOcc In oAss.ComponentDefinition.Occurrences
	oOccName = oOcc.Name
	Description = iProperties.Value(oOccName, "Project", "Description")
	NewName = PartNumber & "_" & oNR & "_" & Description

	If Not Description = "" Then
		iProperties.Value(oOccName, "Project", "Part number") = NewName
	End If

	oNR = oNR + 1
	If oNR < 10 Then
		oNR = "0" + CStr(oNR)
	Else
		oNR = CStr(oNR)
	End If
Next

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 4

WCrihfield
Mentor
Mentor

Also, it looks like you are converting your variable 'oNR' from a numerical integer to a String.  Once you do that, it is no longer numerical, so you can't do math with it anymore.  You can incorporate Integers into Strings just fine the way you have your 'NewName' line laid out, but I believe that converting 'oNR' into a String may be causing problems too if it goes beyond 2.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes