.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Attributes & Selection Sets with differnt OS

1 REPLY 1
Reply
Message 1 of 2
Anonymous
309 Views, 1 Reply

Attributes & Selection Sets with differnt OS

I am having a problem with Attributes and Selection Sets running on differnt
Operating systems. All XP Machines the below code will work but all 2000
machines will error out on:
atts = ss.Item(i).GetAttributes

The error I receive is:
System.Runtime.InteropServices.COMException (0x80020008): Bad variable type.
(Exception from HRESULT: 0x80020008 (DISP_E_BADVARTYPE))

Any Ideas how I can run the code on both Operating Systems.

Dim fType(2) As Short, fData(2) As Object, atts As Object
Dim ss As Autodesk.AutoCAD.Interop.AcadSelectionSet

Try
ss = ThisDrawing.SelectionSets.Add("ss")
Catch ex As Exception
ss = ThisDrawing.SelectionSets.Add("ss2")
End Try
ss.Clear()
fType(0) = 0 : fData(0) = "INSERT"
fType(1) = 2 : fData(1) = "Sheet Text 30x42"
fType(2) = 8 : fData(2) = "A-Tblk-Text"
ss.Select(Autodesk.AutoCAD.Interop.Common.AcSelect.acSelectionSetAll, , ,
fType, fData)
For i = 0 To ss.Count - 1
atts = ss.Item(i).GetAttributes 'errors out here on Windows 2000
machines
'Do stuff with atts
Next i
1 REPLY 1
Message 2 of 2
cgay
in reply to: Anonymous

Nate,

Try this:

[code]
Dim ss As Autodesk.AutoCAD.Interop.AcadSelectionSet = Nothing

Try
ss = ThisDrawing.SelectionSets.Add("ss")
Catch ex As Exception
ss = ThisDrawing.SelectionSets.Item("ss")
ss.Clear()
End Try
If Not ss Is Nothing Then
Dim fType(2) As Short, fData(2) As Object
fType(0) = 0 : fData(0) = "INSERT"
fType(1) = 2 : fData(1) = "Sheet Text 30x42"
fType(2) = 8 : fData(2) = "A-Tblk-Text"
ss.Select(Autodesk.AutoCAD.Interop.Common.AcSelect.acSelectionSetAll, , , fType, fData)

For Each aEnt As Autodesk.AutoCAD.Interop.Common.AcadEntity In ss
Dim atts As Object = Nothing
Select Case True
Case TypeOf aEnt Is Autodesk.AutoCAD.Interop.Common.AcadBlockReference
Dim acdBlock As Autodesk.AutoCAD.Interop.Common.AcadBlockReference = _
DirectCast(aEnt, Autodesk.AutoCAD.Interop.Common.AcadBlockReference)
atts = acdBlock.GetAttributes
Case TypeOf aEnt Is Autodesk.AutoCAD.Interop.Common.AcadExternalReference
Dim acdExtRef As Autodesk.AutoCAD.Interop.Common.AcadExternalReference = _
DirectCast(aEnt, Autodesk.AutoCAD.Interop.Common.AcadExternalReference)
atts = acdExtRef.GetAttributes
Case TypeOf aEnt Is Autodesk.AutoCAD.Interop.Common.AcadMInsertBlock
Dim acdMBlock As Autodesk.AutoCAD.Interop.Common.AcadMInsertBlock = _
DirectCast(aEnt, Autodesk.AutoCAD.Interop.Common.AcadMInsertBlock)
atts = acdMBlock.GetAttributes
Case Else
Debug.Assert(False, "Unhandled Type in selection set, " & TypeName(aEnt))
End Select
If Not atts Is Nothing Then
'Do stuff with atts
End If
Next
Else
MsgBox("Unable to obtain selection set", _
MsgBoxStyle.ApplicationModal Or _
MsgBoxStyle.Exclamation Or _
MsgBoxStyle.OkOnly, "Selection Set Error")
End If
[/code]

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost