ERASE OBJECTS IN VBA

ERASE OBJECTS IN VBA

Anonymous
Not applicable
764 Views
3 Replies
Message 1 of 4

ERASE OBJECTS IN VBA

Anonymous
Not applicable
In a drawing I wish to erase an object in selecting, but also to erase the
object which had been introduced before this object.
I suppose that it is necessary to call upon handel.
You have a good idea or a code vba for to help me.

Thank you Belgium greets you.

Philippe
0 Likes
765 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
This may not be the best way to do this, but here is what I thought of
first:

Use a select method to get the name of the name of the Item to be deleted
using:

SSet.Item(SSIndex).Name

Then iterate throught the modelspace collection:

index=0
Do
index=index +1
Loop Until ThisDrawing.ModelSpace.Item(index).name=SSet.Item(SSIndex).Name
or index >=ThisDrawing.ModelSpace.count

When this loop ends, then ThisDrawing.ModelSpace.Item(index-1) is your
objective.

I have not actually tested this, but it should work in theory.

JHR

"philwil" wrote in message
news:22C7E5A6282DF4137F2699D82AE719A2@in.WebX.maYIadrTaRb...
> In a drawing I wish to erase an object in selecting, but also to erase the
> object which had been introduced before this object.
> I suppose that it is necessary to call upon handel.
> You have a good idea or a code vba for to help me.
>
> Thank you Belgium greets you.
>
> Philippe
>
>
>
0 Likes
Message 3 of 4

Anonymous
Not applicable
If your application is very practical then this may work. This will not work
in a situation such as:

Entity A is created
Entity B is created
Entity C is created
Entity B is DELETED

...now A is the entity before C, the code below would point to entity B,
which does not exist.


Sub TryThis()
Dim sHandle As String
Dim oEnt As AcadEntity
Dim Pt As Variant

'Get the first entity
ThisDrawing.Utility.GetEntity oEnt, Pt, "Pick an object: "
'Save the handle
sHandle = oEnt.Handle
'Delete the entity
oEnt.Delete
'Subtract one from the handle
sHandle = Hex(CSng("&h" & sHandle) - 1)
'Now you'll get the entity that was created BEFORE the first entity you
picked
Set oEnt = Application.ActiveDocument.HandleToObject(sHandle)
'And finally delete that entity also
oEnt.Delete

End Sub

"John Hope-Ross" wrote in message
news:D67F846DFB40142715C8DB8E7DC5FE0C@in.WebX.maYIadrTaRb...
> This may not be the best way to do this, but here is what I thought of
> first:
>
> Use a select method to get the name of the name of the Item to be deleted
> using:
>
> SSet.Item(SSIndex).Name
>
> Then iterate throught the modelspace collection:
>
> index=0
> Do
> index=index +1
> Loop Until ThisDrawing.ModelSpace.Item(index).name=SSet.Item(SSIndex).Name
> or index >=ThisDrawing.ModelSpace.count
>
> When this loop ends, then ThisDrawing.ModelSpace.Item(index-1) is your
> objective.
>
> I have not actually tested this, but it should work in theory.
>
> JHR
>
> "philwil" wrote in message
> news:22C7E5A6282DF4137F2699D82AE719A2@in.WebX.maYIadrTaRb...
> > In a drawing I wish to erase an object in selecting, but also to erase
the
> > object which had been introduced before this object.
> > I suppose that it is necessary to call upon handel.
> > You have a good idea or a code vba for to help me.
> >
> > Thank you Belgium greets you.
> >
> > Philippe
> >
> >
> >
>
>
0 Likes
Message 4 of 4

Anonymous
Not applicable
Thank you for your assistance.

I have the error message (news cadvba01.jpg)

It is not possible to work rather of following manner:
I take again your example (it is the good example).

Entity A is created
Entity B is created
Entity C is created
Entity B is DELETED

It possible that while working in this manner it is simpler :

I select the entity B
I activate your code VBA
This code VBA
seek the entity which was created before him (either A)
It selects this
entity A
Finally it erases A and B


Philwil.





"philwil" a écrit dans le message de news:
22C7E5A6282DF4137F2699D82AE719A2@in.WebX.maYIadrTaRb...
> In a drawing I wish to erase an object in selecting, but also to erase the
> object which had been introduced before this object.
> I suppose that it is necessary to call upon handel.
> You have a good idea or a code vba for to help me.
>
> Thank you Belgium greets you.
>
> Philippe
>
>
>
0 Likes