Find all parts excluded from nesting via model browser, un-exclude programatically?

Find all parts excluded from nesting via model browser, un-exclude programatically?

ccec_ireland
Enthusiast Enthusiast
1,909 Views
20 Replies
Message 1 of 21

Find all parts excluded from nesting via model browser, un-exclude programatically?

ccec_ireland
Enthusiast
Enthusiast

Hi All!

 

I have several models which at one point in time or another have had certain parts excluded from nesting for various reasons. This was done by right click in model browser and select "exclude from nesting." Now, through part and assembly re-use in newer projects, I find myself constantly missing parts because the "exclude from nesting" property followed the part through the copy design operation into the new assembly. 

 

I really don't want to have to manually look at every part to see if that property is set. I was hoping I could just use "Find Component" and search for those with that property set (this is how I find all invisible parts in an assembly) but I do not see that property available in the search parameters. 

 

Does anyone know of a way to identify the parts which have been excluded from nesting? Or perhaps a bit of iLogic to iterate the model and clear that flag from every part?

 

Other ideas of ways to fix/work through this besides the obvious policy fix of "quit using the exclude from nesting flag"?

 

Thanks!

2025: AutoCAD, Inventor, Inventor Nesting, Vault Pro
0 Likes
Accepted solutions (1)
1,910 Views
20 Replies
Replies (20)
Message 2 of 21

A.Acheson
Mentor
Mentor

Hi @ccec_ireland 

Can you send a screenshot of the command you need to use. I assume your using an addin? Can you share the name of that? I doubt there is API access to this exclude command but you might be able to fire the UI command when the correct browser node is selected effectively like pressing the UI Button. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 21

ccec_ireland
Enthusiast
Enthusiast

I do have a few plug ins, but I believe this is a standard feature. We are currently on 2022. 

 

ccec_ireland_0-1720442750859.png

 

2025: AutoCAD, Inventor, Inventor Nesting, Vault Pro
0 Likes
Message 4 of 21

A.Acheson
Mentor
Mentor

I believe this command button comes into use when the nesting add-in is used. I haven’t seen this before. You can check if the command button exists by checking the control definitions. From this post here

Run the code and then search the text file for keywords such as “Nesting”.

 

You should see a line which has exclude from nesting as a note. If you do then the control definition exists and you can execute it to mimic you pressing the button. The next step would be to highlight the part and press the button. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 21

ccec_ireland
Enthusiast
Enthusiast

@A.Acheson thanks for the ideas. I found these two sets of commands. Anyone familiar with these?

 

InventorComposites.MAGInvLaunchCmd.ExcludeFromNestingCmd +++ Exclude from Nesting.

InventorComposites.MAGInvLaunchCmd.UseForNestingCmd +++ Use for Nesting.

 

TRUNEST_COMMAND_EXCLUDEFROMNESTINGCMD_0 +++ Exclude from Nesting

TRUNEST_COMMAND_USEFORNESTINGCMD_0 +++ Use for Nesting

2025: AutoCAD, Inventor, Inventor Nesting, Vault Pro
0 Likes
Message 6 of 21

A.Acheson
Mentor
Mentor

Good you found something. To run this when the part or browsernode is selected use the below. Type in the control definition you found into the brackets below .Item(".....')

If it switches it on/off then you have found the correct one. Selecting the occurrence/browser node is the next step after that. 

 

    Dim controlDefs As ControlDefinitions = ThisApplication.CommandManager.ControlDefinitions

    Dim controlDef As ControlDefinition = controlDefs.Item(".....Enter Control Def......"

    controlDef.Execute

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 7 of 21

ccec_ireland
Enthusiast
Enthusiast

These both compile and run, but so far I have not observed the state change when running these. I am selecting the part and then running the rule. Do I need to explicitly call the rule on the part from within the code? Thanks for the help, I'm brand new to iLogic. 

2025: AutoCAD, Inventor, Inventor Nesting, Vault Pro
0 Likes
Message 8 of 21

A.Acheson
Mentor
Mentor

So you can only change the setting by opening the part exclusively? If you can indicate what manual steps you take to change the setting then I can help you build around this information to automate. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 9 of 21

ccec_ireland
Enthusiast
Enthusiast

Correct. If I right click in the assembly tree, there is no "exclude" in the context menu. Even if I step into the part. 

ccec_ireland_0-1720475133816.png  

ccec_ireland_1-1720475191549.png

But if I open the part directly, I have the "exclude" option. 

ccec_ireland_2-1720475315789.png

 

You can see in my context menu that "use for nesting" was the last command run. However, this doesn't clear the exclude check mark. If that's what it's supposed to do, and if this is how it is supposed to be used. 

 

Is there no documentation from Autodesk on these commands and their use/syntax?

2025: AutoCAD, Inventor, Inventor Nesting, Vault Pro
0 Likes
Message 10 of 21

A.Acheson
Mentor
Mentor

Ok then you need to be inside the part to run the rule. Alot of this is trial an error, narrowing down the correct definition to use. There is no help page other than to get to the definition list and how to execute. Can you attach the code your using?

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 11 of 21

ccec_ireland
Enthusiast
Enthusiast
Dim controlDefs As ControlDefinitions = ThisApplication.CommandManager.ControlDefinitions

    Dim controlDef As ControlDefinition = controlDefs.Item("TRUNEST_COMMAND_USEFORNESTINGCMD_0")

    controlDef.Execute

I added this as a rule within the part, then selected the part and ran the rule. I tried it with all four commands, the exclude feature never toggled. 

2025: AutoCAD, Inventor, Inventor Nesting, Vault Pro
0 Likes
Message 12 of 21

ccec_ireland
Enthusiast
Enthusiast

Ok, I do have something working now. I thought these were both working, but in further testing only

TRUNEST_COMMAND_EXCLUDEFROMNESTINGCMD_0

is actually doing anything. This command will toggle that value regardless of where its currently set. In order to use this command, we will need to first check to see if the part is excluded or not. 

 

Is there any way to get a list of the attributes/variables tied to a part? This bit must be stored somewhere and have a name. 

2025: AutoCAD, Inventor, Inventor Nesting, Vault Pro
0 Likes
Message 13 of 21

A.Acheson
Mentor
Mentor

Ah yes this is where having no API makes things very difficult. 

 

From this article here

You can access the properties(iproperties) of the document.

 

 

  ' Get the active document.
    Dim doc As Document = ThisApplication.ActiveDocument

    ' Get the PropertySets object.
    Dim propSets As PropertySets= doc.PropertySets

    ' Get the design tracking property set.
    For each propSet As PropertySet = propSets
        For each prop As [Property] In propSet
        Logger.Info(prop.DisplayName)
        Logger.Info(prop.Value)

        Next
     Next

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 14 of 21

ccec_ireland
Enthusiast
Enthusiast

I used this code to extract all of the property values from the file. I added some error handling because the images couldn't convert to strings, and output it to a file because I wasn't sure how to retrieve the logger info. 

  'catch and skip errors
  On Error Resume Next
  
    ' Create empty list.
	Dim oList As New ArrayList
	oList.Add( "Property Name " & "Value" )
	
	' Get the active document.
    Dim doc As Document = ThisApplication.ActiveDocument

    ' Get the PropertySets object.
    Dim propSets As PropertySets= doc.PropertySets

    ' Get the design tracking property set.
    For Each propSet As PropertySet In propSets
        For Each prop As [Property] In propSet
        oList.Add(prop.DisplayName & " = " & prop.Value)
        'Logger.Info(prop.DisplayName)
		'Logger.Info(prop.Value)

        Next
     Next
	
	'Create file.
	oWrite = System.IO.File.CreateText("C:\Temp\DocProperties.txt")
	'Write Array out to String.
	For Each Item As String In oList
		oWrite.WriteLine(Item)
	Next

	oWrite.Close()

 

I didn't see anything in there that appears to be related to the nesting status. Are there other property sets?

2025: AutoCAD, Inventor, Inventor Nesting, Vault Pro
0 Likes
Message 15 of 21

ccec_ireland
Enthusiast
Enthusiast
C:\temp> fc DocPropertiesExcluded.txt DocPropertiesIncluded.txt
Comparing files DocPropertiesExcluded.txt and DOCPROPERTIESINCLUDED.TXT
FC: no differences encountered

 

Just to be sure I ran the rule with nesting enabled and disabled. Identical outputs. 

2025: AutoCAD, Inventor, Inventor Nesting, Vault Pro
0 Likes
Message 16 of 21

A.Acheson
Mentor
Mentor

One more thing you could try is to see if the Enabled status displays any difference if ticked or unticked. I suspect it will be the same because that usually just indicates if the button exists in the button dialogue. 

Dim controlDefs As ControlDefinitions = ThisApplication.CommandManager.ControlDefinitions

Dim controlDef As ControlDefinition = controlDefs.Item("TRUNEST_COMMAND_USEFORNESTINGCMD_0")

Dim Ans As Boolean 'Check status of this command
Ans = controlDef.Enabled
MessageBox.Show(Ans)
	

 

@MjDeckdo you think there is away forward in detecting if the exclude from nesting is checked or unchecked? The command above simply Toggles it off and on with no way to detect the status. 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 17 of 21

ccec_ireland
Enthusiast
Enthusiast

Yep, I get a TRUE either way. 

2025: AutoCAD, Inventor, Inventor Nesting, Vault Pro
0 Likes
Message 18 of 21

MjDeck
Autodesk
Autodesk
Accepted solution

@ccec_ireland , there is an Attribute that you can read to get the exclude status of a part. It is on the Document object. The AttributeSet name is TruNEST_Attribute and the Attribute name is ExcludeFromNesting. It is an Integer. If the value of this Attribute is 1, then the part will be excluded from nesting. If the value is zero, it will be included.

You can use that to answer your first question: "Does anyone know of a way to identify the parts which have been excluded from nesting?"
Do you also want to implement this: "iterate the model and clear that flag from every part" ?
If so, I'll try to find out if it's safe to do that using only the Attributes API. That would be simpler than trying to run the command on individual parts.


Mike Deck
Software Developer
Autodesk, Inc.

Message 19 of 21

ccec_ireland
Enthusiast
Enthusiast

Thanks @MjDeck. I'll work on identifying the parts using that attribute. Even if I just end up with a list of parts to go in and manually switch, that's way better than having to manually search for them!

 

I would like to implement something to find and clear these flags through an entire model if I can. Please let me know what you find. 

2025: AutoCAD, Inventor, Inventor Nesting, Vault Pro
0 Likes
Message 20 of 21

MjDeck
Autodesk
Autodesk

I confirmed that it's safe to use the Attributes API to set the flag, rather than using the command. So if you want to clear the flags for all parts in an assembly:

  • iterate over all the parts
  • in any part where that Attribute is set to 1 (one), set it to 0 (zero)

Mike Deck
Software Developer
Autodesk, Inc.