Changing proterties in text box of drawing (idw) header

Changing proterties in text box of drawing (idw) header

Darrell.johnson
Enthusiast Enthusiast
606 Views
5 Replies
Message 1 of 6

Changing proterties in text box of drawing (idw) header

Darrell.johnson
Enthusiast
Enthusiast

Hello, is it possible to assign a different property in a text box in a header with iLogic?

 

Darrelljohnson_0-1646667514599.png

 

Dim oTG As TransientGeometry
    oTG = ThisApplication.TransientGeometry
Dim oDoc As DrawingDocument
    oDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet
    oSheet = oDoc.ActiveSheet
Dim oTB As TitleBlock
    oTB = oSheet.TitleBlock
Dim oDef As TitleBlockDefinition
    oDef = oTB.Definition

Dim referencedDocument As Document
referencedDocument = oDoc.ReferencedDocuments.Item(1)

Dim oSketch As DrawingSketch
Call oDef.Edit(oSketch)

Dim oTextBoxes As TextBoxes
    oTextBoxes = oSketch.TextBoxes

Dim oBox As Inventor.TextBox            
    For Each oBox In oTextBoxes
        If oBox.Text = "<Dokumentenart>" Then 'The text parameter you want to change            
            Call oDef.Edit(oSketch)
            oBox.Text= "????"
        End If
    Next
	
Call oDef.ExitEdit(True)
InventorVb.DocumentUpdate()

 

This is my code so far, but with this I'm only able to assign text and not the mentoined paramters or properties.

 

Thanks in advance

 

Regards Darrell

0 Likes
Accepted solutions (2)
607 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Darrell.johnson.  If you want to change which iProperty or Parameter is being referenced within your drawing's title block, I highly recommend that you do it manually, by going into the edit mode of the title block's sketch, then editing the target drawing note using the user interface tool that you have shown in the image you posted.  Doing this by code is pretty challenging and involves working with the FormattedText property of the TextBox object and replacing a bunch of XML formatted strings and tags.  Here is the official online help page for working with FormattedText in various scenarios.  To see what that FormattedText looks like, try using either a MessageBox.Show(), or MsgBox(), or InputBox (with contents as DefaultValue, so it will be selectable), to show yourself the value of that FormattedText when you get to it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

Darrell.johnson
Enthusiast
Enthusiast

Thank you for your reply, i'll try to figure something out,

0 Likes
Message 4 of 6

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

Just a simple sample to replace the drawing property "Title" with the drawing property "Part Number". Hope it helps a bit.

 

AddReference "System.Xml"
Imports System.Xml

Dim oDrawDoc As DrawingDocument = ThisDoc.Document
Dim oTBDef As Inventor.TitleBlockDefinition = oDrawDoc.TitleBlockDefinitions(1)
Dim oSketch As DrawingSketch

oTBDef.Edit(oSketch)

Dim oTB As Inventor.TextBox
For Each oTB In oSketch.TextBoxes
	If oTB.FormattedText.Contains("TITLE") Then
		' Create the XmlDocument.  
		Dim xdoc As New XmlDocument()  
		xdoc.LoadXml(oTB.FormattedText) 
		xdoc.FirstChild.InnerText="PART NUMBER"
		Dim XMLAttr As XmlAttribute
		break
		For Each XMLAttr In xdoc.FirstChild.Attributes
			If XMLAttr.Name = "Document" Then XMLAttr.Value="drawing" 'drawing or model
			If XMLAttr.Name = "PropertySet" Then XMLAttr.Value="Design Tracking Properties" 'PropertySet name
			If XMLAttr.Name = "Property" Then XMLAttr.Value = "Part Number" 'Property name
			If XMLAttr.Name = "PropertyID" Then XMLAttr.Value = "12" 'Property ID
			If XMLAttr.Name = "FormatID" Then XMLAttr.Value = "{32853F0F-3444-11D1-9E93-0060B03C1CA6}" ' Internal name PropertySet
		Next
		oTB.FormattedText = xdoc.OuterXml
		Exit For
	End If
Next

oTBDef.ExitEdit(True)





 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 5 of 6

WCrihfield
Mentor
Mentor

Nice angle of approach @Ralf_Krieg.  At first it was throwing errors every time in my tests though.  I had to change the text it was looking for from "TITLE" to "Property='Title'", because it kept finding the text box for the label of the title area of my title block before it would find the text box for the value of the title (the one that contains XML tags).  After that, it seemed to work OK for my test drawing.  I believe I've used simple Find/Replace type String tools to do about the same thing before too, without implementing the actual XML Namespace tools, but this is nice too, and likely a bit more proper.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

Darrell.johnson
Enthusiast
Enthusiast

Hello, this works perfectly. Thank you very much for your help!

0 Likes