Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reading "Prompted Entry" Title Block info with VBA

6 REPLIES 6
Reply
Message 1 of 7
joeabberley
4873 Views, 6 Replies

Reading "Prompted Entry" Title Block info with VBA

I've spent ages reading similar-ish posts, and made up some code to read the values from the title block on an idw.

Does it make any difference if the 'type' of the property feild is 'Prompted Entry' (I don't think it should)

I just want my VBA prog to read all the values in the titleblock. Here is the code to try and read one value, and then display it in a massage box:

Dim oPropsets As PropertySets
Set oPropsets = ThisApplication.ActiveDocument.PropertySets
Dim oBlock As PropertySet
Set oBlock = oPropsets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
Dim oBlockProp As Property
For Each oBlockProp In oBlock
Select Case oBlockProp.Name
Case "COMPANY"
MsgBox oBlockProp.Value
End Select
Next

Thanks for any help

6 REPLIES 6
Message 2 of 7
joeabberley
in reply to: joeabberley




I have been experimenting with all the ways I think people
have been doing this, and I can't get anything to work.
I would like to know if this is actually possible, or
am I just wasting time.

If there is an old drawing, with 'prompted entry' info
in the title block, can I run a macro that will read that
titleblock information and display it in a textbox?

If so how?

I would be very grateful if someone could help me with this

Thanks

Joe


Message 3 of 7
Anonymous
in reply to: joeabberley

The value of a prompted entry is in the FormatedText property of the
titleblocks TextBox. I use the following function to retrieve the value for
a specified promted text.

Public Function IvGetPromptedValue(ByRef oTbl As Inventor.TitleBlock, _
sPromptName As String) As String
'get value of specified prompted property from titleblock and return it
'with Function. If property can't be found return "-1"
'
'references:
'mXML.ParseXML

Dim oTextBoxes As Inventor.TextBoxes
Dim lBox As Long

'get textboxes of titleblock
Set oTextBoxes = oTbl.Definition.Sketch.TextBoxes

'iterate through text boxes and find value
For lBox = oTextBoxes.Count To 1 Step -1
If Left(GetFormattedText(oTextBoxes(lBox)), 😎 = "" Then
Dim sValue As String
sValue = ParseXML(oTextBoxes(lBox).FormattedText, "Prompt")

If UCase(sValue) = UCase(sPromptName) Then
IvGetPromptedValue = oTbl.GetResultText(oTextBoxes(lBox))
Exit Function
End If
End If
Next

IvGetPromptedValue = "-1"
End Function


Private Function GetFormattedText(ByRef oTextBox As Inventor.TextBox) As
String
'get value of formatted text property. If error return error string
On Error Resume Next

GetFormattedText = oTextBox.FormattedText

If Err Then
Err.Clear
GetFormattedText = ""
End If
End Function

-Frank
Message 4 of 7
joeabberley
in reply to: joeabberley



Thanks very much for the help, but as I'm a bit new to VBA
I am very frustrated with myself as I cannot understand
everything in the code.

I'm used to using subs, and am a bit unsure about functions.
I'm not sure what the 'ByRef oTbl As Inventor.titleblock'
is refering to in the arguments for the first function.
And is the 'ParseXML' important, as I can't find any
reference to it in my VBA help. How do the two functions
relate to each other, ie which on do I call.
And Im having trouble calling the functions, I'm not sure
what to put in the argument list.

(I'm worried I put the wrong thing in my original question,
I want to read the values from the titleblock, and just
use them elsewhere. As long as I can get a set of text
strings containing the values in the title block, i'll be
happy)

Thanks for the previous help

Message 5 of 7
Anonymous
in reply to: joeabberley

- You can use a function the same way that you use
a sub.  In this case a function is used because it can return a value
to the calling statement.

 

- ByRef passes the address of the argument
instead of the value, which lets you change the variables actual
value.

 

- oTbl As Inventor.Titleblock is the titleblock
object which represents an instance of a title block on a sheet.

face=Arial size=2>    
 

 

- ParseXML is a function that I've got from
somebody on the net, that returns the value of an XML string.

 

The following code returns the value for a prompted
property of a title block on the first sheet of a drawing document.  Let me
know if you need more information on how to extract the file property values of
the title block.

 


Frank

 

 

'start
code========================================================================

Option Explicit


Const xs = "<"
Const xe = ">"
Const
xend = "</"

 


Sub test()
    Dim oDoc As
DrawingDocument
    Dim oTbl As
TitleBlock
   
    Set oDoc =
ThisApplication.ActiveDocument
    Set oTbl =
oDoc.Sheets(1).TitleBlock
   
    'Name of
prompted property that you extract the value for

    Dim sPropName As String
    sPropName
= "<replace this with your property name>"
   

    Dim sPropValue As String
    sPropValue
= IvGetPromptedValue(oTbl, sPropName)
   

    MsgBox "Prompted Property" & vbCrLf & vbCrLf
& sPropName & " = " & sPropValue, vbOKOnly
End Sub

 

Public Function IvGetPromptedValue(ByRef oTbl As Inventor.TitleBlock,
_
                                  
sPromptName As String) As String
'get value of specified prompted property
from titleblock and return it
'with Function. If property can't be found
return "-1"
'
'references:
'mXML.ParseXML
   

    Dim oTextBoxes As
Inventor.TextBoxes
    Dim lBox As Long
   

    'get textboxes of titleblock
    Set
oTextBoxes = oTbl.Definition.Sketch.TextBoxes
   

    'iterate through text boxes and find
value
    For lBox = oTextBoxes.Count To 1 Step
-1
        If
Left(GetFormattedText(oTextBoxes(lBox)), 😎 = "<Prompt>"
Then
            Dim
sValue As
String
           
sValue = ParseXML(oTextBoxes(lBox).FormattedText,
"Prompt")
               

            If
UCase(sValue) = UCase(sPromptName)
Then
               
IvGetPromptedValue =
oTbl.GetResultText(oTextBoxes(lBox))
               
Exit
Function
           
End If
        End
If
    Next
   
   
IvGetPromptedValue = "-1"
End Function

 

Private Function GetFormattedText(ByRef oTextBox As Inventor.TextBox) As
String
'get value of formatted text property. If error return error
string
    On Error Resume Next
   

    GetFormattedText =
oTextBox.FormattedText
   
    If Err
Then
       
Err.Clear
        GetFormattedText =
"<Application-defined or object-defined error>"
    End
If
End Function

 

Private Function ParseXML(ByVal XMLSource As String,
_
    ByVal XMLName As String, _
   
Optional Instance As Integer = 1, _
    Optional Default As
Variant = "") As String

 

    Dim x As Integer, y As Integer, XMLStart As Integer,
XMLTag As String, c As String
    Dim XMLTagEnd As
String
    Dim XMLMatch As Integer, XMLEnd As Integer,
XMLLength As Integer
   
    XMLLength =
Len(XMLSource)
    XMLTag = xs + XMLName +
xe
    XMLTagEnd = xend + XMLName + xe
   

    '*** Find the start of the requested
intstance...
    XMLStart = 1
    For x = 1
To Instance
        y = InStr(XMLStart,
XMLSource, XMLTag)
        If y >=
XMLStart
Then
           
XMLStart = y + Len(XMLTag)
       
Else
           
ParseXML =
Default
           
Exit Function
        End
If
    Next
   
    '***
Find the end of the instance...
    XMLEnd =
XMLStart
    XMLMatch = 1
    Do Until
XMLMatch = 0
        c = Mid(XMLSource,
XMLEnd, Len(XMLTagEnd))
        If c =
XMLTagEnd
Then
           
XMLMatch = XMLMatch - 1
        ElseIf
Left(c, 1) = xs
Then
           
XMLMatch = XMLMatch + 1
        End
If
        XMLEnd = XMLEnd +
1
        If XMLEnd = XMLLength
Then
           
ParseXML =
Default
           
Exit Function
        End
If
    Loop
   
   
ParseXML = Mid(XMLSource, XMLStart, XMLEnd - XMLStart - 1)

 

End Function

'end
code========================================================================

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
 

Thanks very much for the help, but as I'm a bit new to VBA
I am very frustrated with myself as I cannot understand
everything in the code.

I'm used to using subs, and am a bit unsure about functions.
I'm not sure what the 'ByRef oTbl As Inventor.titleblock'
is refering to in the arguments for the first function.
And is the 'ParseXML' important, as I can't find any
reference to it in my VBA help. How do the two functions
relate to each other, ie which on do I call.
And Im having trouble calling the functions, I'm not sure
what to put in the argument list.

(I'm worried I put the wrong thing in my original question,
I want to read the values from the titleblock, and just
use them elsewhere. As long as I can get a set of text
strings containing the values in the title block, i'll be
happy)

Thanks for the previous help


Message 6 of 7
joeabberley
in reply to: joeabberley



Thanks for all the help. I have finally managed to get the titleblock info!

I used the suggest code from Lian Xie (thank you!) to get the values I wanted. I suppose it will be useful if I post my successful solution, just in case anyone else is interested:

Public Sub TitleBlock()

Dim oDoc As DrawingDocument

Set oDoc = ThisApplication.ActiveDocument
Dim oTitle As Inventor.TitleBlock
Set oTitle = oDoc.ActiveSheet.TitleBlock

Dim oTextBox As TextBox
Dim oTextBoxes As TextBoxes
Dim sData As String

Set oTextBoxes = oTitle.Definition.Sketch.TextBoxes

For Each oTextBox In oTextBoxes
sData = oTitle.GetResultText(oTextBox)
If oTextBox.text = "COMPANY" Then
Company = sData
ElseIf oTextBox.text = "SALES ORDER No" Then
SalesOrderNo = sData
ElseIf oTextBox.text = "TITLE LINE 1" Then
TitleOne = sData
ElseIf oTextBox.text = "TITLE LINE 2" Then
TitleTwo = sData
ElseIf oTextBox.text = "DRAWING NUMBER" Then
DrgNoOne = sData
ElseIf oTextBox.text = "DRAWING NUMBER 2 " Then
DrgNoTwo = sData
ElseIf oTextBox.text = "DRAWN BY" Then
Author = sData
End If
Next
End Sub

Thats it!

(Note: if anyone who understands this is reading, I can't post this using the via newsgroup, using outlook newsreader. For some reason it wont accept my username and password for the discussion.autodesk.com server. This username and password work fine for the web based version...?)

Again, Thanks All

Joe



Message 7 of 7
Anonymous
in reply to: joeabberley

There was just a similar discussion in the Inventor 6 Newsgroup.

Have you tried just going here
http://discussion.autodesk.com/WebX?14@78.jFQNakmspr3.317952@.ee93814
and clicking on the group under the Newsreader column? If you are able to read but not
post it may be some sort of firewall issue at your company?

--
Kent
Assistant Moderator
Autodesk Discussion Forum Moderator Program


"joeabberley" wrote in message news:f16292c.4@WebX.maYIadrTaRb...

(Note: if anyone who understands this is reading, I can't post this using the via
newsgroup, using outlook newsreader. For some reason it wont accept my username and
password for the discussion.autodesk.com server. This username and password work fine for
the web based version...?) Again, Thanks All Joe
>

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report