Modifying view label with standard iproperty

Modifying view label with standard iproperty

jesserop
Advocate Advocate
1,095 Views
3 Replies
Message 1 of 4

Modifying view label with standard iproperty

jesserop
Advocate
Advocate

Hi all,

 

I found this code below (for which credit goes to @Curtis_Waguespack), which can batch edit multiple drawing view labels at once.

which works really well. 
Only thing is can only batch edit standard iproperties instead of customs. 

Can anyone explain how i can edit the code to make it work like this:

Pos: <comments> 
Material: <Material> with 3.2
Thickness: <vendor>mm
Qty: <company>x

 

The default view<scale> can be removed.

Thanks in advance.

 

Adding to that, which is not necessesary but rather more handy, it would be usefull to have a userform in which you can edit the text size. But I think this makes it far more difficult.

 

 

'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("My_iProp_1").PropId
		o_iPropID_2 = oModel.PropertySets.Item("User Defined Properties").Item("My_iProp_2").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='My_iProp_1' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_1  & "'>My_iProp_1</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString2 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='My_iProp_2' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_2  & "'>My_iProp_2</Property><Br/>"

		'add the custom iproperties to the view label
		oView.Label.FormattedText = "<DrawingViewName/><Br/>"  &  oString1 &  oString2
		Catch
		'do nothing if error
		End Try
	Next
Next
'end of ilogic code

 

 

 

 

0 Likes
1,096 Views
3 Replies
Replies (3)
Message 2 of 4

bradeneuropeArthur
Mentor
Mentor

Choose these options:

Means no code needed at all!

bradeneuropeArthur_0-1648820835821.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

0 Likes
Message 3 of 4

jesserop
Advocate
Advocate

Hi,

 

Thanks for your answer, I understand this is working. 
The issue is that when you have a drawing with for example cutting contours, you can't change multiple views at once. 
You have to do the writing and the linking of <iproperty> all by mouseclicks. Which is a hugely time consuming job. 

Therefore I was looking to find a macro that did it for me, this macro seems to work when I create some temporary custom iprops. Problem is that i'm not able to work out the way how to change those iprops to standard iproperties.

0 Likes
Message 4 of 4

A.Acheson
Mentor
Mentor

This information is available in the API help although there isn't many direct samples like Curtis kindly provided. 

There is a few keywords you can use to get to the information, it is easier with the built in help file as the online versions can be hard to get to the information you need easily. 

Document Properties

Property Sets

FormatID 

PropertyID

 

The below code has been extracted from the API help on the Document Properties page and I have left in the comments for easy understanding. This will allow you to retrieve all the information to work with propertysets (API Terminology )/ iproperties

' Set a reference to the active document.
' This assumes a document is open.
Dim oDoc As Document
 oDoc = ThisApplication.ActiveDocument
      
' Obtain the PropertySets collection object
Dim oPropsets As PropertySets
 oPropsets = oDoc.PropertySets

' Iterate through all the PropertySets one by one using for loop
Dim oPropSet As PropertySet
For Each oPropSet In oPropsets
    ' Obtain the DisplayName of the PropertySet
    Logger.Info( "Display name: " & oPropSet.DisplayName )

    ' Obtain the InternalName of the PropertySet
    Logger.Info("Internal name: " & oPropSet.InternalName) 
	
    ' Iterate through all the Properties in the current set.
    Dim oProp As [Property]
    For Each oProp In oPropSet
	        ' Obtain the Name of the Property
		Dim Name As String
		Name = oProp.Name 

	    ' Obtain the PropertyId of the Property
		Dim PropertyId As Long
		PropertyId = oProp.PropId 
		
		Logger.Info("(" & PropertyId &")" &" - " & Name)
    Next     
Next

AAcheson_0-1648928123322.png

And here is a link to an online article to do the same thing it also has the list for handy reference. 

https://modthemachine.typepad.com/my_weblog/iproperties/

 

I have converted the code to work in ilogic

  Dim doc As Document
 doc = ThisApplication.ActiveDocument
  
  Dim ps As PropertySet
  For Each ps In doc.PropertySets
   Logger.Info( ps.Name + " / " + ps.InternalName)

    Dim p As [Property]
    For Each p In ps
      Logger.Info( "  " + p.Name + " /" + Str(p.PropId))
    Next
  Next

 

 

And here is how to adapt the original code to work with the built in iproperties. I have added "Material" iproperty. There are two things changed

1. FormatID which uses the internal name for Design Tracking Properties property set which is 32853F0F-3444-11D1-9E93-0060B03C1CA6 

2. Property ID which can be either retrieved via the first try statement or by using the code posted above to manually locate the number which in this case is 20. 

'Summary Information, {F29F85E0-4FF9-1068-AB91-08002B27B3D9} 
'Document Summary Information, {D5CDD502-2E9C-101B-9397-08002B2CF9AE} 
'Design Tracking Properties, {32853F0F-3444-11D1-9E93-0060B03C1CA6} 
'User Defined Properties, {D5CDD505-2E9C-101B-9397-08002B2CF9AE}

'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("My_iProp_1").PropId
		o_iPropID_2 = oModel.PropertySets.Item("User Defined Properties").Item("My_iProp_2").PropId
		o_MaterialID = oModel.PropertySets.Item("Design Tracking Properties").Item("Material").PropId
		'or for standard iproperties just input the property id extracted from a rule.  
		'o_MaterialID = 20
		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='My_iProp_1' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_1  & "'>My_iProp_1</Property><Br/>"
		'format the custom iproperty string and add the property ID
		oString2 = "<Property Document='model' PropertySet='User Defined Properties' " _
		&  "Property='My_iProp_2' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}' PropertyID='" _
		& o_iPropID_2 & "'>My_iProp_2</Property><Br/>"
			
		oString3 = "<Property Document='model' PropertySet='Design Tracking Properties' " _
		&  "Property='Material' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='" _
		& o_MaterialID  & "'>Material</Property><Br/>"
		
		'Extracted from API sample simplified 
		oString4 = "<Property Document='model' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='20' />"

		'add the custom iproperties to the view label
		oView.Label.FormattedText = "<DrawingViewName/><Br/>"  &  oString1 &  oString2 &  oString3 & oString4
		Catch
		'do nothing if error
		End Try
	Next
Next

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes