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
Solved! Go to Solution.
Solved by Ralf_Krieg. Go to Solution.
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
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
Hello
Take a second look, you're using GetPromptTextValues not GetPromptTags.
Is there an error message using my suggestion?
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
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?
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.
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.
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
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
Hello
I see the video, but can't believe what I see. I'm using the same code (with removed i=i+1, that's correct in your code), open a new Inventor-dwg, insert block "BRA" from your template file, fill out some attributes, run the code and get attributes and values. Please see attached Screenshots in zipfile.
I'm using Inventor 2013 SP1.1 Update 1.
Sorry, I'm running out of ideas what's going wrong.
I am using Inventor Professional 2013 sp1.1 64 bit xp pro
I also have Inventor 2013 sp1.1 (non professional) on 32 bit xp pro. It doesn't work on either.
In your code did you have sTags dim as strings or objects? Any chance you can upload the .exe to see if your working build works on this end?
A support case has been logged at Autodesk. Hopefully, I will get this sorted out.
Thank you again,
Dave
Hello
sTags and sValues are defined as String. I have counted the attributes and found 23. So:
Dim sTags(23) As String Dim sAttr(23) As String
I attached the exe and if this works on your site, I can send you my project. Maybe there's a difference we both don't registred yet.
Please replace the extension txt with exe.
It doesn't work. I get an array error, screenshot below.
I hope autodesk support can save me on this one. I don't know what else to do.
Hello
Sorry couldn't help you. My best wishes Autodesk can help.
I discussed with our engineer and we did some tests. The following code can work. Not much change than the code Krieg provided in message 9. Could you give it a try?
PrivateSub Button1_Click(sender As System.Object, 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
EndIf
' 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 AsString
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
'correct
Dim sTags() AsString = NewString() {}
Dim sAttr() AsString = NewString() {}
'wrong
'Dim sTags() As String = New Object() {}
'Dim sAttr() As String = New Object() {}
'correct only when the count of texts
' are no more than 23
'Dim sTags(23) As String
'Dim sAttr(23) As String
'wrong
'Dim sTags() As String
'Dim sAttr() As String
oAcadBlock.GetPromptTextValues(sTags, sAttr)
Dim i AsInteger
Dim iCount AsInteger
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
EndSub
Xiaodong,
It will not build as posted. Intellisense does not like AsString, Once I separate the words it then doesn't like the empty squiggly brackets at the end. Please see screen shot below.
Hello
Try it in this way
Dim sTags() As String = New System.String() {}
Winner, Winner! ....... It builds and works! Thank you Krieg and Xiadong.
Is this just part of the learning curve or is there some reading references I need to study? I'm not sure how I would have ever figured this out. I can't find any meaningful syntax explantion searching the web for this. What purpose does the "{}" do? I'm just wondering out loud why a "regular" string array does not work for me but it did for you Krieg?
Onward with the rest of my program development.
Thank you again,
Dave