Help me create a filter to isolate parts with a certain iproperty

Help me create a filter to isolate parts with a certain iproperty

Ivil
Enthusiast Enthusiast
1,004 Views
8 Replies
Message 1 of 9

Help me create a filter to isolate parts with a certain iproperty

Ivil
Enthusiast
Enthusiast

Hi!

I would like to make a modelstate with only parts from 

Help me create a filter to isolate parts with a certain iProperty (custom) and put it in an new model state. 

The thought of this is to filter get a BOM with only iProperties filterd out.

I want the filter to work through assemblies.

Can someone help me get started 😄

0 Likes
1,005 Views
8 Replies
Replies (8)
Message 2 of 9

WCrihfield
Mentor
Mentor

It is difficult to understand your request.  I understand that you have an assembly, and that some of the components within this assembly may have a certain custom iProperty.  I also understand that you seem to want to create a new model state, somehow based on which components have this custom iProperty.  Is this new model state going to created in the main assembly, or do you want to create a new model state within the components that either do or do not have the custom iProperty?  Does the value of that custom iProperty matter?  If you want the new model state to be created within the main assembly document, then do you want the components that contain the custom iProperty to just have their visibility turned off, or do you want them to be suppressed, or do you want them to be set as 'reference' or 'phantom'?  Or, is it the other way around, and you want the components that do have this custom iProperty to be the only ones left visible or unsuppressed, while all others are made invisible or suppressed?  Please explain in more detail what you want, so we can create a specific plan to accomplish it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 9

Ivil
Enthusiast
Enthusiast

What i want to do is to filter the BOM to only show parts that has a certain value in iproperties.

As far as i understand the BOM can´t have a filter? That is why i imagined that if i could create a modelstate to create a BOM filter, then i could just se the filtered objects in BOM. 

Or can i somehow filter the BOM without this hassle then it would be the best 😄

/Andreas

0 Likes
Message 4 of 9

Ivil
Enthusiast
Enthusiast

I just found out that BOM tools pro maybe solves the problem for me!

Now i just want to color a model based on the iproperties 😄

0 Likes
Message 5 of 9

WCrihfield
Mentor
Mentor

OK. I think I understand now.  Within the BOM dialog of an assembly in Inventor 2022 there is a drop-down list that is normally greyed out.  When I hover my mouse pointer over it, it displays "Filter Member Columns".

WCrihfield_1-1638372044814.png

I have never use that before, but on first glance it might seem like a way to filter the BOM view to only show members of a specific model state.  However, its description doesn't describe its purpose that way.  It is described this way:  "Displays the read only name of the active Model State or iAssembly row. When in an iAssembly Structured view, displays the name of the active row and the available table rows.".

 

So it sounds to me like we need to create a new ModelState within the main assembly.  Then iterate over all components in the assembly, and if they do not contain the specified custom iProperty, then Suppress them (within that ModelState), so that only the ones with that custom iProperty are left unsuppressed when that ModelState is active.  Then simply have that ModelState as the 'active' ModelState when you show the BOM dialog, then it will only show those components in its Structured view.  I believe this is possible to do by code.  Does that sound like what you want?  If so, what would this new ModelState be named, and what is the name of the custom iProperty we are looking for within the components?

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 9

Ivil
Enthusiast
Enthusiast

First i was so happy about BOM tools pro, but it seams that i can´t add data (just extract from there).

So it looks like i´m back to my original idea. Yes that exactly how i imagined it to work.

The Name of the model states can be the same as the value inside the iProperties. (Beam, Plate, Fastener and Other)

0 Likes
Message 7 of 9

WCrihfield
Mentor
Mentor

OK.  So you want multiple ModelStates created within the main assembly, not just one.  One for each different value found within this one custom iProperty in the components.  If the value of this iProperty = "Beam" in 6 components, then create a ModelState in the main assembly named "Beam" and only those components will remain unsuppressed in that ModelState, right?  That still sounds possible to do by code, but may require 2 loops through the components.  One loop to gather all unique values, so I know what ModelStates I need to create.  Then another loop through to do the suppression, because the ModelState needs to be created and activated before doing the suppression, so it will be saved within that ModelState.

 

I would still need to know the name of the custom iProperty I am searching for, so I know how to find it.  Or is there something else unique about this one iProperty in all the components that will allow me to find it when searching for it?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 9

Ivil
Enthusiast
Enthusiast

The iProperty is named 0_Save and contains the vales Beam, Plate , Fastener and other. So only four types of items.

The vision I have is that I should use inventors BOM as the source the complete order/delivery information for a entire project. But I somehow need to filter out the different types of parts to get the order and delivery information for the type of item that it is. For example it will be highly likely that all beams will be orderd from the same company, as well as  fasteners and plates. The only thing left will be the other category that will have several company’s providing our products.

I think that this could be a good way to filter information and get what I want. 

0 Likes
Message 9 of 9

WCrihfield
Mentor
Mentor

Hi @Ivil.  I think I may have something for you to try out.  I haven't tested this yet, because I don't have the proper set of files with iProperties set-up to test it on right now, but it seems to me like this might work for you.  It is a fairly long code, but I tried to include a lot of comments to tell you what's going on.

Here is the iLogic code:

 

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "iLogic")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
	oADef = oADoc.ComponentDefinition
	oOccs = oADef.Occurrences
	oMStates = oADef.ModelStates
	'make sure main assembly's 'Master' ModelState is 'active'
	If oMStates.ActiveModelState.Name <> "Master" Then
		oMStates.Item("Master").Activate
	End If
	
	'create a dictionary variable to hold the one returned by our Function below
	Dim oDictionary As Dictionary(Of String, List(Of ComponentOccurrence))
	'run our custom Function, and get the dictionary back from it
	oDictionary = CheckComponents(oOccs, "O_Save")
	'check to make sure the dictionary contains some items before trying to loop throuh them
	If oDictionary.Count = 0 Then
		MsgBox("No Components found with matching property or values.", vbInformation, "iLogic")
		Exit Sub
	End If
	For Each oPair In oDictionary
		'if no components in its list, then skip to next pair
		If oPair.Value.Count = 0 Then Continue For
		'get or create the assosiated ModelState, and activate it
		'runs our custom Sub routine below
		PrepModelState(oMStates, oPair.Key)
		For Each oOcc As ComponentOccurrence In oOccs
			'if this oOcc is not in the list, then suppress it in this ModelState
			If Not oPair.Value.Contains(oOcc) Then
				If Not oOcc.Suppressed Then oOcc.Suppress
			End If
		Next
	Next
	MsgBox("Process finished.", vbInformation, "iLogic")
End Sub

Sub PrepModelState(oModelStates As ModelStates, oModelStateName As String)
	Dim oMState As ModelState
	Try
		'attempt to find the existing ModelState
		oMState = oModelStates.Item(oModelStateName)
	Catch
		'it was not found, so create it
		oMState = oModelStates.Add(oModelStateName)
	End Try
	oMState.Activate
	oModelStates.MemberEditScope = MemberEditScopeEnum.kEditActiveMember
End Sub

Function CheckComponents(oComps As ComponentOccurrences, oPropName As String) As Dictionary(Of String, List(Of ComponentOccurrence))
	'create the dictionary variable that this Function is supposed to return
	Dim oDict As New Dictionary(Of String, List(Of ComponentOccurrence))
	'create the 4 List objects that will be contained within the dictionary
	Dim oBeamList As New List(Of ComponentOccurrence)
	Dim oPlateList As New List(Of ComponentOccurrence)
	Dim oFastenerList As New List(Of ComponentOccurrence)
	Dim oOtherList As New List(Of ComponentOccurrence)
	'now start looping through the components, and checking them
	For Each oComp As ComponentOccurrence In oComps
		'get the document that this component represents
		Dim oOccDoc As Document = oComp.ReferencedDocumentDescriptor.ReferencedDocument
		
		'get the 'custom' property set
		oCProps = oOccDoc.PropertySets.Item(4)
		
		Dim oCProp As Inventor.Property
		Try
			'tries to find the specified iProperty
			oCProp = oCProps.Item(oPropName)
		Catch
			'the property was not found, so skip to next component
			Continue For
		End Try
		Dim oVal As String = oCProp.Value
		'if Value is empty, then skip to next component
		If String.IsNullOrEmpty(oVal) Then Continue For
		
		'check value, then add component to related List
		If oVal = "Beam" Then
			oBeamList.Add(oComp)
		ElseIf oVal = "Plate" Then
			oPlateList.Add(oComp)
		ElseIf oVal = "Fastener" Then
			oFastenerList.Add(oComp)
		ElseIf oVal = "Other" Then
			oOtherList.Add(oComp)
		End If
	Next
	
	'check lists & add them to the Dictionary with associated Key
	If oBeamList.Count > 0 Then
		If oDict.ContainsKey("Beam") Then
			oDict.Item("Beam") = oBeamList
		Else
			oDict.Add("Beam", oBeamList)
		End If
	End If
	
	If oPlateList.Count > 0 Then
		If oDict.ContainsKey("Plate") Then
			oDict.Item("Plate") = oPlateList
		Else
			oDict.Add("Plate", oPlateList)
		End If
	End If
	
	If oFastenerList.Count > 0 Then
		If oDict.ContainsKey("Fastener") Then
			oDict.Item("Fastener") = oFastenerList
		Else
			oDict.Add("Fastener", oFastenerList)
		End If
	End If
	
	If oOtherList.Count > 0 Then
		If oDict.ContainsKey("Other") Then
			oDict.Item("Other") = oOtherList
		Else
			oDict.Add("Other", oOtherList)
		End If
	End If
	
	Return oDict
End Function

 

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

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes