Switching filters in the part list on a drawing by assembly view representation. PartsList.FilterSettings. ilogic.

Switching filters in the part list on a drawing by assembly view representation. PartsList.FilterSettings. ilogic.

boris
Participant Participant
289 Views
4 Replies
Message 1 of 5

Switching filters in the part list on a drawing by assembly view representation. PartsList.FilterSettings. ilogic.

boris
Participant
Participant

I saw a discussion about PartsList.FilterSettings at the following link: https://forums.autodesk.com/t5/inventor-programming-ilogic/adding-filter-settings-to-parts-list-in-i....

I tried doing something with the code provided there, but I couldn't get it to work. If someone has found a solution for switching assembly view representation in the filters including limiting the quantity to visible components only, I would appreciate the information.

Thank you.

0 Likes
Accepted solutions (1)
290 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @boris.  That can be a difficult one to automate, due to having to specify an actual DVR (DesignViewRepresentation) object within the options of the filter.  You have to get that object from the model document being referenced by a drawing view.  I have no idea how your drawing is laid out, how many sheets, how many PartsLists, which one needs to be edited this way, or which drawing view you want to get that reference from, so I will post something a bit simpler first, just to give you a feel for what might be involved.  In this example, it is using the 'Pick' function to allow you to manually select a PartsList to work with.  Then, just gets the first drawing view that is on the same sheet as that PartsList that you selected, as the one to reference the model document from, and the DVR from.  See if this will work for you.

 

Dim oPList As PartsList = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingPartsListFilter, "Select a Parts List.")
If oPList Is Nothing Then Return
Dim oSheet As Inventor.Sheet = oPList.Parent
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
Dim oViewDoc As Inventor.Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oRepsMgr As RepresentationsManager = oViewDoc.ComponentDefinition.RepresentationsManager
Dim oActiveDVR As DesignViewRepresentation = oRepsMgr.ActiveDesignViewRepresentation
'Dim oOtherDVR As DesignViewRepresentation = oRepsMgr.DesignViewRepresentations.Item("DVR_Name")

Dim oFSettings As PartsListFilterSettings = oPList.FilterSettings
oFSettings.Enabled = True
Dim oNVM As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
oNVM.Add(“AssemblyViewRepresentation”, oActiveDVR)
oNVM.Add(“LimitQTYToVisibleComponentsOnly”, True)
Dim oFilterItem As PartsListFilterItem = oFSettings.Add(PartsListFilterItemTypeEnum.kAssemblyViewRepresentationFilterItem, oNVM)
oFilterItem.Enabled = True
oSheet.Update
Dim oDDoc As DrawingDocument = oSheet.Parent
If oDDoc.RequiresUpdate Then oDDoc.Update2(True)

 

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

boris
Participant
Participant

On the first sheet of the test drawing, there is a basic view and a parts list attached to it. In the parts list, there is already a filter set for view U-100-1.

Inside the drawing, for example, there are three representation views:

U-100-1

U-100-2-300-

U-100-4

 

I set U-100-2-300- as the active view. I want to change the view using your code.

 

Dim oPList As PartsList = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingPartsListFilter, "Select a Parts List.")
If oPList Is Nothing Then Return
Dim oSheet As Inventor.Sheet = oPList.Parent
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
Dim oViewDoc As Inventor.Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oRepsMgr As RepresentationsManager = oViewDoc.ComponentDefinition.RepresentationsManager
Dim oActiveDVR As DesignViewRepresentation = oRepsMgr.ActiveDesignViewRepresentation
Dim oOtherDVR As DesignViewRepresentation = oRepsMgr.DesignViewRepresentations.Item("U-100-1")

Dim oFSettings As PartsListFilterSettings = oPList.FilterSettings
oFSettings.Enabled = True
Dim oNVM As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
oNVM.Add(“AssemblyViewRepresentation”, oActiveDVR)
oNVM.Add(“LimitQTYToVisibleComponentsOnly”, "True")
Dim oFilterItem As PartsListFilterItem = oFSettings.Add(PartsListFilterItemTypeEnum.kAssemblyViewRepresentationFilterItem, oNVM)
oFilterItem.Enabled = True
oSheet.Update
Dim oDDoc As DrawingDocument = oSheet.Parent
If oDDoc.RequiresUpdate Then oDDoc.Update2(True)

I select the specified parts list and get an error.

Error on line 15 in rule: Rule15, in document: Test.idw

Unspecified error (0x80004005 (E_FAIL))

 

I would be grateful if you have any ideas on how to implement my task. Thank you for your attention.

 

image.png

 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @boris.  It looks like you changed the name of the DVR on Line 8, but should have also commented out Line 7, since you no longer need that one.  Then on Line 13, you should have switched out that variable from "oActiveDVR" to "oOtherDVR".  It is throwing the error on Line 15 because that is where that option is being applied, but it contained the other DVR object that may have not worked correctly.  Plus, I have heard others say that if there were already some filters set in the same PartsList, we may have to clear those out first, before adding another one.  Not sure.

 

But I can change the layout of the rule to suit your additional specifications, now that I know more about it.

Sub Main
	Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then Return
	Dim oSheet As Inventor.Sheet = oDDoc.Sheets.Item(1)
	oSheet.Activate
	If oSheet.PartsLists.Count = 0 Then Return
	Dim oPList As PartsList = oSheet.PartsLists.Item(1)
	Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
	'this next line show how to 'get' the which DVR this view is currently set to (ReadOnly property)
	'Dim sViewDVR As String = oView.DesignViewRepresentation
	'this next line shows how to 'set' the DVR that you want this view set to (a Sub type method)
	'oView.SetDesignViewRepresentation(sDVRName, bAssociativeBoolean) 'for setting the DVR of the View
	'<<< get the DVR from 'the model' document >>>
	Dim oViewDoc As Inventor.Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oRepsMgr As RepresentationsManager = oViewDoc.ComponentDefinition.RepresentationsManager
	'this will fail if the DVR named here is not found
	Dim oDVR As DesignViewRepresentation = oRepsMgr.DesignViewRepresentations.Item("U-100-1")
	'get the filter settings of the PartsList
	Dim oFSettings As PartsListFilterSettings = oPList.FilterSettings
	'make sure the main PartsList filters check box is checked
	oFSettings.Enabled = True
	'<<< clear any existing filters >>>
	If oFSettings.Count > 0 Then
		For i As Integer = 1 To oFSettings.Count
			oFSettings.Item(i).Delete
		Next
	End If
	'may need to do an update here, not sure
	'<<< create 'options' for a new filter (to filter by assembly DVR, and visible only) >>>
	Dim oNVM As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	oNVM.Add(“AssemblyViewRepresentation”, oDVR)
	oNVM.Add(“LimitQTYToVisibleComponentsOnly”, True)
	'<<< add the filter, with the options >>>
	Dim oFilterItem As PartsListFilterItem = oFSettings.Add(PartsListFilterItemTypeEnum.kAssemblyViewRepresentationFilterItem, oNVM)
	'make sure this new filter is enabled
	oFilterItem.Enabled = True
	oSheet.Update
	If oDDoc.RequiresUpdate Then oDDoc.Update2(True)
End Sub

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

boris
Participant
Participant

Thank you very much. You have been a great help.

0 Likes