Creating a default layer sheet

As part of my preparing an AutoCAD drawing for my office’s layering system I managed to insert layers into a drawing from Excel using only scripting.

However the creation of a line and a text on each of the layers, so that users can copy and paste to get the layers etc. into new drawings, needed full AutoCAD and its access to LISP to create these quickly.

The script below is a modified (larger text and longer lines) version of a script, kindly written, from here.

(defun c:lintextfromlayer (/ pt dat ln)
(setq pt (getpoint “\nSelect insertion point: “))
(while (setq dat (tblnext “layer” (null dat)))
(entmake (list ‘(0 . “line”) (cons 10 pt) (cons 11 (mapcar ‘+ pt ‘(5000 0 0))) (cons 8 (setq ln (cdr (assoc 2 dat))))))
(entmake (list ‘(0 . “text”) (cons 10 (mapcar ‘+ pt ‘(5200 -125 0))) ‘(40 . 250) (cons 1 ln) (cons 8 ln)))
(setq pt (mapcar ‘- pt ‘(0 1000 0))))
(princ))

 

Excel to AutoCAD layers

I have been attempting to update our office’s layer system. This would be difficult to do in AutoCAD without resorting to LISP or some programming to insert layers on mass. Creating lots of text on mass is really easy to do in Excel so that would be the program of choice to do this task.

The problem then comes of getting these layers into AutoCAD? There are numerous Lisp programs around on the internet to do this but what if you have AutoCAD LT only (as it lacks programming APIs)?

You can use Excels powerful cell commands to convert your layer list to a format that will then be able to create a script file. Below I will go through the steps you need to do to get this to work. (Note this is not my concept but I cannot find the original page where this was proposed).

Firstly create a blank Excel document.

Then place “-LAYER” in the 4th column over.

Now we are ready to input some data into the first three columns. This is in the order, layer name, colour, linetype. Make sure the second column for colour is text only to avoid any true colours being converted into numbers.

One completed we will now enter the following command below the cell with -layer in.

=IF(ISNUMBER(SEARCH(“,”,B2)),”N “& CHAR(34)&TRIM(A2)& CHAR(34)&” C T “&TRIM(B2)&” “& CHAR(34)&TRIM(A2)& CHAR(34)&” LT “&TRIM(C2)&” “& CHAR(34)&TRIM(A2)& CHAR(34),”N “& CHAR(34)&TRIM(A2)& CHAR(34)&” C “&TRIM(B2)&” “& CHAR(34)&TRIM(A2)& CHAR(34)&” LT “&TRIM(C2)&” “& CHAR(34)&TRIM(A2)& CHAR(34))

This creates the magic that is script. (Note the quotes are required for layer names with spaces).

Add layer information down the left and drag the little square in the bottom right of the excel cell to copy this to all cells below.

Once completed, save this file for future reference.

Copy the entire column of D and paste to a new file using paste values only.

Now the file is ready to become a script. Save as Formatted Text (space delimited) PRN file.

You should now have a text file that has the entire script for making your layers you need in it. Two steps to go!

Firstly we are going to rename the extension on the file (if you cannot see extensions follow this). This needs to be renamed from myscript.prn to myscript.scr.

Then open the file and add a return at the very end to create another line. This will terminate the last command and thus end the script.

Finally we load the script into AutoCAD using the command “script“.

Voila, all the layers are now in AutoCAD.

No layers information

One of my colleagues noted that they no longer could see the layers information in the Layers Drop down box when selecting objects.

autocad_pickfirstoff

The image above shows this issue, the object is on a differing layer to that shown, the Layers Drop down only shows the current layer.

In order to fix this the system variable PICKFIRST needs to be set to 1, which should be the default for this variable. Sometimes if AutoCAD crashes this seems to be reset to 0. Now when the object is selected it should display the layer information in the Layers Drop down.

autocad_pickfirston

XREFs and Layers

A colleague of mine was struggling with numerous issues when using XREFs. The two main ones where having multiple Layer States with XREF prefixes that couldn’t be removed and the other was not wanting to see the XREF layers.

Layer States Dialogue for no XREFs does not work with Ribbon pulldown
Layer States Dialogue for no XREFs does not work with Ribbon pulldown

The first issue was frustrating as whilst there is an option to disable these is in the layer states manger dialogue, checking the box does not disable them in the Ribbon pulldown. Duh. So the solution ended up being, delete the layer states in the XREF.

The second issue was easy to solve as AutoCAD has this feature built-in and it works! It works with both the Layer Pulldown, Layer Palette and Classic Layer! Wow!

Layer Drop Down showing XREF layers
Layer Drop Down showing XREF layers

This is how to remove XREF layers from these palettes. You will need a filter (yup AutoCAD has layer filters!)

Layer Pallette indicating the filter section
Layer Palette indicating the filter section

On the panel on the left, click XREF, this will now show the list of layers for the XREF. Click on the checkbox below that states Invert Filter and voila, you have a list of layers without XREF layers within.