Part List Macro using VBA Editor

Part List Macro using VBA Editor

Inventor_Enjoyer
Contributor Contributor
555 Views
4 Replies
Message 1 of 5

Part List Macro using VBA Editor

Inventor_Enjoyer
Contributor
Contributor

Hey Autodesk forum!

 

I need to make macro which would create "Part Type" column and it would replace "Dim" column. "Part Type" column should get it's value from parts iProperties.

So far I've managed to figure out how to create custom column, but I can't figure how to get custom column display value from iProperties and how to replace or delete column.

karjalainenjani123_0-1667319123141.png

 

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

WCrihfield
Mentor
Mentor

Hi @Inventor_Enjoyer.  The PartsListColumn object has a method named "Remove" that you should be able to use to remove an existing one.  And the PartsListColumns object has a method called "Add" that you can use to add a new one to the PartsList.  If you want this column to contain values from a 'custom' iProperty named "Part Type", then you would have to specify PropertyTypeEnum.kCustomProperty as the first input value in the Add method.  Then the PropertySetId String for the 'custom' PropertySet is "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", as the second input value.  Then specify "Part Type" (the name of the custom iProperty) as the third input value.  Then the fourth requested input is asking for you to specify an existing column (by its Index number), as a reference for where to place this new column in relation to, and since you want it to be the first column, you can specify 1 there.  Then the fifth requested input is asking 'insert before?' that column you just specified, and in this case we want our new column to be before that column, so specify True there.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

Inventor_Enjoyer
Contributor
Contributor

Thanks for answering! I got Part Type column right, but still can't remove Dim column. Do I need to make new variable as PartsListColumn for it to work?

My code currently looks like this:

 

Dim oCol As PartsListColumn
Set oCol = oSheet.PartsLists.Item(1).PartsListColumns.Add(kCustomProperty, "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", ("sparepart"), 2, False)
If oCol.Title = "sparepart" Then oCol.Width = 1.3

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Maybe something like this:

Dim oPList As PartsList
Set oPList = oSheet.PartsLists.Item(1)
Dim oPLCol As PartsListColumn
Dim oCol As PartsListColumn
For Each oPLCol In oPList.PartsListColumns
	If oPLCol.Title = "Dim" Then
		Call oPLCol.Remove
	End If
	If oPLCol.Title = "sparepart" Then
		Set oCol = oPLCol
	End If
Next
If oCol Is Nothing Then
	Set oCol = oPList.PartsListColumns.Add(kCustomProperty, "{D5CDD505-2E9C-101B-9397-08002B2CF9AE}", "sparepart", 2, False)
	oCol.Width = 1.3
End If

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

Inventor_Enjoyer
Contributor
Contributor

Looks like I was missing the Call before oPLCol.Remove and If statements make this more clear aswell. Thanks for helping!

0 Likes