getting drawing object from outside AutoCAD

getting drawing object from outside AutoCAD

Anonymous
Not applicable
541 Views
13 Replies
Message 1 of 14

getting drawing object from outside AutoCAD

Anonymous
Not applicable
Hi All,

I am working from outside AutoCAD and developing my application as a separate VB6 application.
I am trying to open autoCAD andthen get the object of the drawing I have open,but somehow my code fails to do so. Please help. Here is my code.

Private Sub Command1_Click()
Dim aDoc As Object
Set aDoc = acadApp.ActiveDocument
Dim blkref As AcadBlockReference 'AcadBlockReference
'Set blkref = acadDoc.Blocks
Dim CurAtts As Variant
Dim bspnt As Variant
aDoc.Utility.GetEntity blkref, bspnt, "Select Block To ShowAttributes: "
CurAtts = blkref.GetAttributes

Getblock = True
End Sub



Private Sub Form_Load()
Dim acadApp As Object
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True


End Sub

Also once I get the object ,I need to get the block on which the user clicks.
Can someone please help me correcting my code .Any suggestion or code is appreciated.

Thanks in advance.
Avantika
0 Likes
542 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable
Here is something I threw together that may help you get going.

Joe ...

Option Explicit

Dim oApp As AcadApplication
Dim ThisDrawing As AcadDocument

Private Sub Command1_Click()
Dim oBlockRef As AcadBlockReference
If GetBlock(oBlockRef) Then
MsgBox "User selected a block with attributes"

Else
MsgBox "User selected a block without attributes"
End If
Unload Me
End Sub

Private Sub Form_Load()
On Error Resume Next
'attempt to get last version of AutoCAD opened
Set oApp = GetObject(, "AutoCAD.Application")

If Err Then
Err.Clear
'attempt to create instantiation of last version of AutoCAD opened
Set oApp = CreateObject("AutoCAD.Application")
'no AutoCAD is available
If Err Then
MsgBox "Cannot start AutoCAD ... sorry!", vbExclamation, "Error
starting AutoCAD"
Unload Me
End If
End If

oApp.Visible = True

Set ThisDrawing = oApp.ActiveDocument
End Sub

Private Function GetBlock(BlockRef As AcadBlockReference) As Boolean
Dim CurAtts As Variant
Dim oSS As AcadSelectionSet
Dim iFilterCode(0) As Integer
Dim vFilterValue(0) As Variant

iFilterCode(0) = 0
vFilterValue(0) = "INSERT"

On Error Resume Next
ThisDrawing.SelectionSets("INSERTS").Delete
Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")

oSS.SelectOnScreen iFilterCode, vFilterValue
On Error GoTo 0

If oSS(0).HasAttributes Then
'return the block to retrieve attributes
Set BlockRef = oSS(0)

GetBlock = True
End If
End Function

wrote in message news:5227195@discussion.autodesk.com...
Hi All,

I am working from outside AutoCAD and developing my application as a
separate VB6 application.
I am trying to open autoCAD andthen get the object of the drawing I have
open,but somehow my code fails to do so. Please help. Here is my code.

Private Sub Command1_Click()
Dim aDoc As Object
Set aDoc = acadApp.ActiveDocument
Dim blkref As AcadBlockReference 'AcadBlockReference
'Set blkref = acadDoc.Blocks
Dim CurAtts As Variant
Dim bspnt As Variant
aDoc.Utility.GetEntity blkref, bspnt, "Select Block To ShowAttributes: "
CurAtts = blkref.GetAttributes

Getblock = True
End Sub



Private Sub Form_Load()
Dim acadApp As Object
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True


End Sub

Also once I get the object ,I need to get the block on which the user
clicks.
Can someone please help me correcting my code .Any suggestion or code is
appreciated.

Thanks in advance.
Avantika
0 Likes
Message 3 of 14

Anonymous
Not applicable
>On Error Resume Next
>ThisDrawing.SelectionSets("INSERTS").Delete
>Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")


If your going to use 'On Error Resume Next' here, I would check
for the error after trying to Delete your SS and clear it before
continuing. Or is it not necessary?

"Joe Sutphin" wrote in message
news:5227551@discussion.autodesk.com...
Here is something I threw together that may help you get going.

Joe ...

Option Explicit

Dim oApp As AcadApplication
Dim ThisDrawing As AcadDocument

Private Sub Command1_Click()
Dim oBlockRef As AcadBlockReference
If GetBlock(oBlockRef) Then
MsgBox "User selected a block with attributes"

Else
MsgBox "User selected a block without attributes"
End If
Unload Me
End Sub

Private Sub Form_Load()
On Error Resume Next
'attempt to get last version of AutoCAD opened
Set oApp = GetObject(, "AutoCAD.Application")

If Err Then
Err.Clear
'attempt to create instantiation of last version of AutoCAD opened
Set oApp = CreateObject("AutoCAD.Application")
'no AutoCAD is available
If Err Then
MsgBox "Cannot start AutoCAD ... sorry!", vbExclamation, "Error
starting AutoCAD"
Unload Me
End If
End If

oApp.Visible = True

Set ThisDrawing = oApp.ActiveDocument
End Sub

Private Function GetBlock(BlockRef As AcadBlockReference) As Boolean
Dim CurAtts As Variant
Dim oSS As AcadSelectionSet
Dim iFilterCode(0) As Integer
Dim vFilterValue(0) As Variant

iFilterCode(0) = 0
vFilterValue(0) = "INSERT"

On Error Resume Next
ThisDrawing.SelectionSets("INSERTS").Delete
Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")

oSS.SelectOnScreen iFilterCode, vFilterValue
On Error GoTo 0

If oSS(0).HasAttributes Then
'return the block to retrieve attributes
Set BlockRef = oSS(0)

GetBlock = True
End If
End Function

wrote in message news:5227195@discussion.autodesk.com...
Hi All,

I am working from outside AutoCAD and developing my application as a
separate VB6 application.
I am trying to open autoCAD andthen get the object of the drawing I have
open,but somehow my code fails to do so. Please help. Here is my code.

Private Sub Command1_Click()
Dim aDoc As Object
Set aDoc = acadApp.ActiveDocument
Dim blkref As AcadBlockReference 'AcadBlockReference
'Set blkref = acadDoc.Blocks
Dim CurAtts As Variant
Dim bspnt As Variant
aDoc.Utility.GetEntity blkref, bspnt, "Select Block To ShowAttributes: "
CurAtts = blkref.GetAttributes

Getblock = True
End Sub



Private Sub Form_Load()
Dim acadApp As Object
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True


End Sub

Also once I get the object ,I need to get the block on which the user
clicks.
Can someone please help me correcting my code .Any suggestion or code is
appreciated.

Thanks in advance.
Avantika
0 Likes
Message 4 of 14

Anonymous
Not applicable
btw...I'm not being critical, just inquisitive..I've posted code the
same way I'm sure...:)

"Paul Richardson" wrote in message
news:5227756@discussion.autodesk.com...
>On Error Resume Next
>ThisDrawing.SelectionSets("INSERTS").Delete
>Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")


If your going to use 'On Error Resume Next' here, I would check
for the error after trying to Delete your SS and clear it before
continuing. Or is it not necessary?

"Joe Sutphin" wrote in message
news:5227551@discussion.autodesk.com...
Here is something I threw together that may help you get going.

Joe ...

Option Explicit

Dim oApp As AcadApplication
Dim ThisDrawing As AcadDocument

Private Sub Command1_Click()
Dim oBlockRef As AcadBlockReference
If GetBlock(oBlockRef) Then
MsgBox "User selected a block with attributes"

Else
MsgBox "User selected a block without attributes"
End If
Unload Me
End Sub

Private Sub Form_Load()
On Error Resume Next
'attempt to get last version of AutoCAD opened
Set oApp = GetObject(, "AutoCAD.Application")

If Err Then
Err.Clear
'attempt to create instantiation of last version of AutoCAD opened
Set oApp = CreateObject("AutoCAD.Application")
'no AutoCAD is available
If Err Then
MsgBox "Cannot start AutoCAD ... sorry!", vbExclamation, "Error
starting AutoCAD"
Unload Me
End If
End If

oApp.Visible = True

Set ThisDrawing = oApp.ActiveDocument
End Sub

Private Function GetBlock(BlockRef As AcadBlockReference) As Boolean
Dim CurAtts As Variant
Dim oSS As AcadSelectionSet
Dim iFilterCode(0) As Integer
Dim vFilterValue(0) As Variant

iFilterCode(0) = 0
vFilterValue(0) = "INSERT"

On Error Resume Next
ThisDrawing.SelectionSets("INSERTS").Delete
Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")

oSS.SelectOnScreen iFilterCode, vFilterValue
On Error GoTo 0

If oSS(0).HasAttributes Then
'return the block to retrieve attributes
Set BlockRef = oSS(0)

GetBlock = True
End If
End Function

wrote in message news:5227195@discussion.autodesk.com...
Hi All,

I am working from outside AutoCAD and developing my application as a
separate VB6 application.
I am trying to open autoCAD andthen get the object of the drawing I have
open,but somehow my code fails to do so. Please help. Here is my code.

Private Sub Command1_Click()
Dim aDoc As Object
Set aDoc = acadApp.ActiveDocument
Dim blkref As AcadBlockReference 'AcadBlockReference
'Set blkref = acadDoc.Blocks
Dim CurAtts As Variant
Dim bspnt As Variant
aDoc.Utility.GetEntity blkref, bspnt, "Select Block To ShowAttributes: "
CurAtts = blkref.GetAttributes

Getblock = True
End Sub



Private Sub Form_Load()
Dim acadApp As Object
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True


End Sub

Also once I get the object ,I need to get the block on which the user
clicks.
Can someone please help me correcting my code .Any suggestion or code is
appreciated.

Thanks in advance.
Avantika
0 Likes
Message 5 of 14

Anonymous
Not applicable
Since I want to delete the selection set regardless and I know that if it
does not exist it's going to raise an error [which in this particular
instance I don't care about] I prefer to just ignore the error as opposed to
trapping it. Unlike for instance, say, when you're attempting to either get
a running instance or create a running instance of AutoCAD. Bottom line, I
think it is somewhat preferential and somewhat contextual.

Joe ...


"Paul Richardson" wrote in message
news:5227756@discussion.autodesk.com...
>On Error Resume Next
>ThisDrawing.SelectionSets("INSERTS").Delete
>Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")


If your going to use 'On Error Resume Next' here, I would check
for the error after trying to Delete your SS and clear it before
continuing. Or is it not necessary?

"Joe Sutphin" wrote in message
news:5227551@discussion.autodesk.com...
Here is something I threw together that may help you get going.

Joe ...

Option Explicit

Dim oApp As AcadApplication
Dim ThisDrawing As AcadDocument

Private Sub Command1_Click()
Dim oBlockRef As AcadBlockReference
If GetBlock(oBlockRef) Then
MsgBox "User selected a block with attributes"

Else
MsgBox "User selected a block without attributes"
End If
Unload Me
End Sub

Private Sub Form_Load()
On Error Resume Next
'attempt to get last version of AutoCAD opened
Set oApp = GetObject(, "AutoCAD.Application")

If Err Then
Err.Clear
'attempt to create instantiation of last version of AutoCAD opened
Set oApp = CreateObject("AutoCAD.Application")
'no AutoCAD is available
If Err Then
MsgBox "Cannot start AutoCAD ... sorry!", vbExclamation, "Error
starting AutoCAD"
Unload Me
End If
End If

oApp.Visible = True

Set ThisDrawing = oApp.ActiveDocument
End Sub

Private Function GetBlock(BlockRef As AcadBlockReference) As Boolean
Dim CurAtts As Variant
Dim oSS As AcadSelectionSet
Dim iFilterCode(0) As Integer
Dim vFilterValue(0) As Variant

iFilterCode(0) = 0
vFilterValue(0) = "INSERT"

On Error Resume Next
ThisDrawing.SelectionSets("INSERTS").Delete
Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")

oSS.SelectOnScreen iFilterCode, vFilterValue
On Error GoTo 0

If oSS(0).HasAttributes Then
'return the block to retrieve attributes
Set BlockRef = oSS(0)

GetBlock = True
End If
End Function

wrote in message news:5227195@discussion.autodesk.com...
Hi All,

I am working from outside AutoCAD and developing my application as a
separate VB6 application.
I am trying to open autoCAD andthen get the object of the drawing I have
open,but somehow my code fails to do so. Please help. Here is my code.

Private Sub Command1_Click()
Dim aDoc As Object
Set aDoc = acadApp.ActiveDocument
Dim blkref As AcadBlockReference 'AcadBlockReference
'Set blkref = acadDoc.Blocks
Dim CurAtts As Variant
Dim bspnt As Variant
aDoc.Utility.GetEntity blkref, bspnt, "Select Block To ShowAttributes: "
CurAtts = blkref.GetAttributes

Getblock = True
End Sub



Private Sub Form_Load()
Dim acadApp As Object
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True


End Sub

Also once I get the object ,I need to get the block on which the user
clicks.
Can someone please help me correcting my code .Any suggestion or code is
appreciated.

Thanks in advance.
Avantika
0 Likes
Message 6 of 14

Anonymous
Not applicable
The on error statement gets abused.

I would say it's best not to use it when it's possible
to use cleaner code :

Dim myset as AcadSelectionSet

For each myset in ThisDrawing.SelectionSets
if myset.name = "INSERTS" then
myset.delete
exit for
end if
next myset

set myset = thisdrawing.selectionsets.add("INSERTS")


--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica


"Paul Richardson" wrote in message
news:5227756@discussion.autodesk.com...
>On Error Resume Next
>ThisDrawing.SelectionSets("INSERTS").Delete
>Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")


If your going to use 'On Error Resume Next' here, I would check
for the error after trying to Delete your SS and clear it before
continuing. Or is it not necessary?

"Joe Sutphin" wrote in message
news:5227551@discussion.autodesk.com...
Here is something I threw together that may help you get going.

Joe ...

Option Explicit

Dim oApp As AcadApplication
Dim ThisDrawing As AcadDocument

Private Sub Command1_Click()
Dim oBlockRef As AcadBlockReference
If GetBlock(oBlockRef) Then
MsgBox "User selected a block with attributes"

Else
MsgBox "User selected a block without attributes"
End If
Unload Me
End Sub

Private Sub Form_Load()
On Error Resume Next
'attempt to get last version of AutoCAD opened
Set oApp = GetObject(, "AutoCAD.Application")

If Err Then
Err.Clear
'attempt to create instantiation of last version of AutoCAD opened
Set oApp = CreateObject("AutoCAD.Application")
'no AutoCAD is available
If Err Then
MsgBox "Cannot start AutoCAD ... sorry!", vbExclamation, "Error
starting AutoCAD"
Unload Me
End If
End If

oApp.Visible = True

Set ThisDrawing = oApp.ActiveDocument
End Sub

Private Function GetBlock(BlockRef As AcadBlockReference) As Boolean
Dim CurAtts As Variant
Dim oSS As AcadSelectionSet
Dim iFilterCode(0) As Integer
Dim vFilterValue(0) As Variant

iFilterCode(0) = 0
vFilterValue(0) = "INSERT"

On Error Resume Next
ThisDrawing.SelectionSets("INSERTS").Delete
Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")

oSS.SelectOnScreen iFilterCode, vFilterValue
On Error GoTo 0

If oSS(0).HasAttributes Then
'return the block to retrieve attributes
Set BlockRef = oSS(0)

GetBlock = True
End If
End Function

wrote in message news:5227195@discussion.autodesk.com...
Hi All,

I am working from outside AutoCAD and developing my application as a
separate VB6 application.
I am trying to open autoCAD andthen get the object of the drawing I have
open,but somehow my code fails to do so. Please help. Here is my code.

Private Sub Command1_Click()
Dim aDoc As Object
Set aDoc = acadApp.ActiveDocument
Dim blkref As AcadBlockReference 'AcadBlockReference
'Set blkref = acadDoc.Blocks
Dim CurAtts As Variant
Dim bspnt As Variant
aDoc.Utility.GetEntity blkref, bspnt, "Select Block To ShowAttributes: "
CurAtts = blkref.GetAttributes

Getblock = True
End Sub



Private Sub Form_Load()
Dim acadApp As Object
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True


End Sub

Also once I get the object ,I need to get the block on which the user
clicks.
Can someone please help me correcting my code .Any suggestion or code is
appreciated.

Thanks in advance.
Avantika
0 Likes
Message 7 of 14

Anonymous
Not applicable
Paul is making a good point here.

You should clear the error after the delete
because you could be ignoring a possible error
generated by the add method.

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica

"Joe Sutphin" wrote in message
news:5227773@discussion.autodesk.com...
Since I want to delete the selection set regardless and I know that if it
does not exist it's going to raise an error [which in this particular
instance I don't care about] I prefer to just ignore the error as opposed to
trapping it. Unlike for instance, say, when you're attempting to either get
a running instance or create a running instance of AutoCAD. Bottom line, I
think it is somewhat preferential and somewhat contextual.

Joe ...


"Paul Richardson" wrote in message
news:5227756@discussion.autodesk.com...
>On Error Resume Next
>ThisDrawing.SelectionSets("INSERTS").Delete
>Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")


If your going to use 'On Error Resume Next' here, I would check
for the error after trying to Delete your SS and clear it before
continuing. Or is it not necessary?

"Joe Sutphin" wrote in message
news:5227551@discussion.autodesk.com...
Here is something I threw together that may help you get going.

Joe ...

Option Explicit

Dim oApp As AcadApplication
Dim ThisDrawing As AcadDocument

Private Sub Command1_Click()
Dim oBlockRef As AcadBlockReference
If GetBlock(oBlockRef) Then
MsgBox "User selected a block with attributes"

Else
MsgBox "User selected a block without attributes"
End If
Unload Me
End Sub

Private Sub Form_Load()
On Error Resume Next
'attempt to get last version of AutoCAD opened
Set oApp = GetObject(, "AutoCAD.Application")

If Err Then
Err.Clear
'attempt to create instantiation of last version of AutoCAD opened
Set oApp = CreateObject("AutoCAD.Application")
'no AutoCAD is available
If Err Then
MsgBox "Cannot start AutoCAD ... sorry!", vbExclamation, "Error
starting AutoCAD"
Unload Me
End If
End If

oApp.Visible = True

Set ThisDrawing = oApp.ActiveDocument
End Sub

Private Function GetBlock(BlockRef As AcadBlockReference) As Boolean
Dim CurAtts As Variant
Dim oSS As AcadSelectionSet
Dim iFilterCode(0) As Integer
Dim vFilterValue(0) As Variant

iFilterCode(0) = 0
vFilterValue(0) = "INSERT"

On Error Resume Next
ThisDrawing.SelectionSets("INSERTS").Delete
Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")

oSS.SelectOnScreen iFilterCode, vFilterValue
On Error GoTo 0

If oSS(0).HasAttributes Then
'return the block to retrieve attributes
Set BlockRef = oSS(0)

GetBlock = True
End If
End Function

wrote in message news:5227195@discussion.autodesk.com...
Hi All,

I am working from outside AutoCAD and developing my application as a
separate VB6 application.
I am trying to open autoCAD andthen get the object of the drawing I have
open,but somehow my code fails to do so. Please help. Here is my code.

Private Sub Command1_Click()
Dim aDoc As Object
Set aDoc = acadApp.ActiveDocument
Dim blkref As AcadBlockReference 'AcadBlockReference
'Set blkref = acadDoc.Blocks
Dim CurAtts As Variant
Dim bspnt As Variant
aDoc.Utility.GetEntity blkref, bspnt, "Select Block To ShowAttributes: "
CurAtts = blkref.GetAttributes

Getblock = True
End Sub



Private Sub Form_Load()
Dim acadApp As Object
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True


End Sub

Also once I get the object ,I need to get the block on which the user
clicks.
Can someone please help me correcting my code .Any suggestion or code is
appreciated.

Thanks in advance.
Avantika
0 Likes
Message 8 of 14

Anonymous
Not applicable
Jorge, I going to print this out and give it to my
Mom to hang on her frig...:)
"Jorge Jimenez" wrote in message
news:5228010@discussion.autodesk.com...
Paul is making a good point here.

You should clear the error after the delete
because you could be ignoring a possible error
generated by the add method.

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica

"Joe Sutphin" wrote in message
news:5227773@discussion.autodesk.com...
Since I want to delete the selection set regardless and I know that if it
does not exist it's going to raise an error [which in this particular
instance I don't care about] I prefer to just ignore the error as opposed to
trapping it. Unlike for instance, say, when you're attempting to either get
a running instance or create a running instance of AutoCAD. Bottom line, I
think it is somewhat preferential and somewhat contextual.

Joe ...


"Paul Richardson" wrote in message
news:5227756@discussion.autodesk.com...
>On Error Resume Next
>ThisDrawing.SelectionSets("INSERTS").Delete
>Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")


If your going to use 'On Error Resume Next' here, I would check
for the error after trying to Delete your SS and clear it before
continuing. Or is it not necessary?

"Joe Sutphin" wrote in message
news:5227551@discussion.autodesk.com...
Here is something I threw together that may help you get going.

Joe ...

Option Explicit

Dim oApp As AcadApplication
Dim ThisDrawing As AcadDocument

Private Sub Command1_Click()
Dim oBlockRef As AcadBlockReference
If GetBlock(oBlockRef) Then
MsgBox "User selected a block with attributes"

Else
MsgBox "User selected a block without attributes"
End If
Unload Me
End Sub

Private Sub Form_Load()
On Error Resume Next
'attempt to get last version of AutoCAD opened
Set oApp = GetObject(, "AutoCAD.Application")

If Err Then
Err.Clear
'attempt to create instantiation of last version of AutoCAD opened
Set oApp = CreateObject("AutoCAD.Application")
'no AutoCAD is available
If Err Then
MsgBox "Cannot start AutoCAD ... sorry!", vbExclamation, "Error
starting AutoCAD"
Unload Me
End If
End If

oApp.Visible = True

Set ThisDrawing = oApp.ActiveDocument
End Sub

Private Function GetBlock(BlockRef As AcadBlockReference) As Boolean
Dim CurAtts As Variant
Dim oSS As AcadSelectionSet
Dim iFilterCode(0) As Integer
Dim vFilterValue(0) As Variant

iFilterCode(0) = 0
vFilterValue(0) = "INSERT"

On Error Resume Next
ThisDrawing.SelectionSets("INSERTS").Delete
Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")

oSS.SelectOnScreen iFilterCode, vFilterValue
On Error GoTo 0

If oSS(0).HasAttributes Then
'return the block to retrieve attributes
Set BlockRef = oSS(0)

GetBlock = True
End If
End Function

wrote in message news:5227195@discussion.autodesk.com...
Hi All,

I am working from outside AutoCAD and developing my application as a
separate VB6 application.
I am trying to open autoCAD andthen get the object of the drawing I have
open,but somehow my code fails to do so. Please help. Here is my code.

Private Sub Command1_Click()
Dim aDoc As Object
Set aDoc = acadApp.ActiveDocument
Dim blkref As AcadBlockReference 'AcadBlockReference
'Set blkref = acadDoc.Blocks
Dim CurAtts As Variant
Dim bspnt As Variant
aDoc.Utility.GetEntity blkref, bspnt, "Select Block To ShowAttributes: "
CurAtts = blkref.GetAttributes

Getblock = True
End Sub



Private Sub Form_Load()
Dim acadApp As Object
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True


End Sub

Also once I get the object ,I need to get the block on which the user
clicks.
Can someone please help me correcting my code .Any suggestion or code is
appreciated.

Thanks in advance.
Avantika
0 Likes
Message 9 of 14

Anonymous
Not applicable
Send me the print out
and I'll autograph it, for your Mama.

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica


"Paul Richardson" wrote in message
news:5228062@discussion.autodesk.com...
Jorge, I going to print this out and give it to my
Mom to hang on her frig...:)
"Jorge Jimenez" wrote in message
news:5228010@discussion.autodesk.com...
Paul is making a good point here.

You should clear the error after the delete
because you could be ignoring a possible error
generated by the add method.

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica

"Joe Sutphin" wrote in message
news:5227773@discussion.autodesk.com...
Since I want to delete the selection set regardless and I know that if it
does not exist it's going to raise an error [which in this particular
instance I don't care about] I prefer to just ignore the error as opposed to
trapping it. Unlike for instance, say, when you're attempting to either get
a running instance or create a running instance of AutoCAD. Bottom line, I
think it is somewhat preferential and somewhat contextual.

Joe ...


"Paul Richardson" wrote in message
news:5227756@discussion.autodesk.com...
>On Error Resume Next
>ThisDrawing.SelectionSets("INSERTS").Delete
>Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")


If your going to use 'On Error Resume Next' here, I would check
for the error after trying to Delete your SS and clear it before
continuing. Or is it not necessary?

"Joe Sutphin" wrote in message
news:5227551@discussion.autodesk.com...
Here is something I threw together that may help you get going.

Joe ...

Option Explicit

Dim oApp As AcadApplication
Dim ThisDrawing As AcadDocument

Private Sub Command1_Click()
Dim oBlockRef As AcadBlockReference
If GetBlock(oBlockRef) Then
MsgBox "User selected a block with attributes"

Else
MsgBox "User selected a block without attributes"
End If
Unload Me
End Sub

Private Sub Form_Load()
On Error Resume Next
'attempt to get last version of AutoCAD opened
Set oApp = GetObject(, "AutoCAD.Application")

If Err Then
Err.Clear
'attempt to create instantiation of last version of AutoCAD opened
Set oApp = CreateObject("AutoCAD.Application")
'no AutoCAD is available
If Err Then
MsgBox "Cannot start AutoCAD ... sorry!", vbExclamation, "Error
starting AutoCAD"
Unload Me
End If
End If

oApp.Visible = True

Set ThisDrawing = oApp.ActiveDocument
End Sub

Private Function GetBlock(BlockRef As AcadBlockReference) As Boolean
Dim CurAtts As Variant
Dim oSS As AcadSelectionSet
Dim iFilterCode(0) As Integer
Dim vFilterValue(0) As Variant

iFilterCode(0) = 0
vFilterValue(0) = "INSERT"

On Error Resume Next
ThisDrawing.SelectionSets("INSERTS").Delete
Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")

oSS.SelectOnScreen iFilterCode, vFilterValue
On Error GoTo 0

If oSS(0).HasAttributes Then
'return the block to retrieve attributes
Set BlockRef = oSS(0)

GetBlock = True
End If
End Function

wrote in message news:5227195@discussion.autodesk.com...
Hi All,

I am working from outside AutoCAD and developing my application as a
separate VB6 application.
I am trying to open autoCAD andthen get the object of the drawing I have
open,but somehow my code fails to do so. Please help. Here is my code.

Private Sub Command1_Click()
Dim aDoc As Object
Set aDoc = acadApp.ActiveDocument
Dim blkref As AcadBlockReference 'AcadBlockReference
'Set blkref = acadDoc.Blocks
Dim CurAtts As Variant
Dim bspnt As Variant
aDoc.Utility.GetEntity blkref, bspnt, "Select Block To ShowAttributes: "
CurAtts = blkref.GetAttributes

Getblock = True
End Sub



Private Sub Form_Load()
Dim acadApp As Object
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True


End Sub

Also once I get the object ,I need to get the block on which the user
clicks.
Can someone please help me correcting my code .Any suggestion or code is
appreciated.

Thanks in advance.
Avantika
0 Likes
Message 10 of 14

Anonymous
Not applicable
still laughing as I type...:o)
"Jorge Jimenez" wrote in message
news:5228129@discussion.autodesk.com...
Send me the print out
and I'll autograph it, for your Mama.

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica


"Paul Richardson" wrote in message
news:5228062@discussion.autodesk.com...
Jorge, I going to print this out and give it to my
Mom to hang on her frig...:)
"Jorge Jimenez" wrote in message
news:5228010@discussion.autodesk.com...
Paul is making a good point here.

You should clear the error after the delete
because you could be ignoring a possible error
generated by the add method.

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica

"Joe Sutphin" wrote in message
news:5227773@discussion.autodesk.com...
Since I want to delete the selection set regardless and I know that if it
does not exist it's going to raise an error [which in this particular
instance I don't care about] I prefer to just ignore the error as opposed to
trapping it. Unlike for instance, say, when you're attempting to either get
a running instance or create a running instance of AutoCAD. Bottom line, I
think it is somewhat preferential and somewhat contextual.

Joe ...


"Paul Richardson" wrote in message
news:5227756@discussion.autodesk.com...
>On Error Resume Next
>ThisDrawing.SelectionSets("INSERTS").Delete
>Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")


If your going to use 'On Error Resume Next' here, I would check
for the error after trying to Delete your SS and clear it before
continuing. Or is it not necessary?

"Joe Sutphin" wrote in message
news:5227551@discussion.autodesk.com...
Here is something I threw together that may help you get going.

Joe ...

Option Explicit

Dim oApp As AcadApplication
Dim ThisDrawing As AcadDocument

Private Sub Command1_Click()
Dim oBlockRef As AcadBlockReference
If GetBlock(oBlockRef) Then
MsgBox "User selected a block with attributes"

Else
MsgBox "User selected a block without attributes"
End If
Unload Me
End Sub

Private Sub Form_Load()
On Error Resume Next
'attempt to get last version of AutoCAD opened
Set oApp = GetObject(, "AutoCAD.Application")

If Err Then
Err.Clear
'attempt to create instantiation of last version of AutoCAD opened
Set oApp = CreateObject("AutoCAD.Application")
'no AutoCAD is available
If Err Then
MsgBox "Cannot start AutoCAD ... sorry!", vbExclamation, "Error
starting AutoCAD"
Unload Me
End If
End If

oApp.Visible = True

Set ThisDrawing = oApp.ActiveDocument
End Sub

Private Function GetBlock(BlockRef As AcadBlockReference) As Boolean
Dim CurAtts As Variant
Dim oSS As AcadSelectionSet
Dim iFilterCode(0) As Integer
Dim vFilterValue(0) As Variant

iFilterCode(0) = 0
vFilterValue(0) = "INSERT"

On Error Resume Next
ThisDrawing.SelectionSets("INSERTS").Delete
Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")

oSS.SelectOnScreen iFilterCode, vFilterValue
On Error GoTo 0

If oSS(0).HasAttributes Then
'return the block to retrieve attributes
Set BlockRef = oSS(0)

GetBlock = True
End If
End Function

wrote in message news:5227195@discussion.autodesk.com...
Hi All,

I am working from outside AutoCAD and developing my application as a
separate VB6 application.
I am trying to open autoCAD andthen get the object of the drawing I have
open,but somehow my code fails to do so. Please help. Here is my code.

Private Sub Command1_Click()
Dim aDoc As Object
Set aDoc = acadApp.ActiveDocument
Dim blkref As AcadBlockReference 'AcadBlockReference
'Set blkref = acadDoc.Blocks
Dim CurAtts As Variant
Dim bspnt As Variant
aDoc.Utility.GetEntity blkref, bspnt, "Select Block To ShowAttributes: "
CurAtts = blkref.GetAttributes

Getblock = True
End Sub



Private Sub Form_Load()
Dim acadApp As Object
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True


End Sub

Also once I get the object ,I need to get the block on which the user
clicks.
Can someone please help me correcting my code .Any suggestion or code is
appreciated.

Thanks in advance.
Avantika
0 Likes
Message 11 of 14

Anonymous
Not applicable
Thanks for agreeing with my original position.


"Jorge Jimenez" wrote in message
news:5227982@discussion.autodesk.com...
The on error statement gets abused.

I would say it's best not to use it when it's possible
to use cleaner code :

Dim myset as AcadSelectionSet

For each myset in ThisDrawing.SelectionSets
if myset.name = "INSERTS" then
myset.delete
exit for
end if
next myset

set myset = thisdrawing.selectionsets.add("INSERTS")


--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica


"Paul Richardson" wrote in message
news:5227756@discussion.autodesk.com...
>On Error Resume Next
>ThisDrawing.SelectionSets("INSERTS").Delete
>Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")


If your going to use 'On Error Resume Next' here, I would check
for the error after trying to Delete your SS and clear it before
continuing. Or is it not necessary?

"Joe Sutphin" wrote in message
news:5227551@discussion.autodesk.com...
Here is something I threw together that may help you get going.

Joe ...

Option Explicit

Dim oApp As AcadApplication
Dim ThisDrawing As AcadDocument

Private Sub Command1_Click()
Dim oBlockRef As AcadBlockReference
If GetBlock(oBlockRef) Then
MsgBox "User selected a block with attributes"

Else
MsgBox "User selected a block without attributes"
End If
Unload Me
End Sub

Private Sub Form_Load()
On Error Resume Next
'attempt to get last version of AutoCAD opened
Set oApp = GetObject(, "AutoCAD.Application")

If Err Then
Err.Clear
'attempt to create instantiation of last version of AutoCAD opened
Set oApp = CreateObject("AutoCAD.Application")
'no AutoCAD is available
If Err Then
MsgBox "Cannot start AutoCAD ... sorry!", vbExclamation, "Error
starting AutoCAD"
Unload Me
End If
End If

oApp.Visible = True

Set ThisDrawing = oApp.ActiveDocument
End Sub

Private Function GetBlock(BlockRef As AcadBlockReference) As Boolean
Dim CurAtts As Variant
Dim oSS As AcadSelectionSet
Dim iFilterCode(0) As Integer
Dim vFilterValue(0) As Variant

iFilterCode(0) = 0
vFilterValue(0) = "INSERT"

On Error Resume Next
ThisDrawing.SelectionSets("INSERTS").Delete
Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")

oSS.SelectOnScreen iFilterCode, vFilterValue
On Error GoTo 0

If oSS(0).HasAttributes Then
'return the block to retrieve attributes
Set BlockRef = oSS(0)

GetBlock = True
End If
End Function

wrote in message news:5227195@discussion.autodesk.com...
Hi All,

I am working from outside AutoCAD and developing my application as a
separate VB6 application.
I am trying to open autoCAD andthen get the object of the drawing I have
open,but somehow my code fails to do so. Please help. Here is my code.

Private Sub Command1_Click()
Dim aDoc As Object
Set aDoc = acadApp.ActiveDocument
Dim blkref As AcadBlockReference 'AcadBlockReference
'Set blkref = acadDoc.Blocks
Dim CurAtts As Variant
Dim bspnt As Variant
aDoc.Utility.GetEntity blkref, bspnt, "Select Block To ShowAttributes: "
CurAtts = blkref.GetAttributes

Getblock = True
End Sub



Private Sub Form_Load()
Dim acadApp As Object
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True


End Sub

Also once I get the object ,I need to get the block on which the user
clicks.
Can someone please help me correcting my code .Any suggestion or code is
appreciated.

Thanks in advance.
Avantika
0 Likes
Message 12 of 14

Anonymous
Not applicable
I didn't say he wasn't making a good point. Merely pointing out that it's up
to the individual as to how they want to handle it. I posted my personal
preference and reasons for doing it that way. I have never [not to say that
it's not possible] encounted an error with the Add method used in the way
described. It's a trade-off between efficiency and stability.

Actually, now that I think about it, the better way to do it might be the
following:

If Not oSS Is Nothing Then
oSS.SelectOnScreen iFilterCode, vFilterValue
End If

Looping through the SelectionSets collection is just too costly.

Joe ...

"Jorge Jimenez" wrote in message
news:5228010@discussion.autodesk.com...
Paul is making a good point here.

You should clear the error after the delete
because you could be ignoring a possible error
generated by the add method.

--
Saludos, Ing. Jorge Jimenez, SICAD S.A., Costa Rica

"Joe Sutphin" wrote in message
news:5227773@discussion.autodesk.com...
Since I want to delete the selection set regardless and I know that if it
does not exist it's going to raise an error [which in this particular
instance I don't care about] I prefer to just ignore the error as opposed to
trapping it. Unlike for instance, say, when you're attempting to either get
a running instance or create a running instance of AutoCAD. Bottom line, I
think it is somewhat preferential and somewhat contextual.

Joe ...


"Paul Richardson" wrote in message
news:5227756@discussion.autodesk.com...
>On Error Resume Next
>ThisDrawing.SelectionSets("INSERTS").Delete
>Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")


If your going to use 'On Error Resume Next' here, I would check
for the error after trying to Delete your SS and clear it before
continuing. Or is it not necessary?

"Joe Sutphin" wrote in message
news:5227551@discussion.autodesk.com...
Here is something I threw together that may help you get going.

Joe ...

Option Explicit

Dim oApp As AcadApplication
Dim ThisDrawing As AcadDocument

Private Sub Command1_Click()
Dim oBlockRef As AcadBlockReference
If GetBlock(oBlockRef) Then
MsgBox "User selected a block with attributes"

Else
MsgBox "User selected a block without attributes"
End If
Unload Me
End Sub

Private Sub Form_Load()
On Error Resume Next
'attempt to get last version of AutoCAD opened
Set oApp = GetObject(, "AutoCAD.Application")

If Err Then
Err.Clear
'attempt to create instantiation of last version of AutoCAD opened
Set oApp = CreateObject("AutoCAD.Application")
'no AutoCAD is available
If Err Then
MsgBox "Cannot start AutoCAD ... sorry!", vbExclamation, "Error
starting AutoCAD"
Unload Me
End If
End If

oApp.Visible = True

Set ThisDrawing = oApp.ActiveDocument
End Sub

Private Function GetBlock(BlockRef As AcadBlockReference) As Boolean
Dim CurAtts As Variant
Dim oSS As AcadSelectionSet
Dim iFilterCode(0) As Integer
Dim vFilterValue(0) As Variant

iFilterCode(0) = 0
vFilterValue(0) = "INSERT"

On Error Resume Next
ThisDrawing.SelectionSets("INSERTS").Delete
Set oSS = ThisDrawing.SelectionSets.Add("INSERTS")

oSS.SelectOnScreen iFilterCode, vFilterValue
On Error GoTo 0

If oSS(0).HasAttributes Then
'return the block to retrieve attributes
Set BlockRef = oSS(0)

GetBlock = True
End If
End Function

wrote in message news:5227195@discussion.autodesk.com...
Hi All,

I am working from outside AutoCAD and developing my application as a
separate VB6 application.
I am trying to open autoCAD andthen get the object of the drawing I have
open,but somehow my code fails to do so. Please help. Here is my code.

Private Sub Command1_Click()
Dim aDoc As Object
Set aDoc = acadApp.ActiveDocument
Dim blkref As AcadBlockReference 'AcadBlockReference
'Set blkref = acadDoc.Blocks
Dim CurAtts As Variant
Dim bspnt As Variant
aDoc.Utility.GetEntity blkref, bspnt, "Select Block To ShowAttributes: "
CurAtts = blkref.GetAttributes

Getblock = True
End Sub



Private Sub Form_Load()
Dim acadApp As Object
Set acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True


End Sub

Also once I get the object ,I need to get the block on which the user
clicks.
Can someone please help me correcting my code .Any suggestion or code is
appreciated.

Thanks in advance.
Avantika
0 Likes
Message 13 of 14

Anonymous
Not applicable
I am interested as to why you think looping the SS Collection is too costly. As we remove SS's when we are finished with them we only have a few in existance at one time. Even if you had the max allowed I think it would still loop through pretty quickly.

Regards - Nathan
0 Likes
Message 14 of 14

Anonymous
Not applicable
Maybe ... but why bother if it isn't necessary.

The last change I presented is faster, more efficient and provides the same
level of error trapping.

Joe ...


wrote in message news:5229471@discussion.autodesk.com...
I am interested as to why you think looping the SS Collection is too costly.
As we remove SS's when we are finished with them we only have a few in
existance at one time. Even if you had the max allowed I think it would
still loop through pretty quickly.

Regards - Nathan
0 Likes