deleting graphical objects

deleting graphical objects

Anonymous
Not applicable
294 Views
8 Replies
Message 1 of 9

deleting graphical objects

Anonymous
Not applicable
James,

The ModelSpace collection may contain an AcadBlockReference
object but not an AcadBlock.

Denis

James McElroy, Jr. a écrit dans le message
<384857F6.7118CB48@integware.com>...
>if I have a block with a few boxes in modelspace. How can I then delete
>the visible graphical boxes from the block and from modelspace. How,
>also, can I delete the block from modelspace?]
>James
>
>--
>*********************************
>* James S. McElroy, Jr. *
>* james@integware.com *
>*********************************
>
>
0 Likes
295 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
When you delete an AcadBlockReference you also delete the
graphical objects contained in your model space (or in a layout) but the
Block definition (AcadBlock) which is stored in the AcadBlocks
collection is kept for further use.

I'm still not sure to understand what you want to delete.
Is it all the AcadBlockReferences of particular name???
Is it the block definition???

Denis

James McElroy, Jr. a écrit dans le message
<38485E25.53A1DAB7@integware.com>...
>Oop's, that's what I meant, my problem is that I can delete all the refs.
>that I want but I need to know how to delete the graphical objects so that
I
>can completely get rid of a block and the objects
>James
>
>Denis Gagne wrote:
>
>James,
>
>The ModelSpace collection may contain an AcadBlockReference
>object but not an AcadBlock.
>
>Denis
>--
>*********************************
>* James S. McElroy, Jr. *
>* james@integware.com *
>*********************************
>
>
0 Likes
Message 3 of 9

Anonymous
Not applicable
if I have a block with a few boxes in modelspace. How can I then delete
the visible graphical boxes from the block and from modelspace. How,
also, can I delete the block from modelspace?]
James

--
*********************************
* James S. McElroy, Jr. *
* james@integware.com *
*********************************
0 Likes
Message 4 of 9

Anonymous
Not applicable
Oop's, that's what I meant, my problem is that I can delete all the refs.
that I want but I need to know how to delete the graphical objects so that I
can completely get rid of a block and the objects
James

Denis Gagne wrote:

James,

The ModelSpace collection may contain an AcadBlockReference
object but not an AcadBlock.

Denis
--
*********************************
* James S. McElroy, Jr. *
* james@integware.com *
*********************************
0 Likes
Message 5 of 9

Anonymous
Not applicable


Sorry I'm not being clear, the whole block and block ref. thing is seriously
confusing to me.  I'm having to teach myself this api and I've only
got the one Joe Sutphin book to help me and that is vague and obscure and
doesn't cover a lot of areas.  So, let me start from the beginning
of what I'm doing and see if that helps

Okay,  I create a block in the document.blocks collection. 
I take that block and do a few block.addbox to create some 3d solids. 
then I do a modelspace.insert with the origin, blockname, scales and rotation. 
When I insert it I set it to a blockreference which I insert into a group. 
Also, when I created the 3dsolids I added them to the group as well.

Now, my objective here is to run a different function that has the block
and the group names, and I want to get rid of everything
the blocks, refs, definitions, solids, whatever it is that I need to get
rid of to destroy it all and leave me with a document that does not now
have the aforementioned objects that I created and added.

Maybe I'm doing something wrong while creating them and if so feel free
to tell me.  But that's what I need to know how to do and all the
book tells me is that to delete a block I have to delete all references
to said block but it doesn't explain any further.

James

Denis Gagne wrote:

When you delete an AcadBlockReference you also delete
the

graphical objects contained in your model space (or in a layout) but
the

Block definition (AcadBlock) which is stored in the AcadBlocks

collection is kept for further use.

I'm still not sure to understand what you want to delete.

Is it all the AcadBlockReferences of particular name???

Is it the block definition???

Denis

James McElroy, Jr. a écrit dans le message

<38485E25.53A1DAB7@integware.com>...

>Oop's, that's what I meant, my problem is that I can delete all the
refs.

>that I want but I need to know how to delete the graphical objects
so that

I

>can completely get rid of a block and the objects

>James

>

>Denis Gagne wrote:

>

>James,

>

>The ModelSpace collection may contain an AcadBlockReference

>object but not an AcadBlock.

>

>Denis

>--

>*********************************

>*     James S. McElroy, Jr.    
*

>*      james@integware.com     
*

>*********************************

>

>



--

*********************************

*     James S. McElroy, Jr.    
*

*      james@integware.com     
*

*********************************

 

0 Likes
Message 6 of 9

Anonymous
Not applicable
I am very disappointed to hear that you do not appreciate
AutoCAD 2000 vba programmer's reference and I hope
your opinion will change in the future.

It's difficult for me to find a solution to your problem without
seeing your code.

but here's a suggestion:

Option Explicit
Option Compare Text

Public Function DeleteThis(NameOfBlockToDelete As String, _
NameOfGroupToDelete As String)
Dim oEnt As AcadEntity
Dim oBlock As AcadBlock
Dim oGroup As AcadGroup

Set oGroup = ThisDrawing.Groups(NameOfGroupToDelete)
For Each oEnt In oGroup
oEnt.Delete
Next
oGroup.Delete

For Each oEnt In ThisDrawing.ModelSpace
If TypeOf oEnt Is AcadBlockReference Then
If oEnt.Name = NameOfBlockToDelete _
Then oEnt.Delete
End If
Next

ThisDrawing.Application.Update

For Each oBlock In ThisDrawing.Blocks
If oBlock.Name = NameOfBlockToDelete _
Then oBlock.Delete
Next
End Function

Denis

James McElroy, Jr. a écrit dans le message
<38486552.76999782@integware.com>...
Sorry I'm not being clear, the whole block and block ref. thing is
seriously confusing to me. I'm having to teach myself this api and I've
only got the one Joe Sutphin book to help me and that is vague and obscure
and doesn't cover a lot of areas. So, let me start from the beginning of
what I'm doing and see if that helps
Okay, I create a block in the document.blocks collection. I take that
block and do a few block.addbox to create some 3d solids. then I do a
modelspace.insert with the origin, blockname, scales and rotation. When I
insert it I set it to a blockreference which I insert into a group. Also,
when I created the 3dsolids I added them to the group as well.

Now, my objective here is to run a different function that has the block
and the group names, and I want to get rid of everything! the blocks, refs,
definitions, solids, whatever it is that I need to get rid of to destroy it
all and leave me with a document that does not now have the aforementioned
objects that I created and added.

Maybe I'm doing something wrong while creating them and if so feel free
to tell me. But that's what I need to know how to do and all the book tells
me is that to delete a block I have to delete all references to said block
but it doesn't explain any further.
James

Denis Gagne wrote:

When you delete an AcadBlockReference you also delete the
graphical objects contained in your model space (or in a layout) but
the
Block definition (AcadBlock) which is stored in the AcadBlocks
collection is kept for further use.
I'm still not sure to understand what you want to delete.
Is it all the AcadBlockReferences of particular name???
Is it the block definition???

Denis

James McElroy, Jr. a écrit dans le message
<38485E25.53A1DAB7@integware.com>...
>Oop's, that's what I meant, my problem is that I can delete all the
refs.
>that I want but I need to know how to delete the graphical objects
so that
I
>can completely get rid of a block and the objects
>James
>
>Denis Gagne wrote:
>
>James,
>
>The ModelSpace collection may contain an AcadBlockReference
>object but not an AcadBlock.
>
>Denis
>--
>*********************************
>* James S. McElroy, Jr. *
>* james@integware.com *
>*********************************
>
>

--
*********************************
* James S. McElroy, Jr. *
* james@integware.com *
*********************************
0 Likes
Message 7 of 9

Anonymous
Not applicable
James:

why don't you post your
code, so we know what is your problems!

 

amy

ps: without Joe Sutphine's book we are all in the
dark!

 


style="BORDER-LEFT: #000000 solid 2px; MARGIN-LEFT: 5px; PADDING-LEFT: 5px">
Sorry
I'm not being clear, the whole block and block ref. thing is seriously
confusing to me.  I'm having to teach myself this api and I've only got
the one Joe Sutphin book to help me and that is vague and obscure and
doesn't cover a lot of areas.  So, let me start from the beginning of
what I'm doing and see if that helps

Okay,  I create a block in the document.blocks collection.  I
take that block and do a few block.addbox to create some 3d solids. 
then I do a modelspace.insert with the origin, blockname, scales and
rotation.  When I insert it I set it to a blockreference which I insert
into a group.  Also, when I created the 3dsolids I added them to the
group as well.

Now, my objective here is to run a different function that has the block
and the group names, and I want to get rid of everything!  the
blocks, refs, definitions, solids, whatever it is that I need to get rid of
to destroy it all and leave me with a document that does not now have the
aforementioned objects that I created and added.

Maybe I'm doing something wrong while creating them and if so feel free
to tell me.  But that's what I need to know how to do and all the book
tells me is that to delete a block I have to delete all references to said
block but it doesn't explain any further.
James

Denis Gagne wrote:

When you delete an AcadBlockReference you also
delete the
graphical objects contained in your model space (or in a
layout) but the
Block definition (AcadBlock) which is stored in the
AcadBlocks
collection is kept for further use.

I'm still not sure to understand what you want to delete.
Is it
all the AcadBlockReferences of particular name???
Is it the block
definition???

Denis

James McElroy, Jr. a écrit dans le message

<38485E25.53A1DAB7@integware.com>...
>Oop's, that's
what I meant, my problem is that I can delete all the refs.
>that
I want but I need to know how to delete the graphical objects so that

I
>can completely get rid of a block and the objects

>James
>
>Denis Gagne wrote:
>

>James,
>
>The ModelSpace collection may contain an
AcadBlockReference
>object but not an AcadBlock.
>

>Denis
>--
>*********************************

>*     James S. McElroy,
Jr.     *
>*     
james@integware.com      *

>*********************************
>
>


--
*********************************
*    
James S. McElroy, Jr.     *

*     
james@integware.com      *

*********************************
 

0 Likes
Message 8 of 9

Anonymous
Not applicable
alright, alright, sorry I badmouthed the book a little, I know that it's
pretty much all we have and I'd be completely lost without it. I'm just
saying that there are some areas where important topics like removing
objects are somewhat glossed over and not explained well.
okay, now that that's out of the way, I tried Denis' code in with mine
but it gives err's when it tries to delete stuff.
Okay, so here's my deletion code. Lets assume that in this group there
is the acadblockreference for a block called Title_Bar. Using the Block
Title_Bar I added two boxes and several acadattributes and inserted the
block into modelspace. Everything, including my meta attributes and the
3dsolids, I have appended to the group with name strName. So, here's my
deletion code. All it's doing right now is removing everything from the
group. I added in Denis' code at the end while trying to delete the
block. but it's not working and the geometry stays visible. The code
is clearing out the group correctly though because at the end the count
is 0.
grpChart is the group I'm using.
James

iIndex = grpChart.Count()

iAtCnt = 0
iSlCnt = 0
iBlCnt = 0
If iIndex > 0 Then
For i = 0 To iIndex - 1
'tell what the entity name is
MsgBox grpChart.Item(i).EntityName
'if the item is an attribute then add to attribute array
If grpChart.Item(i).EntityName = "AcDbAttributeDefinition"
Then
If iAtCnt = 0 Then
ReDim objAtts(iAtCnt)
Else
ReDim Preserve objAtts(iAtCnt)
End If
Set objAtts(iAtCnt) = grpChart.Item(i)
iAtCnt = iAtCnt + 1
'else if the item is a 3dsolid then add to solid array
ElseIf grpChart.Item(i).EntityName = "AcDb3dSolid" Then
If iSlCnt = 0 Then
ReDim objSols(iSlCnt)
Else
ReDim Preserve objSols(iSlCnt)
End If
Set objSols(iSlCnt) = grpChart.Item(i)
iSlCnt = iSlCnt + 1
'else if the item is a block ref. then add to block array
ElseIf grpChart.Item(i).EntityName = "AcDbBlockReference"
Then
If iBlCnt = 0 Then
ReDim objBlks(iBlCnt)
Else
ReDim Preserve objBlks(iBlCnt)
End If
Set objBlks(iBlCnt) = grpChart.Item(i)
iBlCnt = iBlCnt + 1
End If
Next i
'if there were attributes then remove them
If iAtCnt > 0 Then
grpChart.RemoveItems objAtts
If Err Then
MsgBox "error deleting attributes"
End If
End If
'if there were solids then remove them
If iSlCnt > 0 Then
grpChart.RemoveItems objSols
If Err Then
MsgBox "error deleting solids"
End If
End If
'if there were blocks then remove them
If iBlCnt > 0 Then
grpChart.RemoveItems objBlks
If Err Then
MsgBox "error deleting blocks"
End If
For Each objEnt In ThisDrawing.ModelSpace
If TypeOf objEnt Is AcadBlockReference Then
If objEnt.Name = "Title_Bar" Then
objEnt.Delete
If Err Then
MsgBox "unable to delete blkref
'Title_Bar'"
Else
MsgBox "block ref delete completed"
End If
End If
End If
Next objEnt

ThisDrawing.Application.Update

For Each objBlock In ThisDrawing.Blocks
If objBlock.Name = "Title_Bar" Then
objBlock.Delete
If Err Then
MsgBox "unable to delete blk 'Title_Bar'"
Else
MsgBox "block delete completed"
End If
End If
Next objBlock
End If
'output number of items
MsgBox "Number of items " & grpChart.Count
End If
0 Likes
Message 9 of 9

Anonymous
Not applicable
okay, so let's try a simple one. here's some code that I just wrote to test
this. now, how would I have to modify the delete function in order to
destroy the block and erase the box from the drawing?

Sub test_blocks()
Dim oblk As AcadBlock
Dim oblkr As AcadBlockReference
Dim obox As Acad3DSolid
Dim dorg(2) As Double
dorg(0) = 0: dorg(1) = 0: dorg(2) = 0

On Error Resume Next
Set oblk = ThisDrawing.Blocks("hi")
If oblk Is Nothing Then
Set oblk = ThisDrawing.Blocks.Add(dorg, "hi")
Set obox = oblk.AddBox(dorg, 1, 0.5, 0.01)
Set oblkr = ThisDrawing.ModelSpace.InsertBlock(dorg, "hi", 1, 1, 0)
Else
Call delete
End If

End Sub

Sub delete()
Dim oblk As AcadBlock
Dim oblkr As AcadBlockReference
Dim oent As AcadEntity

On Error Resume Next
For Each oent In ThisDrawing.ModelSpace
oent.delete
If Err Then
MsgBox "error deleting " & oent.EntityName
End If
Next

Set oblkr = ThisDrawing.Blocks("hi")
If Not oblkr Is Nothing Then
oblkr.delete
If Err Then
MsgBox "error deleting blkr " & oblkr.EntityName
End If
Else
MsgBox "blkr doesn't exist"
End If

Set oblk = ThisDrawing.Blocks("hi")
If Not oblk Is Nothing Then
oblk.delete
If Err Then
MsgBox "error deleting blk " & oblk.EntityName
End If
Else
MsgBox "blk doesn't exist"
End If

End Sub

*********************************
* James S. McElroy, Jr. *
* james@integware.com *
*********************************
0 Likes