Prompted Entry / Prompted Texts / PromptStrings

<?xml encoding=”UTF-8″>By Adam Nagy

You can add prompted text to a title block or border by placing instances of  “Prompted Entry” in them: 

PromptedEntry

When you are inserting such a title block or border (or a new sheet with one of those) then you’ll be prompted with a dialog called “Prompted Texts” to provide the values for them:

PromptedTexts1

When creating a new sheet, adding a new title block or border, you can specify the strings that should be used for the Prompted Entry‘s by filling in the TitleBlockPromptStrings/BorderPromptStrings variables in Sheets.AddUsingSheetFormat function, or PromptStrings variable in Sheet.AddBorder and Sheet.AddTitleBlock functions. 

The Inventor API help file has a sample for setting the Prompted Entry‘s inside the Sheet.AddTitleBlock function. You have to use the other two functions in a similar fashion.

If you want to do things dynamically, i.e. your function is supposed to work with multiple different title block and border definitions and you have to check what Prompted Entry‘s they contain, then this blog post will help. 

In my drawing the active sheet has my custom title block and border:

CustomSheet

This VBA code can create a new sheet with the same title block and border that the active sheet has, without Inventor popping up the “Prompted Texts” dialog:

'Before running this code, add reference to
' "Microsoft XML, v6.0" in this VBA project
Function GetPromptedEntryNames(sk As Sketch) As String()
On Error Resume Next
Dim names() As String
Dim tb As TextBox
For Each tb In sk.TextBoxes
Dim xml As DOMDocument
Set xml = New DOMDocument
' FormattedText might not be available on
' all TextBox, that's why using
' error handling
Call xml.loadXML(tb.FormattedText)
' Look for prompted entry
Dim node As IXMLDOMNode
Set node = xml.selectSingleNode("Prompt")
If Not node Is Nothing Then
If (Not names) = -1 Then
ReDim names(0) As String
Else
ReDim Preserve names(UBound(names) + 1) As String
End If
names(UBound(names)) = node.text
End If
Next
On Error GoTo 0
GetPromptedEntryNames = names
End Function
Sub SetValueBasedOnName(strings() As String)
Dim i As Integer
For i = 0 To UBound(strings)
Dim s As String: s = strings(i)
If s = "MyBorderPrompt" Or s = "MyTitlePrompt" Then
strings(i) = "My Value"
Else
strings(i) = "Dunno"
End If
Next
End Sub
Sub AddNewSheet()
Dim dwg As DrawingDocument
Set dwg = ThisApplication.ActiveDocument
Dim sh As Sheet
Set sh = dwg.ActiveSheet
' Arrays for the Prompted Entry's
Dim psTB() As String
Dim psB() As String
psTB = GetPromptedEntryNames(sh.TitleBlock.Definition.Sketch)
psB = GetPromptedEntryNames(sh.Border.Definition.Sketch)
' Fill them with values based on our logic
Call SetValueBasedOnName(psTB)
Call SetValueBasedOnName(psB)
' Create a new format based on active sheet
Dim sf As SheetFormat
Set sf = dwg.SheetFormats.Add(sh, "Mine")
' Create a new sheet
Dim s As Sheet
Set s = dwg.Sheets.AddUsingSheetFormat( _
sf, , "My sheet", , psTB, psB)
' If you don't want to keep the format you can delete it
Call sf.Delete
End Sub

 


Comments

One response to “Prompted Entry / Prompted Texts / PromptStrings”

  1. Hey thanks for this, Adam.
    You help me solve a problem that I was struggling with for hours.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading