Inventor Customization

Inventor Customization

Reply
Valued Contributor
dave.deane
Posts: 78
Registered: ‎04-27-2007
Message 1 of 19 (299 Views)
Accepted Solution

Trying to use "GetPromptTextValues" method

299 Views, 18 Replies
12-31-2012 01:18 PM

I am trying to display the Tags and Values of an inserted AutoCAD block in an Inventor 2013 dwg. I am using .Net studio10.

 

I can list the properties of the block object but cannot get the "GetPromptTextValues" method to work. Problem is at the bottom of the code listed below.

Thanks,

Dave

 

' Connect to a running instance of Inventor.  
        Dim invApp As Inventor.Application

        ' Check to see if a drawing is active
        invApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        If invApp.ActiveDocument.DocumentType <> Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
            MsgBox("Need to have a drawing document active")
            Return
        End If

        ' Create ref to active drawing document
        Dim oDrawingDoc As Inventor.DrawingDocument
        oDrawingDoc = invApp.ActiveDocument

        ' Create ref to AutoCADBlocks collection in the active sheet
        Dim cAcadBlocks As Inventor.AutoCADBlocks
        cAcadBlocks = oDrawingDoc.ActiveSheet.AutoCADBlocks

        ' Get the name of the block
        Dim AcadBlockName As String
        AcadBlockName = cAcadBlocks.Item(1).Name

        Debug.Print(cAcadBlocks.Item(1).Name)

        ' Create ref to the AutoCAD block object in the active sheet
        Dim oAcadBlock As Inventor.AutoCADBlock
        oAcadBlock = cAcadBlocks.Item(AcadBlockName)

        ' check to see if block object code is working (it does)
        Debug.Print(oAcadBlock.Scale)
        Debug.Print(oAcadBlock.LineWeight)
        Debug.Print(oAcadBlock.Name)

        'XXXXXXXXXXXXXXXXXXXX FAILS BELOW XXXXXXXXXXXXXXXXXXXXX
        ' Try and display block tags and values
        Dim sTags(10) As String
        Dim sAttr(10) As String

        oAcadBlock.GetPromptTextValues(sTags, sAttr)


        ' display attribute tag and value 
        For i = 0 To 10
            MsgBox(sTags(i) & " = " & sAttr(i))
        Next

 

Mentor
krieg
Posts: 176
Registered: ‎11-22-2009
Message 2 of 19 (247 Views)

Re: Trying to use "GetPromptTextValues" method

01-06-2013 08:03 AM in reply to: dave.deane

Hello

 

This typically happens when your array has less (or more?) fields than your block attributes. Try

 

' Connect to a running instance of Inventor.  
        Dim invApp As Inventor.Application

        ' Check to see if a drawing is active
        invApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        If invApp.ActiveDocument.DocumentType <> Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
            MsgBox("Need to have a drawing document active")
            Return
        End If

        ' Create ref to active drawing document
        Dim oDrawingDoc As Inventor.DrawingDocument
        oDrawingDoc = invApp.ActiveDocument

        ' Create ref to AutoCADBlocks collection in the active sheet
        Dim cAcadBlocks As Inventor.AutoCADBlocks
        cAcadBlocks = oDrawingDoc.ActiveSheet.AutoCADBlocks

        ' Get the name of the block
        Dim AcadBlockName As String
        AcadBlockName = cAcadBlocks.Item(1).Name

        Debug.Print(cAcadBlocks.Item(1).Name)

        ' Create ref to the AutoCAD block object in the active sheet
        Dim oAcadBlock As Inventor.AutoCADBlock
        oAcadBlock = cAcadBlocks.Item(AcadBlockName)

        ' check to see if block object code is working (it does)
        Debug.Print(oAcadBlock.Scale)
        Debug.Print(oAcadBlock.LineWeight)
        Debug.Print(oAcadBlock.Name)

        'XXXXXXXXXXXXXXXXXXXX FAILS BELOW XXXXXXXXXXXXXXXXXXXXX
        ' Try and display block tags and values
        Dim sTags() As String
        Dim sAttr() As String

        oAcadBlock.GetPromptTextValues(sTags, sAttr)

        Dim iCount as integer
iCount = UBound(sTags)
' display attribute tag and value For i = 0 To sTags-1 MsgBox(sTags(i) & " = " & sAttr(i)) Next

 

 

Valued Contributor
dave.deane
Posts: 78
Registered: ‎04-27-2007
Message 3 of 19 (238 Views)

Re: Trying to use "GetPromptTextValues" method

01-07-2013 06:34 AM in reply to: dave.deane

Please see attached screen shot below

 

When looking at the object browser, it indicates the "GetPromptTextValues" method needs an Object and not a string.

So I used an object but I get an error message in Studio that... "it has been passed by reference befor being assigned a value". I thought thats what the "GetPromptTextValues" method did, pass a value?

 

The debugger says it needs a "NEW" keyword.... ?????

 

At my wits end trying to get this to work

 

Thanks,

Dave

 

 

Mentor
krieg
Posts: 176
Registered: ‎11-22-2009
Message 4 of 19 (232 Views)

Re: Trying to use "GetPromptTextValues" method

01-07-2013 09:04 AM in reply to: dave.deane

Hello

 

Take a second look, you're using GetPromptTextValues not GetPromptTags. :smileywink:

Is there an error message using my suggestion?

Valued Contributor
dave.deane
Posts: 78
Registered: ‎04-27-2007
Message 5 of 19 (226 Views)

Re: Trying to use "GetPromptTextValues" method

01-07-2013 09:29 AM in reply to: krieg

Yes, the screen shot of the object browser was incorrect. Should have been the one in this attached screen shot. I also grabbed the error when using your suggestion.

 

Thanks for trying to help

Mentor
krieg
Posts: 176
Registered: ‎11-22-2009
Message 6 of 19 (218 Views)

Re: Trying to use "GetPromptTextValues" method

01-07-2013 12:12 PM in reply to: dave.deane

Hello

 

sTags and sValues are nothing, that's why the error occurs. You can prevent this, if you check both are not nothing after GetPromptTextValues and before you proceed.

Are you really sure your AutoCadBlock has attributes? Can you upload the Block to check this?

Valued Contributor
dave.deane
Posts: 78
Registered: ‎04-27-2007
Message 7 of 19 (214 Views)

Re: Trying to use "GetPromptTextValues" method

01-07-2013 12:44 PM in reply to: krieg

Hi again,

Yes the block has attributes and they are not empty. I have attached it.

 

I also added a document below with the code. you will need a button1 on a form1 to use it as is. Using studio 10 express here.

 

Mentor
krieg
Posts: 176
Registered: ‎11-22-2009
Message 8 of 19 (206 Views)

Re: Trying to use "GetPromptTextValues" method

01-07-2013 03:11 PM in reply to: dave.deane

Hello

 

Shame on me, there's a stupid error in my code. Please replace "sTags" with "iCount" in line

 

For i = 0 To sTags - 1

 

I tried it out with my code (don't have Studio 10) and it works.

Mentor
krieg
Posts: 176
Registered: ‎11-22-2009
Message 9 of 19 (203 Views)

Re: Trying to use "GetPromptTextValues" method

01-07-2013 03:44 PM in reply to: krieg

Once again

 

Seem's there is a difference between using this code in VBA and VB. If the arrays are defined without fixed size, nothing is result. Forget my last post and try this:

 

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Connect to a running instance of Inventor.  
        Dim invApp As Inventor.Application

        ' Check to see if a drawing is active
        invApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        If invApp.ActiveDocument.DocumentType <> Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
            MsgBox("Need to have a drawing document active")
            Return
        End If

        ' Create ref to active drawing document
        Dim oDrawingDoc As Inventor.DrawingDocument
        oDrawingDoc = invApp.ActiveDocument

        ' Create ref to AutoCADBlocks collection in the active sheet
        Dim cAcadBlocks As Inventor.AutoCADBlocks
        cAcadBlocks = oDrawingDoc.ActiveSheet.AutoCADBlocks

        ' Set the name of the block
        Dim AcadBlockName As String
        AcadBlockName = "BRA"

        ' Create ref to the AutoCAD block object in the active sheet
        Dim oAcadBlock As Inventor.AutoCADBlock
        oAcadBlock = cAcadBlocks.Item(AcadBlockName)

        ' check to see if block object code is working (it does)
        Debug.Print(oAcadBlock.Scale)
        Debug.Print(oAcadBlock.LineWeight)
        Debug.Print(oAcadBlock.Name)
        Debug.Print(oAcadBlock.AttributeSets.Count)


        'XXXXXXXXXXXXXXXXXXXX FAILS BELOW XXXXXXXXXXXXXXXXXXXXX
        ' Try and display block tags and values
        Dim sTags(10) As String
        Dim sAttr(10) As String

        oAcadBlock.GetPromptTextValues(sTags, sAttr)

        Dim i As Integer
        Dim iCount As Integer
        iCount = UBound(sTags)
        Debug.Print("icount = " & iCount)

        ' display attribute tag and value 
        For i = 0 To iCount
            MsgBox(sTags(i) & " = " & sAttr(i))
            i = i + 1
        Next

    End Sub
End Class

 

Valued Contributor
dave.deane
Posts: 78
Registered: ‎04-27-2007
Message 10 of 19 (193 Views)

Re: Trying to use "GetPromptTextValues" method

01-08-2013 08:34 AM in reply to: krieg

Krieg,

I really appreciate your continued assistance. Unfortunately, I am still unable to get to the tags and values. I created a screen recording with audio showing the error using strings and objects. Hope this helps to explain things, turn up the volume and enjoy the show.

 

http://screencast.com/t/9DRBWW4MS

 

Dave

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.