How to access a title block prompted entry field?

How to access a title block prompted entry field?

Anonymous
Not applicable
1,964 Views
3 Replies
Message 1 of 4

How to access a title block prompted entry field?

Anonymous
Not applicable
I would like to create a macro that takes the prompted entry text entered when a new sheet is created (as the prompted entry is defined in the title block), and rename the active sheet with this text.

I assume that it's ActiveSheet.Name that I have to set for the sheet name, but I can't find any info on how to reference a prompted entry.

In my case, I have a prompted entry that ends up being a title block property field ''.

Thanks in advance!
-KB
0 Likes
1,965 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Here's some example code that I believe does what
you want.  It's searching for a prompted entry named "<Part
Name>".  You can easily change that.  The code is also attached in
case there's a formatting problem with this post.

 

Public Sub SetSheetName()
    Dim
oDrawDoc As DrawingDocument
    Set oDrawDoc =
ThisApplication.ActiveDocument
   
    Dim
oSheet As Sheet
    Set oSheet =
oDrawDoc.ActiveSheet
   
    ' Get the
prompted text value from the title block.
    ' This is done
by first getting the text box in the title
    ' block
definition that defines the prompted text.  Then
    '
you can use this to get the value specified for this
    '
particular title block instance.
    Dim oTitleBlockDef As
TitleBlockDefinition
    Set oTitleBlockDef =
oSheet.TitleBlock.Definition
    Dim oTextBox As
TextBox
    Dim bFound As Boolean
    bFound
= False
    For Each oTextBox In
oTitleBlockDef.Sketch.TextBoxes
        If
GetPromptField(oTextBox.FormattedText) = "<Part Name>"
Then
           
bFound =
True
            Exit
For
        End If
   
Next
   
    If bFound
Then
        oSheet.Name =
oSheet.TitleBlock.GetResultText(oTextBox)
   
Else
        MsgBox "Specified formatted
text was not found in the title block."
    End If
End
Sub

 

' Get the text value of the prompted text.  It
extracts this from the
' formatted text.  If there's a failure then an
empty string is returned.
Private Function GetPromptField(ByVal FormattedText
As String) As String
    On Error GoTo ErrorFound

 

    ' Verify that this is a prompt
field.
    If Left$(FormattedText, 7) <> "<Prompt"
Then
        GetPromptField =
""
        Exit
Function
    End If

 

    ' Get the text that is to the
right of the first ">" symbol
    ' and to the left of the
last "<" symbol.
    GetPromptField = Right$(FormattedText,
Len(FormattedText) - InStr(FormattedText, ">"))
   
GetPromptField = Left$(GetPromptField, InStr(GetPromptField, "<") -
1)

 

    ' Replace any &lt; or
&gt; with < and > symbols.
    GetPromptField =
Replace(GetPromptField, "&lt;", "<")
    GetPromptField
= Replace(GetPromptField, "&gt;", ">")

 

    Exit
Function
ErrorFound:
    GetPromptField = ""
End
Function

0 Likes
Message 3 of 4

Anonymous
Not applicable
Wow! that's great! thanks a lot Brian!

One further addition to this to make it super elite...

How can I make the macro run after every time the prompted entry field is changed?
0 Likes
Message 4 of 4

Anonymous
Not applicable

A macro won't do that but I think it should be
possible to create an Add-In that would.  The Add-In would watch the
OnDocumentChange event and look at the information that passed with the event to
determine what kind of edit took place.  If it was a prompted text change
then it can update the sheet name.  The guts of doing something like this
is covered in my blog post
href="http://modthemachine.typepad.com/my_weblog/2008/10/converting-vba-auto-macros-to-an-add-in.ht...

 

In addition to this you'll need the macro code and
some experimenting.  To determine how to handle the event, there's a tool
delivered as part of the SDK called Event Watcher that will let you see what
events are being fired and what information is provided with the
event.

 

Have fun. 🙂



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Wow!
that's great! thanks a lot Brian! One further addition to this to make it
super elite... How can I make the macro run after every time the prompted
entry field is changed?
0 Likes