/Copy-bounded-area-AutoCAD

:straight_ruler: :triangular_ruler: Copy the area bounded by a polygon and everything inside it, to paste into a new file

Primary LanguageCommon LispGNU General Public License v3.0GPL-3.0

Copy-bounded-area-AutoCAD

AutoCAD_version

Copy the area bounded by a polygon and everything inside it, to paste into a new file

The code is divided into two parts, one to copy the entities and another part where the original coordinates are pasted into a new drawing. This code is intended for a large drawing with a grid structure where the drawing is formed by polygonal subdivisions of it.

Something like this:

image

In this context, if you want to save certain parts of the drawing separately and store it in separate files, you could do it using the following code.

AA

1. Select an entity from the drawing and initialize variables.

(SETQ cont 0)
(setq lista (entget(car(entsel)))); It asks us to select an entity of the drawing, in our case, we will select the frame that delimits the sheet that we want to copy and saves all the characteristics of the selected entity in a variable called 'lista'.
(setq puntos ())

2. Get the data of the vertices of the sheet frame.

(WHILE (/= (nth cont lista) (nth 39 lista))
(if (= (car(nth cont lista)) 10)
(setq puntos (append (list (cdr(nth cont lista))) (list puntos))))
(setq cont (+ cont 1))); In this way we go through the list, until the penultimate position (39), we obtain the vertices of the rectangle, which are stored in the list within sublists with the prefix 10. These vertices are stored in the list 'puntos'

3. Separate the points.

(setq p1 (car puntos))
(setq p2 (car (car (cdr puntos))))
(setq p3 (car (car (cdr (car (cdr puntos))))))
(setq p4 (car (car (cdr (car (cdr (car (cdr puntos))))))))
(setq pt_list (list p1 p2 p3 p4));

4. Select all entities within and passing through the sheet frame.

(setq conj (ssget "_CP" pt_list))

5. Copy the set to the clipboard.

(COMMAND "_.copyclip" conj "")
(setq conj2 (ssget "_WP" pt_list))
(command "_change" conj2 "" "_p" "_c" "3" ""); With this, the entities that are completely within the selected area are changed to green, this is to know which sheets have been copied.

CC (Before this code, open a new draw)

6. Paste the entiti es at original coordinates and focus the screen there.

(COMMAND "_.PASTEORIG" conj)
(command "_.ZOOM" "E")

7. Select polygon and delete everything outside said polygon.

(COMMAND "_.maptrim" "Seleccionar" Pause "No" "No" "Exterior" "Si" "Si" "Suprimir" "Si"); This command needs to be changed, it depends on the version.

8. Select file name and save it in specified folder.

(princ "Nombre del Archivo:")
(setq n_hoja (read-line)); We write the name of the new sheet
(setq name (strcat "C:\\Users\\...\\ INSERT HERE THE PATH" n_hoja ".dwg"))
(command "_.SAVE" name)

The steps to load and run these files.

1. Open the file and activate and unlock the layers that you want to copy.

2. Now you have to load the files with the code. To do this, it is first necessary to save the files in .lsp format through a text file.

To upload the files you have to access the 'Manage' tab on the toolbar and within this select upload application. image A pop-up window like this will open:

image

There we look for the folder where the '.lsp' files that we have created are located and press load. If everything went well, the box below will show that the action has been successful.

Now, so that these files can be found in each new drawing that is opened, we will have to load them at the beginning, therefore, without leaving this window, click 'Content...' in the part that says 'Load at the beginning' and will open another popup: image

In this case, the loaded files already appear, but if it is the first time, they must be loaded by searching for the files once we have clicked 'Add'. Once this is done we close both pop-up windows.

The code is already loaded in AutoCAD, now you have to run it. To do this, simply write the name of the file in the autocad drawing window or in the command line and execute it.

Example: We select the file saved as 'AA' image

We select the frame of the sheet that we want to extract, press enter and all the entities within the frame will automatically change to green, to highlight that this sheet is already copied. image

image

Next, a new drawing must be opened and in it the same as in the first step above will be done, but this time with the CC command and the result is:

image

We mark the frame of the sheet again so that the outside of it is cut: image

We put the name of the file and it will automatically be saved in the path specified in the code.