iLogic inserting parts list into drawing rule help

iLogic inserting parts list into drawing rule help

Anonymous
Not applicable
1,188 Views
15 Replies
Message 1 of 16

iLogic inserting parts list into drawing rule help

Anonymous
Not applicable

I currently have the following rule that will insert a parts list into an assembly drawing:

oDrawDoc = ThisDoc.Document
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet
 
Dim oBorder As Border = oSheet.Border 
Dim oDrawingView As DrawingView
oDrawingView = oSheet.DrawingViews(1)
Dim oPartsList As PartsList 
'Boarder
If Not oBorder Is Nothing Then
    oPlacementPoint = oBorder.RangeBox.MaxPoint
Else
    oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width, oSheet.Height)
End If

'Look for Parts List
Try
    'Parts List Found, Do Nothing
    oPartsList = oSheet.PartsLists(1)
Catch
    'Create the parts list.	 
     oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint) 
 Catch 
	oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint, PartsListLevelEnum.kStructuredAllLevels)
End Try


doc = ThisDrawing.ModelDocument

'Set Parts List Type
Dim oStyleMgr As DrawingStylesManager
oStyleMgr = oDrawDoc.StylesManager
Dim oPartListStyle As PartsListStyle 

Select doc.SubType

Case "{4D29B490-49B2-11D0-93C3-7E0706000000}" 'PartDocument
	oPartListStyle = oStyleMgr.PartsListStyles.Item("AWE Part List")
Case "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" 'SheetMetal Document
	oPartListStyle = oStyleMgr.PartsListStyles.Item("AWE DXF List")
Case "{E60F81E1-49B3-11D0-93C3-7E0706000000}" 'Assembly Document

	oPartListStyle = oStyleMgr.PartsListStyles.Item("AWE Assembly List")
End Select

'Dim oPartsList As PartsList
For Each oPartsList In oDrawDoc.ActiveSheet.PartsLists
oPartsList.Style = oPartListStyle
Next

'Move the Parts List
PartHight=oSheet.PartsLists.Item(1).RangeBox.MaxPoint.Y-oSheet.PartsLists.Item(1).RangeBox.MinPoint.Y
TitleY=oSheet.TitleBlock.RangeBox.MaxPoint.Y
PointX=oBorder.RangeBox.MaxPoint.X
PointY=TitleY+PartHight
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(PointX,PointY)
oPartsList.Position = oPlacementPoint

iLogicVb.UpdateWhenDone = True

The rule works, however due the the nature of how the parts are created, the description column is often left blank. Is there a way I can populate the description column by pulling info from a user parameter that is set when creating the part instead of where the description column pulls info from by default?

0 Likes
Accepted solutions (1)
1,189 Views
15 Replies
Replies (15)
Message 2 of 16

WCrihfield
Mentor
Mentor

This user parameter you're talking about...is this something within each model document?  Since that description column is most likely pulling data from the description iProperty within each model document, you could probably create a routine that would look into each model, get the value of that user parameter, then write its value (or something based on that info) to the description iProperty of that model.  That should fill in that column as it should be, without having to overwrite cell values with static values.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 16

Anonymous
Not applicable

it is a parameter that is created whenever an individual part is created. its called by using 

	part_type = parameter("PartType")

is there a way to replace the description column with this variable for each part in an assembly? 

0 Likes
Message 4 of 16

bradeneuropeArthur
Mentor
Mentor
Mark the parameter for export an link it to the description expression by description =<parametername>

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 16

WCrihfield
Mentor
Mentor

Since you're thinking about replacing the column with a new one, instead of updating the description iProperties, we're a little more limited.  PartsLists are fairly limited as to what they will let you add a column for, so there isn't really a simple way to include a column for a user parameter.  Generally when you want to add a 'special' column it's for a custom iProperty.  So, in order to include a column filled with those user parameter values, you would first have to create a custom iProperty in all the model files with its value equal to that user parameter's value.  Then include the column for that custom iProperty.  I'm guessing that user parameter has text type values, in which case we wouldn't be able to just set it to 'export' or 'expose as custom iProperty', which might have made that process easier and kept the values up-to-date.  The next alternative would be to overwrite the parts list cells in the description column with the values we extract from that user parameter of each model.  The values would be static though (won't update).  Which process do you think would fit your needs best?  Either way, it's probably going to have to include a lot of extra code to accomplish.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 16

Anonymous
Not applicable

I believe your second approach would be best. It is not a big deal that the property values be static as these should not change anyways. 

0 Likes
Message 7 of 16

bradeneuropeArthur
Mentor
Mentor

You could use ilogic to write the parameter to a property!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 8 of 16

WCrihfield
Mentor
Mentor

This may seem like a huge iLogic rule, because it is a complicated task, but I think I have most of the possible errors accounted for, one way or another.  I chose to outsource most of the routines of this rule out to separate Subs and Functions, in an attempt to keep the main Sub as straight forward and clear as possible.  Give this a try and let me know how it works for you.

Sub Main
	oDrawDoc = ThisDrawing.Document
	oSheet = oDrawDoc.ActiveSheet
	oView = oSheet.DrawingViews.Item(1)

	'get/create the PartsList (using our custom Sub below)
	oPList = GetCreatePartsList(oSheet)
	If IsNothing(oPList) Then
		MsgBox("Could not get/create a PartsList.  Exiting rule.", vbCritical, "iLogic")
		Exit Sub
	End If

	'get the model document (using our custom Sub below)
	oModelDoc = GetDrawingModel(oDrawDoc)
	If IsNothing(oModelDoc) Then
		MsgBox("No 'Model' document found.  Exiting rule.", vbCritical, "iLogic")
		Exit Sub
	End If

	'determine/get PartsListStyle to use/apply
	Dim oPListStyle As PartsListStyle = GetPartsListStyle(oDrawDoc, oModelDoc)
	If IsNothing(oPListStyle) Then
		MsgBox("Could not get the PartsListStyle.  Exiting rule.", vbCritical, "iLogic")
		Exit Sub
	End If

	'oPList.Style = oPListStyle
	For Each oPrtList As PartsList In oSheet.PartsLists
		oPrtList.Style = oPListStyle
	Next
	
	'reposition the PartsList (using our Sub below)
	RepositionPartsList(oSheet, oPList)
	
	oDrawDoc.Update2(True)
	
	'get the Index of the Description column
	Dim oCol As Integer
	For oCol = 1 To oPList.PartsListColumns.Count
		If oPList.PartsListColumns.Item(oCol).Title = "Description" Then
			Exit For 'oCol will retain its value
		End If
	Next
	
	For Each oRow As PartsListRow In oPList.PartsListRows
		'get the Document this Row represents
		Dim oDBOMRow As DrawingBOMRow = oRow.ReferencedRows.Item(1)
		Dim oRowDoc As Document = oDBOMRow.BOMRow.ComponentDefinitions.Item(1).Document
		'get Param Value from it
		Dim oParam As Inventor.Parameter
		Try
			oParam = oRowDoc.ComponentDefinition.Parameters.Item("PartType")
		Catch
			'could not find it
		End Try
		If IsNothing(oParam) Then
			MsgBox("Could not find the parameter named 'PartType'.  Skipping to next.", vbInformation, "iLogic")
			Continue For
		End If
		oVal = CStr(oParam.Value) 'making sure it's a String, because that's what we need
		'write the parameter's value to the cell in that row for the Description column
		oRow.Item(oCol).Value = oVal
	Next
	
	oDrawDoc.Update2(True)
End Sub

Function GetDrawingModel(oDrawing As DrawingDocument) As Document
	If oDrawing.AllReferencedDocuments.Count = 0 Then Return Nothing
	For Each oRefDoc As Document In oDrawing.AllReferencedDocuments
		If oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or _
			oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
			Return oRefDoc
			Exit For
		End If
	Next
End Function

Function GetCreatePartsList(oDSheet As Sheet) As PartsList
	'define placement point
	oTG = ThisApplication.TransientGeometry
	Dim oPlacementPoint As Point2d
	If oDSheet.Border Is Nothing Then
		oPlacementPoint = oTG.CreatePoint2d(oDSheet.Width, oDSheet.Height)
	Else
		oPlacementPoint = oDSheet.Border.RangeBox.MaxPoint
	End If

	'get/Create the PartsList
	Dim oPrtList As PartsList
	Try
		oPrtList = oDSheet.PartsLists.Item(1)
	Catch
		oPrtList = oDSheet.PartsLists.Add(oView, oPlacementPoint, PartsListLevelEnum.kStructuredAllLevels)
	Catch
		oPrtList = oDSheet.PartsLists.Add(oView, oPlacementPoint)
	End Try
	Return oPrtList
End Function

Function GetPartsListStyle(oDrawing As DrawingDocument, oModel As Document) As PartsListStyle
	oSylesMgr = oDrawing.StylesManager
	Dim oPLStyle As PartsListStyle
	Try 'just in case it can't find those styles, so it won't throw an error
		Select Case oModel.SubType
			Case "{4D29B490-49B2-11D0-93C3-7E0706000000}" 'PartDocument
				oPLStyle = oSylesMgr.PartsListStyles.Item("AWE Part List")
			Case "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" 'SheetMetal Document
				oPLStyle = oSylesMgr.PartsListStyles.Item("AWE DXF List")
			Case "{E60F81E1-49B3-11D0-93C3-7E0706000000}" 'Assembly Document
				oPLStyle = oSylesMgr.PartsListStyles.Item("AWE Assembly List")
		End Select
	Catch
	End Try
	Return oPLStyle
End Function

Sub RepositionPartsList(oDSheet As Sheet, oPrtList As PartsList)
	PartHight = oPrtList.RangeBox.MaxPoint.Y - oPrtList.RangeBox.MinPoint.Y
	Try
		TitleY = oDSheet.TitleBlock.RangeBox.MaxPoint.Y 'this might Error if no TitleBlock
		PointX = oDSheet.Border.RangeBox.MaxPoint.X 'this might Error if no Border
		PointY = TitleY + PartHight
		oPosition = ThisApplication.TransientGeometry.CreatePoint2d(PointX, PointY)
		oPrtList.Position = oPosition
	Catch
	End Try
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 16

Anonymous
Not applicable

Thanks for taking the time to work on my rule! 

 

I tried to run it and the following error occurred:

CodyCZorn_0-1634059369647.png

 

Not sure why this is happening?

0 Likes
Message 10 of 16

WCrihfield
Mentor
Mentor

After seeing the information on the other tab of that error dialog, I can see that was having trouble with the PartsLists.Add() method, so I investigated that Function I wrote for that task.  I see now that I forgot to pass the DrawingView object to that Function as an input variable, so that it could be used in that line of code.  So I modified that Function a bit to include it.  Even though those lines of code were within a Try...Catch block, if the final Catch routine still fails, it will still throw an error, that's why the final Catch usually contains something like a message or log entry in difficult situations.

Here are just the parts of the code that need to be changed:

 

The line in the Sub Main part of the rule that calls the Function to run, needs to change from this:

oPList = GetCreatePartsList(oSheet)

to this:

oPList = GetCreatePartsList(oSheet, oView)

 Then the Function down below (GetCreatePartsList) needs to be replaced by this:

Function GetCreatePartsList(oDSheet As Sheet, oDView As DrawingView) As PartsList
	'define placement point
	oTG = ThisApplication.TransientGeometry
	Dim oPlacementPoint As Point2d
	If oDSheet.Border Is Nothing Then
		oPlacementPoint = oTG.CreatePoint2d(oDSheet.Width, oDSheet.Height)
	Else
		oPlacementPoint = oDSheet.Border.RangeBox.MaxPoint
	End If

	'get/Create the PartsList
	Dim oPrtList As PartsList
	Try
		oPrtList = oDSheet.PartsLists.Item(1)
	Catch
		oPrtList = oDSheet.PartsLists.Add(oDView, oPlacementPoint, PartsListLevelEnum.kStructuredAllLevels)
	Catch
		oPrtList = oDSheet.PartsLists.Add(oDView, oPlacementPoint)
	Catch
		MsgBox("All attempts to get or create the PartsList failed.", vbCritical, "iLogic")
	End Try
	Return oPrtList
End Function

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 11 of 16

Anonymous
Not applicable

Ok I'm no longer receiving the parameter error but i am now getting an error saying a variable is not declared. here is the error I'm seeing: 

CodyCZorn_0-1634064072741.png

CodyCZorn_1-1634064081289.png

 

 

0 Likes
Message 12 of 16

WCrihfield
Mentor
Mentor

The first warning line:

I'm guessing this means that, if that function doesn't find a model document, then it will never reach a point where it is supposed to return a value, and it must be able to return a value, even if its Nothing or empty.  So, there are two different ways to fix that Function.  I could define the oRefDoc variable in the line above the loop, instead of within the loop, then use the line 'Return oRefDoc' after the loop.  Or I could simply just add the line 'Return Nothing' after the end of the loop.  Either way, would fix that warning message.

 

The second warning line:

The variable 'oView' was defined and given a value in line 4 of the Sub Main part of the rule, so I don't know why it would be finding this down within the 'GetCreatePartsList' Function (location based on the line number of the warning message).  The variable I'm using in that Function is named 'oDView' in the last code I posted.  (I never use the same variable name within a lower custom Sub or Function as I'm using in the 'Sub Main' area of the code, as a practice.)

 

The other warning lines:

I'm not 100% sure, but I'm thinking you can only have one of the Add() lines included as a Catch, instead of two different versions of the Add() method.  I think it's because if either of those two failed, it would be for the same reason, so only one of them is allowed.  I think it has to be possible for each Catch statement to be able to fail for a different reason.  In an attempt to fix this, try commenting out one of the 'Catch' lines in there, then the following line of code within it too, where it is attempting to add a PartsList.  Here is the official documentation for the Try...Catch block of code.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 13 of 16

Anonymous
Not applicable

hello, i followed your tips and there is no longer any warning messages just the original error message aboyt "GetPartsListStyle" on line 21 that I previously shared is popping up when trying to run the rule

0 Likes
Message 14 of 16

Anonymous
Not applicable

Hello, I had the simpler idea to just write the iproperty in for the parts that were missing a description for every part in an assembly. Then, if the iproperty existed the description would automatically be present in the parts list. my current code is as follows:

 

Dim oDoc As Document = ThisApplication.ActiveDocument
Dim aDoc As DocumentsEnumerator = oDoc.AllReferencedDocuments
Dim iDoc As Document
For Each iDoc In aDoc
    'Set iProperties in each of the parts in assembly
    Dim sTS As String = iDoc.FullFileName
    Dim FNamePos As Long = InStrRev(sTS, "\", - 1)
    Dim docFName As String = Mid(sTS, FNamePos + 1, Len(sTS) - FNamePos)
	part_descript = parameter("PartType")
    iProperties.Value(docFName, "Project", "Description") = part_descript
Next

This code works to rewrite the iproperty description in for whatever I set the second to last line of code equal to. the only issue is when I set it equal to 'part_descript' the paramter is not found. This parameter does indeed exist as a user parameter in each part. Not sure why the code is not recognizing the parameter, i'm sure its just a simple fix but I cannot seem to figure out what my rule is missing. Thanks!

0 Likes
Message 15 of 16

WCrihfield
Mentor
Mentor
Accepted solution

I sorry for not getting back here sooner.  Trying to debug that longer, complicated rule above remotely, without being able to test it myself was starting to make even my head hurt. 😅

In your latest rule here, this line of code:

 

part_descript = parameter("PartType")

 

is trying to get that parameter value from the 'active' document, which I assume is the main assembly, because you are not specifying any other document for it to source it from.  Much the same as what you did in your iProperty line of code, where you specify the document or component to access the iProperty in, there is also a way to specify a document or component to access a parameter from with that Parameter() line.  There are a couple of iLogic snippets that use that Parameter() line in them, but they all either don't specify a specific document, or specify component name, or use MakePath to specify where to source the parameter from.

 

Parameter("d0") = 1.2 'works on the 'active' document
Parameter("Part1:1", "d0") = 1.2 'specifying Component.Name
Parameter(MakePath("SubAssem1:1", "Part1:1"), "d0") = 1.2

 

So, I assume it will accept the Document.DisplayName or Document.FullDocumentName or similar input in that first input variable, because it doesn't specify exactly.

 

Try this instead of that line:

part_descript = iDoc.ComponentDefinition.Parameters.Item("PartType").Expression

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 16 of 16

Anonymous
Not applicable

So is there a way i can pull the 'PartType' parameter for an individual part in the assembly instead of the parameter for the entire assembly? the 'PartType' parameter only exists for the individual parts NOT for the entire assembly.

0 Likes