Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ACAD 2004 and VB.NET 2003 extracting attributes 1

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
Getting error on [red]RED[/red] line.
An unhandled exception of type 'System.InvalidCastException' occurred in CADTime2.exe
Additional information: Specified cast is not valid.

Code:
       Dim A2K As AutoCAD.AcadApplication
        Try
            A2K = GetObject(, "AutoCAD.Application")
        Catch
            A2K = CreateObject("AutoCAD.Application")
        End Try
        Dim A2Kdwg As AutoCAD.AcadDocument = A2K.ActiveDocument
        A2K.Visible = True
        A2Kdwg.Application.Documents.Open(DWGName)
        Dim ss As AutoCAD.AcadSelectionSets
        Dim fType(1) As Integer, fData(1)
        Dim i, j As Integer
        Dim hndl, atts, NumBlocks As Object

        [red]ss = A2K.SelectionSets("ss")[/red]
        fType(0) = 0 : fData(0) = "INSERT" : fType(1) = 2 : fData(1) = "B-AttributeBlock"
        For i = 0 To ss.Count - 1     'This is how many times the Block exists in the drawing.
            hndl = ss.Item(i).Handle
            atts = ss.Item(i).GetAttributes
            For j = LBound(atts) To UBound(atts)  'This is how many TAGS in a block
                '<do whatever here>
                Debug.Write("Tag: " & atts(j).TagString & "   Value: " & atts(j).TextString)
            Next
        Next

Not sure what to put there. I have tried several things.
How do I find out if a particular block exists and then extract the already known atributes?
TIA

DougP, MCP, A+
 
Doug,

I think your problem is how you are dimensioning A2K as AutoCAD.AcadApplication. I'm not real familiar with VB.NET but I think that should be just AcadApplication. The second problem I see is ss = A2K.SelectionSets("ss") should be Set ss = A2K.SelectionSets("ss").

As to how to find if a particular block exists, you're on the right track with fType and fData - you need to re-write your fType and fData filter list and then you just need to implement them:

After setting ss, your filter data should look like this:
(You can ignore my indentation!)

fType(0) = -4: fData(0) = "<and"
fType(1) = 0: fData(1) = "INSERT"
fType(2) = 2: fData(2) = "B-AttributeBlock"
fType(3) = -4: fData(3) = "and>"

then, implement your filter data by using the following line in your code:

ss.Select acSelectionSetAll, , fType, fData

then check your selection set count to test for the presence of your block.

Hope that helps

Todd
 
VB.NET removes the word SET if you type it in
It also added the AutoCAD.AcadApplication
I had this working in VB6 and just wanted to convert it to .NET

Thanks anyway

DougP, MCP, A+
 
Doug,

Did you check to see if "ss" already exists in the AutoCAD selection set collections? You may be bumping into an existing selection set - AutoCAD doesn't like that.

Todd
 
Do you have VB.net and Acad to plug this in and have a look see?
Sorry This is old code I have above
here is the latest version.
----------------
Dim A2K As AutoCAD.AcadApplication
Try
A2K = GetObject(, "AutoCAD.Application")
Catch
A2K = CreateObject("AutoCAD.Application")
End Try
Dim A2Kdwg As AutoCAD.AcadDocument = A2K.ActiveDocument
A2K.Visible = True
Dim ss As AutoCAD.AcadSelectionSet
Dim fType(1) As Integer, fData(1) As Object
Dim i, j As Integer
Dim hndl, atts, NumBlocks As Object
Try
ss = A2Kdwg.SelectionSet("ss")
Catch
'ss.Clear()
ss = A2Kdwg.SelectionSets.Add("SS")
End Try
ss.Clear()
fType(0) = 0
fType(1) = 2
fData(0) = "INSERT"
fData(1) = "B-AttributeBlock"
[red]ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)[/red]

For i = 0 To ss.Count - 1 'This is how many times the Block exists in the drawing.
hndl = ss.Item(i).Handle
atts = ss.Item(i).GetAttributes
For j = LBound(atts) To UBound(atts) 'This is how many TAGS in a block
'<do whatever here>
Debug.Write("Tag: " & atts(j).TagString & " Value: " & atts(j).TextString)
Next
Next
-------------------------

Error is now on [red]RED[/red] line.

"Type Cast" Error. It needs to be converted to something or the DIM statement is not correct I guess.


DougP, MCP, A+
 
I just want to Find a block called "B-AttributeBlock" and get the attribute called "JobNum" out of it. So I have the job number of that drawing.

If there is an easier way?

DougP, MCP, A+
 
Doug,

You are correct - you need to dimension fData as a Variant not an Object - in your filter data, when you are searching for a particular block, you will supply a string, not an object. Also you still need to include an '<and' in your filter list.

Re-write your filter data:

fType(0) = -4: fData(0) = "<and"
fType(1) = 0: fData(1) = "INSERT"
fType(2) = 2: fData(2) = "B-AttributeBlock"
fType(3) = -4: fData(3) = "and>"

or:

fType(0) = 2: fData(0) = "B-AttributeBlock"
 
I don't think Variant is a type in VB.ET 2003
When I type it in, it chages back to Object
I can type String though or Double

Did not work anyway
Error =
An unhandled exception of type 'System.ArgumentException' occurred in CADTime2.exe
Additional information: Invalid argument FilterType in Select.

Same RED line as above.



DougP, MCP, A+
 
Doug,

Did you change your filter list as above?

What version/service pack of AutoCAD are you on?

It appears you are getting a different error message this time, is this true.
 
Doug,

Found this little tidbit:

Use short[] for the group codes and object[] for the values.

Hope this helps

Todd
 
ACAD 2004
no service pak

I added some code to the code originally posted at the top That error is different but I'm past that stage now.

I don't understand WYMB "Short" or "object"



DougP, MCP, A+
 
Doug,

I'm afraid I don't have vb.net and don't understand the Short[] or Object[] data types either. Frank Oquendo wrote this in one of Autodesk's forums. His website is, or used to be; - which I haven't been able to access for a couple of days now - don't know if it's on our side or his but he discusses vb.net with AutoCAD.

In case you weren't aware, service pack 1a is available for AutoCAD, you can find it here:


HTH

Todd
 
Ok
Great
Autodesks WEB site is down too

DougP, MCP, A+
 
Here ya go. Notice the dimming of the fType & fData:

Dim A2K As AutoCAD.AcadApplication
Try
A2K = GetObject(, "AutoCAD.Application")
Catch
A2K = CreateObject("AutoCAD.Application")
End Try
Dim A2Kdwg As AutoCAD.AcadDocument = A2K.ActiveDocument
A2K.Visible = True
Dim ss As AutoCAD.AcadSelectionSet
Dim fType(1) As Short, fData(1) As Object
Dim i, j As Integer
Dim hndl, atts, NumBlocks As Object
Try
ss = A2Kdwg.SelectionSets.Add("ss")
Catch
'ss.Clear()
A2Kdwg.SelectionSets.Item("ss").Delete()
ss = A2Kdwg.SelectionSets.Add("ss")
End Try
ss.Clear()
fType(0) = 0
fType(1) = 2
fData(0) = "INSERT"
fData(1) = "B-AttributeBlock"
ss.Select(AutoCAD.AcSelect.acSelectionSetAll, , , fType, fData)

For i = 0 To ss.Count - 1 'This is how many times the Block exists in the drawing.
hndl = ss.Item(i).Handle
atts = ss.Item(i).GetAttributes
For j = LBound(atts) To UBound(atts) 'This is how many TAGS in a block
'<do whatever here>
Debug.Write("Tag: " & atts(j).TagString & " Value: " & atts(j).TextString)
Next
Next
 
Oh Yeah Baby !!!!!!!!!!!!
How 'bout a STAR !!!!!!!!!

[wavey2]

DougP, MCP, A+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top