iLogic to write Instance Prop's in Partslist column

iLogic to write Instance Prop's in Partslist column

j_chaissonQB25Y
Contributor Contributor
637 Views
4 Replies
Message 1 of 5

iLogic to write Instance Prop's in Partslist column

j_chaissonQB25Y
Contributor
Contributor

 Hi Everyone, 

I'm beating my head trying to figure this iLogic rule out. I'm pretty good with model rules but the drawing side is pretty new to me. I'm using Instance Properties to assign Nozzle #'s to each Nozzle in my assembly and the only way to show all nozzle #'s is to uncheck Merge Instance Rows in the BOM but then in the partslist even same parts now have their own line in the partslist and that's a no-go (see screenshot). So i need to leave the BOM set to merge. my solution is to have a iLogic rule loop (i think it needs to be a Loop within a Loop) through the BOM and look for a Instance Prop called "NOZZ" when it finds it Loop again looking for other instances of the same Part Number to find its "NOZZ" value and group the results into a string "N1, N2" writing that to the partslist column "NOZZ". (See second screenshot). With that said, if I'm over complicating this please let me know.

 

-Jeremy

 

j_chaissonQB25Y_0-1692887635360.png

j_chaissonQB25Y_1-1692887963424.png

 

 

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

WCrihfield
Mentor
Mentor

Hi @j_chaissonQB25Y.  That is a fairly complex scenario to do by code, but I created something that you can try out.  It gets the first PartsList on the active sheet of the active drawing.  Then it loops through its rows.  It gets the assembly level BOMRow object that the PartsListRow is referencing.  Then it attempts to loop through the components collection that the row represents.  Then it checks if it has any instance/occurrence properties.  If it does, it checks for one with that specific name, then records its value to a List(Of String), which can then be sorted later.  Then it converts that List of Strings into a single String with commas separating the values, and sets that as the value of the PartsListCell which is at the intersection of that row, and the custom column.  At least that was the plan. 😉

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
	If oSheet.PartsLists.Count = 0 Then Exit Sub
	Dim oPList As PartsList = oSheet.PartsLists.Item(1)
	For Each oRow As PartsListRow In oPList.PartsListRows
		If oRow.Custom Then Continue For
		Dim oInsPropValues As New List(Of String)
		Dim oDBOMRow As DrawingBOMRow = oRow.ReferencedRows.Item(1)
		If oDBOMRow.Custom Then Continue For
		Dim oBOMRow As BOMRow = oDBOMRow.BOMRow
		Dim oOccs As ComponentOccurrencesEnumerator = oBOMRow.ComponentOccurrences
		For Each oOcc As ComponentOccurrence In oOccs
			If oOcc.OccurrencePropertySetsEnabled = False Then Continue For
			Dim oOPS As PropertySet = oOcc.OccurrencePropertySets.Item(1)
			For Each oProp As Inventor.Property In oOPS
				If oProp.Name = "NOZZ" Then
					oInsPropValues.Add(oProp.Value.ToString)
				End If
			Next 'oProp
		Next 'oOcc
		oInsPropValues.Sort
		oRow.Item("NOZZ").Value = String.Join(",", oInsPropValues)
	Next 'oRow
	oSheet.Update
	If oDDoc.RequiresUpdate Then oDDoc.Update2(True)
	'If oDDoc.Dirty Then oDDoc.Save2(False)
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)

0 Likes
Message 3 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Actually, here is a slightly more dynamic version of that same routine, which is not specific to just that one hard-coded instance property name.  This version uses a Dictionary to keep track of potentially multiple instance properties by different names that may be found for each component in the row, and all of the different values for each.  Then collects the instance property's name, along with all the values it finds under that same name in other components in that row, within one Dictionary entry.  Then, sorts the values, as before.  Then attempts to put those values into a column by the same exact name as the instance property's name, if one exists.  This code could be modified to either let the user know that a column was not found for an instance property, and/or attempt to create the column.  There are lots of possibilities.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
	If oSheet.PartsLists.Count = 0 Then Exit Sub
	Dim oPList As PartsList = oSheet.PartsLists.Item(1)
	For Each oRow As PartsListRow In oPList.PartsListRows
		If oRow.Custom Then Continue For
		Dim oInsPropData As New Dictionary(Of String, List(Of String))
		Dim oDBOMRow As DrawingBOMRow = oRow.ReferencedRows.Item(1)
		If oDBOMRow.Custom Then Continue For
		Dim oBOMRow As BOMRow = oDBOMRow.BOMRow
		Dim oOccs As ComponentOccurrencesEnumerator = oBOMRow.ComponentOccurrences
		For Each oOcc As ComponentOccurrence In oOccs
			If oOcc.OccurrencePropertySetsEnabled = False Then Continue For
			Dim oOPS As Inventor.PropertySet = oOcc.OccurrencePropertySets.Item(1)
			For Each oProp As Inventor.Property In oOPS
				If oInsPropData.Keys.Contains(oProp.Name) Then
					oInsPropData.Item(oProp.Name).Add(oProp.Value.ToString)
				Else
					Dim oInsPropValues As New List(Of String)
					oInsPropValues.Add(oProp.Value.ToString)
					oInsPropData.Add(oProp.Name, oInsPropValues)
				End If
			Next 'oProp
		Next 'oOcc
		If oInsPropData.Count = 0 Then Continue For
		For Each oEntry In oInsPropData
			oEntry.Value.Sort
			Dim oCol As PartsListColumn = Nothing
			Try : oCol = oPList.PartsListColumns.Item(oEntry.Key) : Catch : End Try
			If oCol Is Nothing Then Continue For 'or try to create/add the column
			Try : oRow.Item(oCol).Value = String.Join(",", oEntry.Value) : Catch : End Try
		Next
	Next 'oRow
	oSheet.Update
	If oDDoc.RequiresUpdate Then oDDoc.Update2(True)
	'If oDDoc.Dirty Then oDDoc.Save2(False)
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 4 of 5

j_chaissonQB25Y
Contributor
Contributor

@WCrihfield ,

 

thank you for your help on this it worked like a charm, unfortunately I have a new problem now lol. the image below is after i ran your code, it populated the partslist column perfect but now my balloons reflect what was put in the partslist. So my Solution is to have a prompted entry sketch symbol named "NozNo". I'm assuming that there is a way if the symbol attached to parts it can find the Instance Property "NOZZ" and apply its value to the sketch symbol. I don't know why but Instance Properties are not accessible under sketch symbols unless I'm missing something.

 

-Jeremy

 

 

 

 

 

j_chaissonQB25Y_0-1692984915143.png

 

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

Hi @j_chaissonQB25Y.  There is no way to include instance properties in your Balloon by way of Styles settings (but they can have 2 sections, which are customizable).  And I am not sure about a 'linked' property (inserted instance property using Format Text dialog), because I have never tried that before, and don't know if it is possible.  But if you want to avoid using manual Promted Entry, it does sound possible to look at each Balloon (or SketchedSymbol) after the fact, and retrieve the instance property from the model it is attached to, then put that 'static' text into the SketchedSymbol.  To make that work, you would either make that text within the SketchedSymbol static, or as a Prompted Entry (if Prompted Entry, do not fill it in when created yet), then run a rule to fill in the properties.  It would likely be complicated to achieve though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes