iLogic Code for drawing view label change

iLogic Code for drawing view label change

michael6T7C2
Participant Participant
2,611 Views
6 Replies
Message 1 of 7

iLogic Code for drawing view label change

michael6T7C2
Participant
Participant

Can someone please help me, I have no coding experience and really need an iLogic code.

 

This is basically what it needs to do:

 

In my drawing space I want to select a drawing view and then hit run code.

The code needs pull 3 iProperties and some text to the drawing view label. The first is an existing Inventor iProperty and the two remaining are custom iProperties.

 

I currently need to add these manually into every drawing view label, but would like to automate it.

 

<PART NUMBER>

<Member>

<TotalQty> x off

 

Any help would be so greatly appreciated!

 

Format Text Window 3.jpg

 

 

 

 

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

mcgyvr
Consultant
Consultant

@michael6T7C2 

How's this?

 

 

Dim oSSet As SelectSet = ThisDoc.Document.SelectSet
If oSSet.Count = 0 Then
	MsgBox("Select a drawing view")
	Exit Sub
End If

'Reference to the drawing view from the 1st selected object
Dim oView As DrawingView = TryCast(oSSet.Item(1), DrawingView)

If oView IsNot Nothing Then
		'get the model
	    oModelName = oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
         'get the properties from the model     
		oPartNumber = iProperties.Value(oModelName, "Project", "Part Number")
		oMember = iProperties.Value(oModelName, "Custom", "Member")  
		oTotalQty = iProperties.Value(oModelName, "Custom", "TotalQty") 

		 'modify the view label as needed
		 oView.Label.FormattedText = oPartNumber & vbCrLf & oMember & vbCrLf & oTotalQty & " X OFF"
	
Else
	MsgBox("Selected object is not a drawing view")
End If

 

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 4 of 7

iUser
Advocate
Advocate
Accepted solution

@mcgyvr Thanks for your help. This code unfortunately doesn't keep the link to the iProperties when you double click on the view label after running the code. It leaves it as text.

 

I got someone else to look at this and they gave me some code that I slightly modified and it looks like its working. The only thing that I still need to figure out is how to underline the text at the end?

 

If ThisApplication.ActiveDocumentType = kDrawingDocumentObject Then
Dim oView As DrawingView
oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select View")
MsgBox(oView.Name)
oView.ShowLabel = True 'show label for selected view
'Inventor.Document.PropertySets.Item("Design Tracking Properties")
'ThisPartInfo = DrawingView.ScaleString & " SCALE" & vbLf & partName & " Name" & vbLf & DesProperty.Value & " Description"
oPartNumber = 	"<Property Document='model' 	PropertySet='Design Tracking Properties' 	Property='Part Number'>								PART NUMBER	</Property><Br/>"

o_iPropID_1 = ThisDoc.ModelDocument.PropertySets.Item("User Defined Properties").Item("Member").PropId
oMember = 		"<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/>"
		
o_iPropID_2 = ThisDoc.ModelDocument.PropertySets.Item("User Defined Properties").Item("TotalQty").PropId
oTotalQty =	"<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>"

oView.Label.FormattedText = oPartNumber & oMember & oTotalQty & " X OFF "

End If

 

0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor

Here's another method I sometimes use when I need to insert iProperty references (not just static text values) into a FormattedText String.  I first get the target PropertySet object(s) and the  Property object(s).  Then as I'm assembling the needed sub-string for the iProperty reference, I insert the 'PropertySet.InternalName' in place of the FormatID value, and insert the 'Property.PropId' in place of the PropertyID value.  Pay close attention, because the 'value' is enclosed by one apostrophe (') on each side...one right after the = sign, and one right after the value.  You will also notice that the end of my string ends with a space, then "/>".  That last couple of characters will be automatically replaced with , for example ">PART NUMBER</Property>" by Inventor, because it already know what you want.  You can confirm by un-commenting the two InputBox lines temporarily, as a test.

 

Here's the code:

 

'to select the drawing view after you run the rule
'Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter,"Select a drawing view.")

Dim oSSet As SelectSet = ThisDrawing.Document.SelectSet
If oSSet.Count = 0 Then
	MsgBox("You need to pre-select a drawing view before running this rule.  Exiting.", , "")
	Exit Sub
End If
oView = oSSet.Item(1)
If oView Is Nothing Then Exit Sub
	
'get the view's model document
Dim oMDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument

'Part Number preparations - get the property set object, get property object
Dim oDTProps As Inventor.PropertySet = oMDoc.PropertySets.Item("Design Tracking Properties")
Dim oPNProp As Inventor.Property = oDTProps.Item("Part Number")
'use above objects to fill-in the FormattedText line for Part Number iProperty reference
Dim oPN As String = "<Property Document='model' FormatID='" & oDTProps.InternalName & "' PropertyID='" & oPNProp.PropId & "' />"

'custom properties preparations - get property set object, and property objects
Dim oCProps As Inventor.PropertySet = oMDoc.PropertySets.Item("Inventor User Defined Properties")
Dim oMbrProp As Inventor.Property = oCProps.Item("Member")
Dim oTtlQtyProp As Inventor.Property = oCProps.Item("TotalQty")
'use those objects to fill-in the FormattedText line for those iProperty references
Dim oMbr As String = "<Property Document='model' FormatID='" & oCProps.InternalName & "' PropertyID='" & oMbrProp.PropId & "' />"
Dim oTtlQty As String = "<Property Document='model' FormatID='" & oCProps.InternalName & "' PropertyID='" & oTtlQtyProp.PropId & "' />"

'to preview the (selectable) FormattedText 'Before' you change it.
'a = InputBox("","Before Changes:", oView.Label.FormattedText)

'assemble them using <Br/> to go to the next line
oView.Label.FormattedText = oPN & "<Br/>" & oMbr & "<Br/>" & oTtlQty

'to preview the (selectable) FormattedText 'After' you change it.
'b = InputBox("","After Changes:", oView.Label.FormattedText)

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you have time, please... Vote For My IDEAS 💡or you can Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 7

mcgyvr
Consultant
Consultant

@iUser 

To get underlines you just do style override tags around your data.

And yes I simply put the text instead of referencing propertyID's.. Just easier. 

 

<StyleOverride Underline='True'><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></StyleOverride>

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
0 Likes
Message 7 of 7

WCrihfield
Mentor
Mentor

FYI:

Here is the link to the official online help page that 'attempts' to document how to use XML tags to manipulate FormattedText, in several different scenarios, and where all you can use it.

https://help.autodesk.com/view/INVNTOR/2021/ENU/?guid=GUID-915B75BA-4696-4fc7-A2C6-54B2BACDE7E1 

 

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)

0 Likes