Synchronize Prompted Entry TextBox values

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

If you use the same Title Block definition for all Sheet’s then you can go through its Definition, check for the Prompted Entry TextBox’s and keep track of what each TextBox had as value in the main/master sheet where all these values are correct. Now you can update all the other sheets with those values. You could easily modify this code to also update Prompted Entry’s on sheets which are using a different Title Block definition – if they use the same TextBox.Text.

Here is a VBA sample

' "Dictionary" coming from
' "Microsoft Sctipting Runtime" library
' You could simply use an array instead
Function GetPromptedEntries(block As TitleBlock) As Dictionary
Set GetPromptedEntries = New Dictionary
Dim boxes As TextBoxes
Set boxes = block.Definition.Sketch.TextBoxes
Dim box As TextBox
For Each box In boxes
' Check if it's a Prompted Entry
If InStr(1, box.FormattedText, "<Prompt") Then
Dim value As String
value = block.GetResultText(box)
Call GetPromptedEntries.Add(box, value)
End If
Next
End Function
Sub SetPromptedEntries(block As TitleBlock, dict As Dictionary)
If block Is Nothing Then Exit Sub
If dict.Count < 1 Then Exit Sub
Dim firstBox As TextBox
Set firstBox = dict.Keys(0)
Dim blockSketch As DrawingSketch
Set blockSketch = block.Definition.Sketch
' At the moment we only do the update for sheets
' using the same block definition, because we are using
' the TextBox objects as keys, which would be different
' for different title block definitions
If Not firstBox.parent Is blockSketch Then Exit Sub
Dim box As TextBox
Dim value As String
For Each box In dict
value = dict(box)
Call block.SetPromptResultText(box, value)
Next
End Sub
Sub SyncPromptedEntries()
Dim dwg As DrawingDocument
Set dwg = ThisApplication.ActiveDocument
Dim curSheet As Sheet
Dim entries As Dictionary
For Each curSheet In dwg.Sheets
If entries Is Nothing Then
Set entries = GetPromptedEntries( _
curSheet.TitleBlock)
Else
Call SetPromptedEntries( _
curSheet.TitleBlock, _
entries)
End If
Next
End Sub

Comments

3 responses to “Synchronize Prompted Entry TextBox values”

  1. Nik Barbour Avatar
    Nik Barbour

    Thanks for this – it is exactly what I was looking for.

  2. Hi thanks for this, excatly what I’m looking for. But I copied and pasted the code as a module in Inventor 2012, but I’m getting an error.
    “user defined type not defined”
    Does this sample work? Or do I need to enable the Microsoft Sctipting Runtime?
    Cheers,
    Ben

  3. Hi Ben,
    Yes, this specific solution is using the Dictionary class from Microsoft Scripting Runtime. So inside VBA you can simply go to “Tools >> References…”, search for “Microsoft Scripting Runtime” and tick the box next to it.
    Cheers,
    Adam

Leave a Reply to BenCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading