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: 

Inventor Part occurrence name

8 REPLIES 8
Reply
Message 1 of 9
dclunie
4691 Views, 8 Replies

Inventor Part occurrence name

I have several parts that are controlled by ilogic rules linked to member names ,and in some cases some of staff run the productivity bonus tool (rename browser nodes) to either file name or part number.

This causes the rules to fail as rules definition name have been overwritten.

 

I am after a simple rule that is triggered on save to save my occurrence browser name to what originally was defined

 

Dim Browsername As String = Plywood 01

 

Any help on this would be appreciated

 

 

Member names example

Plywood 01

Plywood 02

Plywood 03

Plywood 04

 

Regards

 

Dave

 

Tags (2)
8 REPLIES 8
Message 2 of 9
Curtis_Waguespack
in reply to: dclunie

Hi dclunie,

 

I think this iLogic snippet does what you're after.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com


 

oName = InputBox("Enter a Name", "iLogic", "Plywood")

' set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

i=0
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
i=i+1
oOccurrence.Name = oName & ":" & i
Next

 

 

Message 3 of 9
Curtis_Waguespack
in reply to: dclunie

Hi dclunie,

 

Just in case you're wanting to simply reset the name for each component rather than set a name for each one, here is another snippet to do so.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com


 

' set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition


'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
oOccurrence.Name = "" 'reset name to nothing, which pulls in the original name
Next 
Message 4 of 9
dclunie
in reply to: Curtis_Waguespack

Hi Curtis

 

Thanks that is great however is there a way to have it so it is a rule in itself attached to individual  .ipt files so taht when we hit save it automatically names occurrence as in rule.

 

We have a few files in each assembly and we know what they need to be called  but when we have input box we are unable to define if we are giving it the same name as originally defined.

 

oName= Plywood 01

 

oOccurrence.Name = oName

 

 

 

regards

 

Dclunie

Message 5 of 9
dclunie
in reply to: Curtis_Waguespack

 Hi

 

I am after some more help if you dont mind, in our office we have started developing ilogic controlled assemblies.we give the occurrence name like lh side and rh side etc,and all code references that occurrence name to control assembly.

 

However thanks to productivity tool in inventor some people hit rename browser nodes command in which basically a ticking time bomb for ilogic code and the code will fail .

 

What i am thinking is that if we give the title in the summary tab in inventor iproperties the name we desire for the occurrence name we can run a rule on save to change part occurrence back to desired name giving the code a chance to stay viable.

 

  1. Search all files for .ipt
  2. If Title in summary tab has name then
  3. change that part to occurrence name in browser

occurrence name.JPG

Any help would be appreciated

 

Thanks

 

Dave

 

 

 

Tags (2)
Message 6 of 9
xiaodong_liang
in reply to: dclunie

hi,

 

This is a small code for your reference. copy it to iLogic rule of the assembly. It checks the Title of the part and changes the occurrence name. But it does not consider the scenario if there is multi occurrences from same part. e.g.

 

mypart:1

mypart:2

 

because they are from the same part.The Title property is same. You will need to write a function to check if the name has been used and provide the names such as:

 

titlevalue:1

titlevalue:2

 

 oAssDoc =  ThisDoc.Document  
 oAssDef = oAssDoc.ComponentDefinition
  
 Dim oOcc As ComponentOccurrence
 For Each oOcc In oAssDef.Occurrences
  
    ' if this is a part
    If TypeOf oOcc.Definition.Document Is PartDocument Then
       
       oPartDoc = oOcc.Definition.Document
       
       'Summary Information
       oPSet = oPartDoc.PropertySets("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}")
       
       ' Title
       oP = oPSet.ItemByPropId(2)
       
       ' if the property value is not empty, change the occurrence name
       If oP.Value <> "" Then
         oOcc.Name = oP.Value
       End If
    End If
  Next
Message 7 of 9

HI all, i'm very happy to find this thread..

my questions..

I have a nozzle. and in assembly I need to add this nozze more than two valve. 

I can use methode in this thread to customize item name using part occurence name.

and my problem is, how to put this occurence name to Part List?

ie..

 

Mark  size     Service                  Connections

N1      Ø30     Spraying Device    DINxxx

N2      Ø30     Spraying Device    DINxxx

N3      Ø30     Spraying Device    DINxxx

 

 

note : N1,N2,N3 is one part and one file.

 

thanks before...

daily works with :
-----------------------------------------------------------------------------------------
Autodesk Inventor Profesional 2014.
AutoCAD Mechanical 2014.
Autodesk Vault Profesional 2014.
Message 8 of 9

Hi there,

 

I just want to rename one specific occurrence in the model browser through iLogic, not every compnent. Is there a way to do this?

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 9 of 9
i.pous
in reply to: Curtis_Waguespack

i have a variant of this problem. i use a for for each document on an assembly , like this:

For Each doc In asmDoc.AllReferencedDocuments 

so i can see the filename of each part 

and i want to see the occurence name of "doc" not of every part in the assembly, is possible?

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

Post to forums  

Autodesk Design & Make Report