Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create table for Instance Properties

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
sultan_mustun
449 Views, 7 Replies

Create table for Instance Properties

Hello,

I usually have assemblies with lots of content center flanges in them. To differentiate them, I usually create an Instance Property for the flanges, named "Nozzle_Name", and call them N1, N2, N3,...
I use this custom instance property to mark them using insert symbols on my drawing.

I would like to know if there is a way to create an automatic table that goes through the assembly and list all the flanges as well as the quantity present. Something like this:

Nozzle NameQtySpecs
N12Flange Asme B16.5…
N21 
N34 


Because right now I am doing this manually, but doing so is very prone to mistake.

I tried using the Parts List, but it is not possible to have two different Parts List in the same drawing. And I need the normal Parts List also in the drawing.

Thank you.

Labels (3)
7 REPLIES 7
Message 2 of 8
m_baczewski
in reply to: sultan_mustun

Hi,

Of course, it is possible. Just let me know how we can identify that a given part is a nozzle. If this information is recorded somewhere in the iProperties or can be extracted from the name, then all you need to do is create a custom table with the number of rows resulting from searching the model for, for example, the name "nozzle," and then populate it as follows:

 

Sub TableFill(table As CustomTable, document As Object, rowNumber As Integer)

	Dim userDefinedProperties As PropertySet = document.PropertySets.Item("Inventor User Defined Properties")
	For Each userDefinedProperty As [Property] In userDefinedProperties
		If TypeOf (userDefinedProperty.Value) Is String	
			If userDefinedProperty.DisplayName = "KOD-BH_symbol"
				table.Rows.Item(rowNumber).Item(1).Value = userDefinedProperty.Value
			Else If userDefinedProperty.DisplayName = "KOD-BH_oznaczenie"
				table.Rows.Item(rowNumber).Item(2).Value = userDefinedProperty.Value
			Else If userDefinedProperty.DisplayName = "KOD-BH_opis"
				table.Rows.Item(rowNumber).Item(3).Value = userDefinedProperty.Value
			End If
		Else 
			Continue For
		End If
	Next
End Sub
Message 3 of 8
WCrihfield
in reply to: sultan_mustun

Hi @sultan_mustun.  Here is another example that I somewhat customized to your specs.  I had an interest in something similar to this myself recently, so this is sort of exploratory for me too.  It will not create the third column though, because I had no idea how to populate that third column based on available data in your post.  It expects that you have a drawing open on your screen, and the active sheet has at least one view of an assembly on it.  If not, it will not do anything.  It will then attempt to navigate only the top level components in that view's referenced assembly, and collect 'instance property' data related to your inquiry specs, but just names and quantities (quantity not based on BOM qty).  If it found some matching data, it will then attempt to either find an existing CustomTable by the Title "Instance Data" (can be changed in code), or create a new one.  Then it will attempt to put the new data into that table's rows.  I have not tested this myself yet, because I was in a hurry and on my way out for the day, so let me know how it works for you.

Sub Main
	Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then
		Logger.Debug("iLogic rule '" & iLogicVb.RuleName & "' was aborted - no DrawingDocument found.")
		Return
	End If
	Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
	If oSheet.DrawingViews.Count = 0 Then Return
	Dim oRefDocDesc As DocumentDescriptor = oSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor
	If oRefDocDesc.ReferencedDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Return
	Dim oInstanceData As New Dictionary(Of String, Integer)
	Dim oRefADoc As AssemblyDocument = oRefDocDesc.ReferencedDocument
	Dim oOccs As ComponentOccurrences = oRefADoc.ComponentDefinition.Occurrences
	For Each oOcc As ComponentOccurrence In oOccs
		If Not oOcc.OccurrencePropertySetsEnabled Then Continue For
		For Each oProp As Inventor.Property In oOcc.OccurrencePropertySets.Item(1)
			If oProp.Name <> "Nozzle_Name" Then Continue For
			Dim sNozzleName As String = oProp.Value
			If oInstanceData.ContainsKey(sNozzleName) Then
				oInstanceData.Item(sNozzleName) += 1 'adds 1 to current Qty value
			Else 'this instance name not encountered yet
				oInstanceData.Add(sNozzleName, 1) 'add an entry for this name, with Qty = 1
			End If
		Next oProp
	Next oOcc
	If oInstanceData.Count = 0 Then Return
	Dim oCTable As CustomTable = Nothing
	Dim sTitle As String = "Instance Data"
	Try : oCTable = oSheet.CustomTables.OfType(Of Inventor.CustomTable).First(Function(c) c.Title = sTitle)
	Catch : End Try
	If oCTable Is Nothing Then
		Dim oP2D As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width / 2, oSheet.Height / 2)
		Dim iCols As Integer = 2
		Dim iRows As Integer = oInstanceData.Count
		Dim oColTitles() As String = {"Nozzle Name", "QTY"}
		Try
			oCTable = oSheet.CustomTables.Add(sTitle, oP2D, iCols, iRows, oColTitles)
			oCTable.HeadingPlacement = HeadingPlacementEnum.kHeadingAtTop
			oCTable.ShowTitle = False
		Catch
			Logger.Error("Error creating CustomTable.")
		End Try
	End If
	If oCTable Is Nothing Then Return
	oCTable.HeadingPlacement = HeadingPlacementEnum.kHeadingAtTop
	For i As Integer = 1 To oCTable.Rows.Count
		Dim oRow As Inventor.Row = oCTable.Rows.Item(i)
		oRow.Item(1).Value = oInstanceData.ElementAt(i - 1).Key
		oRow.Item(2).Value = oInstanceData.ElementAt(i - 1).Value
	Next i
	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 4 of 8

@WCrihfield thank you very much, that's exactly what I needed! But I have 3 2 issues with it that I'm trying to correct:

Issue 1 : Suppose I had up until nozzle N5, I ran the program and it works just fine. It creates 5 rows for N1-5. But if I later add another one, now we are at N6, running the program does not add the new row for the N6.

Issue 2 : Since most of the flanges would come from the content center, there would still be some columns that I would need to fill in manually. Like for example writing what the connections are for. But running the program, erases the Static values. Update: I was assigning "" to the column, that's why it was erasing the latter. My mistake.

Issue 3 : How do I add the part number and the iProperty description to columns 3 and 4? Note that nozzles with same name (example N2) will always be the same part.

Message 5 of 8
WCrihfield
in reply to: sultan_mustun

Hi @sultan_mustun.

Issue 1:  I understand.  I have actually dealt with this sort of thing before in the past, so I may be able to fix that.  I believe that I will need to use a different Type of collection variable for gathering data into...one that can hold that many different types/pieces of data, per entry in the list.  Then modify the data collection portion of the routine to collect the extra data (and maybe make that section a separate Function routine).  Then, later in the code, check the 'Count' of entries in the collection, and use that to either 'Add' or 'Delete' rows in the table, before writing the collected data into the table. 

 

Issue 2:  Should the code either create or ignore a specific number of columns at the end for 'manual entry stuff'?  Or is the Part Number & Description columns all you will need?

 

Issue 3:  I assume that the 'Part Number' & 'Description' you are mentioning are the 'standard' iProperties, right?...not custom ones, or 'instance' properties?  Hopefully there will not be components referencing different source documents, with different values for Part Number & Description, with the same instance property named "Nozzle_Name", and the same value for that property.  If so, first/earlier values may get overwritten with last/later values.  When creating the table, including the other columns should be OK, because the column count would be based on the number of pieces of data within each entry of the main collection (optionally plus some).  However, if finding an existing table, that will be more difficult/complicated to deal with properly.  I assume we would have to get the 'Count' of pieces of data in first entry in collection, then use that to either add or delete columns of table, before writing new data to it.  If there will be 'extra' columns, that might be tricky to handle.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 8
sultan_mustun
in reply to: WCrihfield

Hi @WCrihfield ,

Issue 1:
I tried comparing the old to the new list, when the rule is ran, but did not manage to make it work.

Issue 2:
In the end I will have the two columns that we already discussed, column 3 would be the part number, column 4 the description, and column 5 would be the one that I input manually.

 

Issue 3:
Yes, I meant the standard iProperties.
Yes to avoid the issue of overriding the values, if there are two flanges with the same Nozzle_Name, it will always be the exact same part.

Message 7 of 8
WCrihfield
in reply to: sultan_mustun

Hi @sultan_mustun.  I'm on my way out, but give the attached code example a try and see if it works any better for you.  Again, I have not tested this myself yet, so be cautious.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 8

@WCrihfield , Thank you so much. It works like a charm.

Is there a way to sort the data in alphabetical order before creation of the table? Because right now it sorts it by the order that it appears in the model tree.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report