delete everything (layers, objects and layouts)

delete everything (layers, objects and layouts)

erhan.lale
Contributor Contributor
1,657 Views
4 Replies
Message 1 of 5

delete everything (layers, objects and layouts)

erhan.lale
Contributor
Contributor

Hello,

 

i am a beginner and need help:

in my vba-programm user clicks to 4 points and after it i create a polyline. But I want to delete everything before crete polyline: i mean all layers (locked or not locked), all objects and layouts. Is there any easy way to clean everything?

 

I am using "send command", delete and all. But i can not select and delete layers and layouts, if i don't know names.

 

Is there an easy way? Or can i create a new empty file and use points on this?

0 Likes
Accepted solutions (1)
1,658 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor
Accepted solution

Firstly, try not to use AcadDocument.SendCommand(), in most cases while writing code in VBA.

 

You did not provide your business workflow in regard of why you need to delete everything in drawing before user executes your code to create a polyline. But, yes, simply opening a new blank drawing (base on proper drawing template, of course) would be easier, if your workflow does not require to use currently opened/specific drawing. The code would be like:

 

Dim dwg As AcadDocument

Set dwg = Application.Documents.Add("[template name]")

DrawPolyline dwg

... ...

 

Private Sub DrawPolyline(dwg As AcadDocument)

  '' Ask user to pick points

  '' Draw polyline with user picked points

End Sub

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 5

erhan.lale
Contributor
Contributor

I want to draw poylgons as polyline for CNC machine (only 2d).

 

We have problems because of invisible layers or some objects, which far a way from main drawing etc. We are always looking for, is there anything else. I have aready drawings with dimentions and a lot of other elements. My idea is so: User clicks on all edge of polygon object, I delete everything (layouts, layers and all objects) and draw a poyline on Layer 0. The issue is: i need to pick points, before I delete everything.

0 Likes
Message 4 of 5

norman.yuan
Mentor
Mentor

Well, I am still not sure why picking points and then drawing polyline (or anything) has anything to do with deleting everything, especially why you need to delete Layouts. If you choose open a new blank drawing, why do you bother deleting everything?

 

If deleting everything means to result in a blank drawing, simply open a new. blank drawing would be the easiest, in term of writing code.

 

If for some specific reason that you have to use the currently open drawing, and must delete everything first, and then picking/drawing, you should use COM API code to delete everything, instead of using "SendCommand()". You would need to not only delete every entities on each layout (or simply delete layout. but ModelSpace cannot be deleted), and then delete everything in ModelSpace, but also delete all block definitions, styles..., for this part of deleting, you actually "Purge" the drawing. As you can see, it could be quite some coding, in comparison of just opening a new blank drawing.

 

Maybe, your actual workflow is that you need user to pick points on the polygon from the currently open drawing, and then do the drawing? Again, it is not really clear of your workflow and why you tie the deleting everything and picking/drawing together.

 

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 5

Anonymous
Not applicable

I dont think so,

 

cà phê nguyên chất

 

0 Likes