iLogic: Customizing occurrence name by adding Assembly PN

iLogic: Customizing occurrence name by adding Assembly PN

JreyesGQ5VQ
Explorer Explorer
1,713 Views
5 Replies
Message 1 of 6

iLogic: Customizing occurrence name by adding Assembly PN

JreyesGQ5VQ
Explorer
Explorer

Hello all,

 

Just starting to incorporate iLogic to automate some workflows. I have a pretty good start from going through the forums, but need some help with one last detail.

 

My current code (attached) goes through all first-level items and renames them to the format 'PN - Description'. What I would also like to do is rename any second-level items if they have "- base" in their occurrence name to 'firstlevelPN - base'. The base part would essentially pull the PN of the assembly it is in. Essentially the ideal output would look something like below:

 

TopAssy

       > FirstLevelPN - Description

              > FirstLevelPN - base

 

Thanks in advance for any help

 

0 Likes
Accepted solutions (1)
1,714 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

You should be able to add another For Each into your current one for sub occurrences and use the Part Number of the parent assembly. You seem to have a good grasp on how you want to name them, so I'm not going to write an entire block of code.

I'm not sure why you are using the browser node name instead of the ComponentOccurrence.Name, I don't know if there is a difference though.

 

Hopefully this is what you're looking for

 

Dim oOcc As ComponentOccurrence
For Each oOcc In oDoc.ComponentDefinition.Occurrences

......naming code.....

   For Each oSubOcc as ComponentOccurrence in oOcc.SubOccurrences

   ...naming code...
   oSubOcc.Name = invPartNumberProperty.Value & " - base"

   Next

Next

 

0 Likes
Message 3 of 6

_dscholtes_
Advocate
Advocate

@JreyesGQ5VQ 

I'm also curious why you change the browser node name instead of the ComponentOccurrence.Name
(I have even found an script that changes the Document.DisplayName in order to change the occurrence name.)

0 Likes
Message 4 of 6

JreyesGQ5VQ
Explorer
Explorer

@Anonymous Thanks for the suggestion on adding another For Each. @_dscholtes_ I honestly copied this code from somewhere in the forum, and modified it to add description instead of just PN. So I don't exactly know why browser node names are used instead. My guess is it has something to do with the counter number? 

 

Do you know what I can use to search the sub parts for " - base" in the current occurrence name? My intention is to only rename these. 

0 Likes
Message 5 of 6

Anonymous
Not applicable
Accepted solution

Well if using the browser node works the way you want, I guess there is no reason to change it.

 

To check the Occurrence name is simple, just need a .Contains.

 

Dim oOcc As ComponentOccurrence
For Each oOcc In oDoc.ComponentDefinition.Occurrences

......naming code.....

   For Each oSubOcc as ComponentOccurrence in oOcc.SubOccurrences

   If oSubOcc.Name.Contains(" - base") Then

     ...naming code...
     oSubOcc.Name = invPartNumberProperty.Value & " - base"

   End If

   Next

Next

 

0 Likes
Message 6 of 6

_dscholtes_
Advocate
Advocate

Put this in the For-Each oSubOcc loop:

If oSubOcc.Name Like "* - base*" Then
    <do your renaming here>
End If

 

or

If InStr(1, oSubOcc.Name, " - base") > 0 Then
   <do your renaming here>
End If

 

 

0 Likes