Title Block Data

Title Block Data

martin_mmj
Enthusiast Enthusiast
535 Views
5 Replies
Message 1 of 6

Title Block Data

martin_mmj
Enthusiast
Enthusiast
I have this VBA code in Inventor 10. I can print the names of titleblock attributes but how can print the DATA of this attributes? Any idea or sample code?

Sub TitleBlockData()
'
Dim oDrawDoc As DrawingDocument
Dim oSheet As sheet
Set oDrawDoc = ThisApplication.ActiveDocument
Set oSheet = oDrawDoc.ActiveSheet
'
If Not oSheet.titleBlock Is Nothing Then
Set oTitleBlockDef = oSheet.titleBlock.Definition
Else
MsgBox "NoTitle block"
End If
'
For Each textBox In oTitleBlockDef.Sketch.TextBoxes
If textBox.FormattedText Like "?Prompt*" Then
Debug.Print textBox.Text
Else
End If
Next
'
End Sub
0 Likes
536 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Try this ...

Joe
--
Sub TitleBlockData()
'
Dim oDrawDoc As DrawingDocument
Dim oSheet As Sheet
Set oDrawDoc = ThisApplication.ActiveDocument
Set oSheet = oDrawDoc.ActiveSheet
Dim oTitleBlockDef As TitleBlockDefinition
Dim oTextBox As TextBox
'
If Not oSheet.TitleBlock Is Nothing Then
Set oTitleBlockDef = oSheet.TitleBlock.Definition
Else
MsgBox "NoTitle block"
End If
'
For Each oTextBox In oTitleBlockDef.Sketch.TextBoxes
If oTextBox.FormattedText Like "Prompt*" Then
Debug.Print oTextBox.Text
End If
Next oTextBox
End Sub


wrote in message news:5208688@discussion.autodesk.com...
I have this VBA code in Inventor 10. I can print the names of titleblock
attributes but how can print the DATA of this attributes? Any idea or sample
code?

Sub TitleBlockData()
'
Dim oDrawDoc As DrawingDocument
Dim oSheet As sheet
Set oDrawDoc = ThisApplication.ActiveDocument
Set oSheet = oDrawDoc.ActiveSheet
'
If Not oSheet.titleBlock Is Nothing Then
Set oTitleBlockDef = oSheet.titleBlock.Definition
Else
MsgBox "NoTitle block"
End If
'
For Each textBox In oTitleBlockDef.Sketch.TextBoxes
If textBox.FormattedText Like "?Prompt*" Then
Debug.Print textBox.Text
Else
End If
Next
'
End Sub
0 Likes
Message 3 of 6

martin_mmj
Enthusiast
Enthusiast
Thank you Joe for reply.
But I need 'value' of fields stored in title block. This code shows only 'name' of this atrributes.

For example I need :
name : "att01_DrawingScale"
value : "1:10"
0 Likes
Message 4 of 6

Anonymous
Not applicable
Perhaps you are not seeing anything because of your condition statement?

wrote in message news:5208855@discussion.autodesk.com...
Thank you Joe for reply.
But I need 'value' of fields stored in title block. This code shows only
'name' of this atrributes.

For example I need :
name : "att01_DrawingScale"
value : "1:10"
0 Likes
Message 5 of 6

Anonymous
Not applicable
When working with title blocks, borders, and sketch symbols there is the
concept of the definition and instances of the definition. The definitions
are shown in the Drawing Resources area of the browser and are what you
construct when you define a new title block, border, or sketched symbol.
Within these definitions you can define prompted and property text fields.

When you use one of these definitions, i.e. place a title block on a sheet,
the end-user is prompted to supply values for any of the prompted text
fields. Property text fields are automatically filled in using the current
values of the specified properties.

Let's say you've created a new title block definition that contains a
prompted text field where you set the text when placing it to be
"". When you insert this title block into a sheet you are
prompted to supply the text for this field. For example, "ACME Castings".
The inserted title block is represented as a TitleBlock object and
represents the specific instance of the definition on this sheet. You can
also create additional sheets and insert the title block on each of those
and enter different strings for the prompted text. For example one sheet
one the prompted text in title block might be "ACME Castings" and on sheet
two the same prompted text might be "ABC Machining".

The defintion object contains the defining information for the title block.
To get the value entered for the prompted values you need to ask for from
the instance you want the information in the context of. For example, if
you ask for the result from the text in the context of sheet one you would
get "ACME Castings" and if you ask for it in the context of sheet two you'll
get "ABC Machining". It's the same text box in the definition but the
result can be different for each instance. The GetResultText method is
supported by the Border, TitleBlock, and SketchedSymbol objects and allows
you to text that is being displayed by an particular instance.

To use the GetResultText you first need to go to the definition object and
find the TextBox object that you want the result text for. You then use
this TextBox object as input to the GetResultText method to get back the
text that is currently being displayed for that instance

We did find one issue in the current implementation that makes all of this a
bit confusing. When you look at the TextBox objects you obtain from a
definition object, the Text property is returning an incorrect value. It
should be returning the string you entered as the prompt text. In this
example, the Text property should be returning the string "".
Instead it is currently returning the value of this string in one of the
instances. This is incorrect and will be fixed in an upcoming release. To
get the instance text you need to use the GetResultText. The Text property
could be useful in identifying the particular field to want to use as input
to the GetResultText method, but with the current behavior you don't know
what value it will contain so it's basically useless.

Below is some sample code that demonstrates getting all of the prompted text
from the title block on the active sheet. I've written a small function
that extracts the prompt text from the FormattedText property. If the Text
property was behaving correctly I could have just used it.

Public Sub GetTitleBlockText()
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

' Get the title block used by the active sheet.
Dim oTitleBlock As TitleBlock
Set oTitleBlock = oDrawDoc.ActiveSheet.TitleBlock

' Get the associated title block definition.
Dim oTitleBlockDef As TitleBlockDefinition
Set oTitleBlockDef = oTitleBlock.Definition

' Iterate through the text in the definition.
Dim oText As TextBox
For Each oText In oTitleBlockDef.Sketch.TextBoxes
' Get the prompt string. If this text box is not a
' prompted text text box this will return "".
Dim strPromptText As String
strPromptText = GetPromptField(oText.FormattedText)

If strPromptText <> "" Then
' Get the text that was provided by the end-user.
Debug.Print "Prompt Text = " & strPromptText
Debug.Print "Result = " & oTitleBlock.GetResultText(oText)
End If
Next
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) <> " 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 < or > with < and > symbols.
GetPromptField = Replace(GetPromptField, "<", "<")
GetPromptField = Replace(GetPromptField, "&gr;", ">")

Exit Function
ErrorFound:
GetPromptField = ""
End Function

wrote in message news:5208688@discussion.autodesk.com...
I have this VBA code in Inventor 10. I can print the names of titleblock
attributes but how can print the DATA of this attributes? Any idea or sample
code?
Message 6 of 6

martin_mmj
Enthusiast
Enthusiast
Nice code. A lot of THANKS for Brian Ekins.
0 Likes