Change specific Text format in the Title block
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I am trying to automate inventor drawing for specific cases and I want to create a code that checks Titleblock textformat with weight. I want to be able to format the weight (how many digits after the comma, unite etc) or to promt the user for specific text.
This seams to be way more complicated than I thought so here is the code that i managed to put together with a lot of help from chatGPT.
I think the error is in the fact that the code does not specify whitch textformat in the title block sketch should be worked on.
The question:
How do I make the code to check for a specific text format in the sketch of the title block?
The code:
' Get the active document.
Dim oDoc As Document = ThisApplication.ActiveDocument
' Update the physical properties and calculate the weight.
oDoc.Update2()
Dim weight As Double = oDoc.ComponentDefinition.MassProperties.Mass
' Get the title block definition.
Dim titleBlockDef As TitleBlockDefinition = oDoc.ActiveSheet.TitleBlock.Definition
' Loop through all the text formats in the "Schriftfeld" sketch.
For Each TextFormat As TextFormat In titleBlockDef.Sketches.Item("Schriftfeld").TextFormats
' Check if the text format contains the word "weight".
If TextFormat.Text.Contains("weight") Then
' Delete the text and variable.
TextFormat.Text = ""
TextFormat.Variable = Nothing
End If
Next
' Prompt the user for the weight.
Dim weightPrompt As String = InputBox("What weight should it have?", "Weight Prompt", weight.ToString())
' Add the new text format with the user's weight.
Dim newFormat As TextFormat = titleBlockDef.Sketches.Item("Schriftfeld").TextFormats.Add(weightPrompt, 0, 0)
newFormat.Field = Nothing