Adding Filter Settings to Parts List in iLogic

Adding Filter Settings to Parts List in iLogic

przemyslaw_sokolowski
Autodesk Autodesk
1,099 Views
8 Replies
Message 1 of 9

Adding Filter Settings to Parts List in iLogic

przemyslaw_sokolowski
Autodesk
Autodesk

I am trying to apply "Test" View Representation Filter Settings to Parts List. When I run my code in VBA the "Primary" View is applied. When I am trying to run it in iLogic Inventor crashes. Could you give me a hint what is wrong in my code? 

 

Sub main
	Dim oDrawing As Inventor.DrawingDocument
	oDrawing = ThisApplication.ActiveDocument

	Dim oView As DrawingView
	oView = oDrawing.ActiveSheet.DrawingViews.Item(1)

	Dim oPartsList As PartsList
	oPartsList = oDrawing.ActiveSheet.PartsLists.Item(1)
	
	Dim oAssyComp As AssemblyComponentDefinition
	oAssyComp = oPartsList.ReferencedFile.DocumentDescriptor.ReferencedDocument.ComponentDefinition
	
	Dim oViewRep As DesignViewRepresentation
	oViewRep = oAssyComp.RepresentationsManager.DesignViewRepresentations.Item("Test") 
	
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oOptions.Add(“AssemblyViewRepresentation”, oViewRep)

	oPartsList.FilterSettings.Enabled = True
        
    Dim oPartsListFItem As PartsListFilterItem

	oPartsListFItem=oPartsList.FilterSettings.Add(kAssemblyViewRepresentationFilterItem,oOptions)
End Sub

Thanks

Przemek



Przemyslaw Sokolowski
Technical Sales Specialist
0 Likes
Accepted solutions (1)
1,100 Views
8 Replies
Replies (8)
Message 2 of 9

Andrii_Humeniuk
Advisor
Advisor

Hi @przemyslaw_sokolowski . It looks like you are trying to add a filter of the View Representation category, while it is already present in the filter list. You need to clear the existing filters and add a new one.
ListFilter.png

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 9

WCrihfield
Mentor
Mentor

Hi @przemyslaw_sokolowski.  These are just educated guesses at this point, because I haven't been updated to the 2024.1 version yet, but I would suggest looking into the following changes:

 

Dim oAssyDoc As AssemblyDocument = oPartsList.ReferencedDocumentDescriptor.ReferencedDocument
oAssyComp = oAssyDoc.ComponentDefinition

 

...instead of:

 

oAssyComp = oPartsList.ReferencedFile.DocumentDescriptor.ReferencedDocument.ComponentDefinition

 

And, including the Enum name before the Enum variation's name, like this:

 

oPartsListFItem = oPartsList.FilterSettings.Add(PartsListFilterItemTypeEnum.kAssemblyViewRepresentationFilterItem, oOptions)

 

VBA encourages us to not include it, but it is always very much recommended in iLogic rules, unless you prefer the numerical variation value instead, which can be harder to read later.

Then, after you have that newly added PartsListFilterItem to that oPartsListFItem variable, you may want to take the extra step of Enabling that item.

oPartsListFItem.Enabled = True

The main other things are simply making sure there is a DrawingView, and PartsList on the 'active' sheet, and that there is actually a DVR (DesignViewRepresentation) object in that assembly named "Test".

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 9

przemyslaw_sokolowski
Autodesk
Autodesk

Thanks for the tips, unfortunately they did not help. What I noticed is that if I remove oOptions (which is optional) from the line:

oPartsListFItem=oPartsList.FilterSettings.Add(PartsListFilterItemTypeEnum.kAssemblyViewRepresentationFilterItem)

The code did not crash Inventor but creates filter for "Primary" Design View Representation. So it looks like something is wrong with the definition of NameValueMap.



Przemyslaw Sokolowski
Technical Sales Specialist
0 Likes
Message 5 of 9

przemyslaw_sokolowski
Autodesk
Autodesk

Thanks for pointing that out. I created the screenshot to prove that there is "Test" Design View Representation defined in assembly.  If the filter is applied the code fails to create a new one.



Przemyslaw Sokolowski
Technical Sales Specialist
0 Likes
Message 6 of 9

WCrihfield
Mentor
Mentor
Accepted solution

Hi @przemyslaw_sokolowski.  This may sound overly simple, and a stretch, but have you tried 'declaring' the oOptions variable as a NameValueMap before setting its value.  This is rarely an issue, but I have seen similar situations stump up iLogic rules before, so I just thought it was worth mentioning.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 9

przemyslaw_sokolowski
Autodesk
Autodesk

That was it. Thank you very much  🙂



Przemyslaw Sokolowski
Technical Sales Specialist
0 Likes
Message 8 of 9

Luis_Pacheco_3D
Advocate
Advocate

From which inventor version does this code work?

0 Likes
Message 9 of 9

WCrihfield
Mentor
Mentor

Hi @Luis_Pacheco_3D.  The online documentation for the PartsList.FilterSettings property indicates that it was added in 2024.1 version.

Edit:  Here are two more related links:

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-A0B07812-EB30-4898-B53E-1112CF02DB2C 

https://forums.autodesk.com/t5/inventor-ideas/parts-list-filter-settings/idi-p/6238772 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)