How to assign a iProperty to a textbox in my title through VB

How to assign a iProperty to a textbox in my title through VB

david.lafleur4MYDQ
Contributor Contributor
788 Views
3 Replies
Message 1 of 4

How to assign a iProperty to a textbox in my title through VB

david.lafleur4MYDQ
Contributor
Contributor

I'm working right now to try making a macro that will change the property in a specific textbox in my titleblock (in a .idw). Right now, that textbox contain "FILENAME AND PATH", which is a standard property of inventor, but I want it to be "FilePath", which is a custom property.

 

Right now, I have this, which just open the sketch of the title, put the value of the property "FilePath" and close the sketch (see first image). The problem is, the "FILENAME AND PATH" property is still assign to the textbox itself. I need to find a way to clear any value linked to it and link the new "FilePath" one. I'm trying to find the documentation for accessing that kind of information but can't find it. Essentially, it would be the equivalent to go on the Format text window (see image 2), select in the drop list "Custom iproperties" and select "FilePath" to add it.

 

 

0 Likes
Accepted solutions (1)
789 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @david.lafleur4MYDQ.  In a case like this, you will have to deal with the TextBox.FormattedText property, instead of the TextBox.Text property.  Then you will have to deal with XML tags within its String value.  Here is a link to the official online help page for dealing with the XML tags in FormattedText scenarios.  The link is not super helpful, which is why this type of task is often fairly complicated to deal with entirely by code, instead of using the ready made User Interface tool.  When you look at the Text property of that TextBox, you would probably just see that "<FilePath>" text when it is already set-up properly, but simply putting that into the Text property of the TextBox will not work for setting it up that way.  Of course it has to be much more complicated 😉.  So, what most folks do in cases like this, is set it up manually, using the User Interface tool, the way you want it first.  Then use some code to 'read' what that TextBox.FormattedText contains.  Then use that data as a guide to help them input the correct data within their regular code for setting it up right.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Assuming that the TextBox has not been changed yet, and is still pointing to the "<FINENAME AND PATH>", you can try this code out, to see if it will work for you.  The new value I am specifying for the FormattedText does not contain the "PropertyID=" part, but I'm thinking that may be filled in for you.

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this code to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	If oDDoc.ActiveSheet.TitleBlock Is Nothing Then Exit Sub
	oTB = oDDoc.ActiveSheet.TitleBlock
	oTBDef = oTB.Definition
	Dim oTBDefSketch As DrawingSketch = Nothing
	oTBDef.Edit(oTBDefSketch)
	For Each oTBox As Inventor.TextBox In oTBDefSketch.TextBoxes
		If oTBox.Text = "<FINENAME AND PATH>" Then
			oNewFText = "<Property Document='Model' PropertySet='User Defined Properties' Property='FilePath' FormatID='{D5CDD505-2E9C-101B-9397-08002B2CF9AE}'>FilePath</Property>"
			oTBox.FormattedText = oNewFText
		End If
	Next
	oTBDef.ExitEdit(True)
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 4

david.lafleur4MYDQ
Contributor
Contributor
Thanks a lot, thats what I was looking for. Wouldn't expect we literally have overwrite the XML line through VB instead of just accessing a property of the sketch object and modify it. I had to modify the 'Model' property for 'Drawing' though, because I was trying to get the iproperty in a .dwf of an .iam and trying with that exact code would only make me able to access the iproperty of the later. I have to say, I have experience with other few languages end most of the time I can get away by finding code examples and/or documentation, but it is quite hard to find information for inventor objects/structure/definitions.
0 Likes