Creating a View Label with Custom Properties

Creating a View Label with Custom Properties

dbrown3J3B6E
Participant Participant
1,624 Views
6 Replies
Message 1 of 7

Creating a View Label with Custom Properties

dbrown3J3B6E
Participant
Participant

I was able to get a code from another forum post and modified it to my needs to include our custom properties. I'm now having two issues I can't find the answer to. I'm attaching the code I'm using as well as the .ipt and .idw files.

 

1. I'm trying to make it so that the label automatically shows up correctly when a view is created. I saved the iLogic rule in the template file and also opened the "Event Triggers" and applied this rule to all of them. It seems to run the rule when I do a save, but ideally I would like it to populate when the view is created. I thought applying the rule to "Drawing View Change" would do this, but it doesn't.

 

2. I want to have two different view labels, one for .ipt files and one for .iam files. How can I modify this code to do that?

'start of ilogic code
Dim oDoc As DrawingDocument:  oDoc = ThisDoc.Document
oModel = ThisDoc.ModelDocument

Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView

oSheets = oDoc.Sheets

For Each oSheet In oSheets
oViews = oSheet.DrawingViews
	For Each oView In oViews
	oView.ShowLabel = True
		Try
		'get the property ID for these custom iProperties from the model referenced by the view
		o_iPropID_1 = oModel.PropertySets.Item("User Defined Properties").Item("FCE_PartNumber").PropId
		o_iPropID_2 = oModel.PropertySets.Item("User Defined Properties").Item("DESCRIPTION_AP").PropId
		o_iPropID_3 = oModel.PropertySets.Item("User Defined Properties").Item("MATERIAL_A").PropId
		o_iPropID_4 = oModel.PropertySets.Item("User Defined Properties").Item("STANDARD_A").PropId
		Catch
		'here you could add a message that one or more of the custom iProperties were not found
		End Try
		
		Try
		'format the custom iproperty string and add the property ID
		oString1 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='FCE_PartNumber' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_1  & "'>FCE_PartNumber</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString2 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='DESCRIPTION_AP' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_2 & "'>DESCRIPTION_AP</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString3 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='MATERIAL_A' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_3 & "'>MATERIAL_A</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString4 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='STANDARD_A' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_4 & "'>STANDARD_A</Property><Br/>"
		oStringScale = "<StyleOverride FontSize='0.3'>SCALE <DrawingViewScale/></StyleOverride>"

		'add the custom iproperties to the view label
		oView.Label.FormattedText = oString1 &  oString2 &  oString3 &  oString4 & oStringScale
		Catch
		'do nothing if error
		End Try
	Next
Next
'end of ilogic code

 

0 Likes
Accepted solutions (1)
1,625 Views
6 Replies
Replies (6)
Message 2 of 7

bradeneuropeArthur
Mentor
Mentor
Accepted solution

for point 1 you need to use events.

You can do that easily with an add-in.

for point 2:

'start of ilogic code
Dim oDoc As DrawingDocument:  oDoc = ThisDoc.Document
oModel = ThisDoc.ModelDocument

Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView

oSheets = oDoc.Sheets

For Each oSheet In oSheets
oViews = oSheet.DrawingViews
	For Each oView In oViews
		oView.ShowLabel = True
		If oView.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kAssemblyDocumentObject
		Try
		'get the property ID for these custom iProperties from the model referenced by the view
		o_iPropID_1 = oModel.PropertySets.Item("User Defined Properties").Item("FCE_PartNumber").PropId
		o_iPropID_2 = oModel.PropertySets.Item("User Defined Properties").Item("DESCRIPTION_AP").PropId
		o_iPropID_3 = oModel.PropertySets.Item("User Defined Properties").Item("MATERIAL_A").PropId
		o_iPropID_4 = oModel.PropertySets.Item("User Defined Properties").Item("STANDARD_A").PropId
		Catch
		'here you could add a message that one or more of the custom iProperties were not found
		End Try
		
		Try
		'format the custom iproperty string and add the property ID
		oString1 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='FCE_PartNumber' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_1  & "'>FCE_PartNumber</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString2 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='DESCRIPTION_AP' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_2 & "'>DESCRIPTION_AP</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString3 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='MATERIAL_A' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_3 & "'>MATERIAL_A</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString4 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='STANDARD_A' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_4 & "'>STANDARD_A</Property><Br/>"
		oStringScale = "<StyleOverride FontSize='0.3'>SCALE <DrawingViewScale/></StyleOverride>"

		'add the custom iproperties to the view label
		oView.Label.FormattedText = oString1 &  oString2 &  oString3 &  oString4 & oStringScale
		Catch
		'do nothing if error
		End Try	
		End If
	
		If oView.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kPartDocumentObject
		Try
		'get the property ID for these custom iProperties from the model referenced by the view
		o_iPropID_1 = oModel.PropertySets.Item("User Defined Properties").Item("FCE_PartNumber").PropId
		o_iPropID_2 = oModel.PropertySets.Item("User Defined Properties").Item("DESCRIPTION_AP").PropId
		o_iPropID_3 = oModel.PropertySets.Item("User Defined Properties").Item("MATERIAL_A").PropId
		o_iPropID_4 = oModel.PropertySets.Item("User Defined Properties").Item("STANDARD_A").PropId
		Catch
		'here you could add a message that one or more of the custom iProperties were not found
		End Try
		
		Try
		'format the custom iproperty string and add the property ID
		oString1 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='FCE_PartNumber' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_1  & "'>FCE_PartNumber</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString2 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='DESCRIPTION_AP' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_2 & "'>DESCRIPTION_AP</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString3 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='MATERIAL_A' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_3 & "'>MATERIAL_A</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString4 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='STANDARD_A' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_4 & "'>STANDARD_A</Property><Br/>"
		oStringScale = "<StyleOverride FontSize='0.3'>SCALE <DrawingViewScale/></StyleOverride>"

		'add the custom iproperties to the view label
		oView.Label.FormattedText = oString1 &  oString2 &  oString3 &  oString4 & oStringScale
		Catch
		'do nothing if error
		End Try	
		End If
	Next
Next

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

Message 3 of 7

dbrown3J3B6E
Participant
Participant

Thanks so much for the revised code! As for the event trigger, I can't get it to work on view creation. The only related option I see is "Drawing View Change" and I had already applied that trigger before and it didn't work.

 

dbrown3J3B6E_0-1620042469371.png

 

0 Likes
Message 4 of 7

bradeneuropeArthur
Mentor
Mentor

Why not using "on Save event" ?

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

Message 5 of 7

dbrown3J3B6E
Participant
Participant

It works when I save the document, I was just saying it would be nice if it populated on view creation instead.

0 Likes
Message 6 of 7

bradeneuropeArthur
Mentor
Mentor

There is no "On View Create Event" 

bradeneuropeArthur_0-1620047950583.png

 

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

Message 7 of 7

floccipier
Advocate
Advocate
oString1 = "<Property Document='model' PropertySet='User Defined Properties' " _
& "Property='FCE_PartNumber' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
& o_iPropID_1 & "'>FCE_PartNumber</Property><Br/>

used this code and it works great. Just wondering if you could add bit notes that what part does what in live above. where do you get the FormatID, so if I am trying to use one of default property in label how do I do that. Not trying to get you do more code as what you have provided in post above is fantastic, just trying to understand so that I could modify it to use my need. Thanks in advance.
0 Likes