AutoCAD/Macros

Advertisement


Question
QUESTION: I have the following Macro for a pull down menu to change layers:
^C^C(setvar "clayer" "layername")
I have added the following to the Macro to allow a layer that is not in a drawing to be inserted just by selecting it in the pull down menu.
^C^C(command "filedia" 0);(command "script");layers.scr;(command "filedia" 1 )
This was working in Auto Cad 2011, however I now have 2013 Mechanical and it will not work can you help?
Thanks

ANSWER: Hi Jon,

Your macro runs a script file called Layers.scr.  My first guess is that the file is not in the support file search path; AutoCAD 2013 cannot find it.

A quick check is to type the following at the command line:

(findfile "layers.scr")

If it returns nil, AutoCAD did not find the file.  Check your 2011 version to see where the file was located, and add the folder to your 2013 support file search path (the first tab in OPTIONS).

Let me know if this helps or not, or if you have any questions.

Regards,
Scott Wilcox

---------- FOLLOW-UP ----------

QUESTION: Thanks Scott

I have the file in the support file now but I get the following error:

Command: (setvar "clayer" "B-TAB-ALL") ; error: AutoCAD variable setting rejected: "clayer" "B-TAB-ALL"

B-TAB-ALL is the layer I want to insert in to the drawing.

Jon

ANSWER: Hi again, Jon.

The "clayer" variable identifies or sets the current layer, so (SETVAR "CLAYER" "B-TAB-ALL") simply means for AutoCAD to change layer C-TAB-ALL to be current.  

For the command to execute the layer has to exist in the drawing, else it returns an error; AutoCAD cannot make a non-existent layer current.  The error message means that AutoCAD did not find the named layer in your drawing (in your case layer B-TAB-ALL).

Did the layers.scr file run? My guess is it did not. I suspect the script file creates the B-TAB-ALL layer (among other things) when it runs.

Open the SCR file in a text editor, and take a look. If you are unsure, reply to this, copy and paste the contents of the layers.scr file into your message and I will take a look.

On a completely different topic, I am from Newfoundland, graduating from Cabot (now CONA) a few years back.

Let me know if this helps at all.

Scott

---------- FOLLOW-UP ----------

QUESTION: Hi Scott

Below is the contents of my Layers.scr file I assume it is incorrect.

-LAYER
N B-BDR-ALL C 7 B-BDR-ALL
N B-TXT-ALL C 7 B-BDR-ALL
N B-TAB-ALL C 7 B-BDR-ALL

Nice to see your from Newfoundland as well I just moved back in the fall after 11 + years in Halifax I went to Marine.

Thanks
Jon

Answer
Jon, the script looks OK.

-LAYER
N B-BDR-ALL C 7 B-BDR-ALL
N B-TXT-ALL C 7 B-BDR-ALL
N B-TAB-ALL C 7 B-BDR-ALL

What does it all mean? It's basically imitating keyboard input:

The -LAYER means run the layer command without a dialog box (the - sign does that)
N means make a new layer
B-BDR-ALL is a layer name
C means set the layer color
7 is color 7 (white)


The command typically ends with the layer name at the end

-LAYER
N B-BDR-ALL C 7 B-BDR-ALL
N B-TXT-ALL C 7 B-TXT-ALL
N B-TAB-ALL C 7 B-TAB-ALL

With that said, it should still work as-is.

Since every space in a script is the same as the enter key, you will need a blank line at the end of the script file.

I tried your script, it looks fine.  If you are getting the error message, I think it means AutoCAD is still not finding the SCR file.  

Try the (findfile "layers.scr") again and make sure AutoCAD is finding it.  Also remember, AutoCAD loads the FIRST INSTANCE it finds, so if you have several files called LAYERS.SCR in several directories, AutoCAD goes through the support file list, in order, and loads the first one it finds.  

In order for the CLAYER to work, the layer already need to be in the drawing, so make sure it exists (the script file is supposed to create it)

In Summary:
1. Run the script and check if your layers were created.
2. Run the clayer and check if the layer is now current.

If the layers are not there, my guess is AutoCAD could not find the script file.  As a test, type SCRIPT at the command prompt, and browse to the LAYERS.SCR file and load it manually.  Try step 2 again and see if the layer is current.

Let me know how all this works out.

I went to the ETC, next door to Marine.  Had many plates of fish and chips on Fridays there.  Graduated in 1996.

Scott


    Thanks Scott The problem was the space I had before the "N" in the script. It is now inserting the layer in to the drawing as I want and when in the drawing I can use the pull down menu to jump between layers. The only issue now is when I use the pull down menu to jump between layers a list comes up on the command line asking me to "Enter a option" and the options include "?, Make, Set, New and Rename" just to name some. How do I stop this from coming up I just want to select the layer from the pull down menu and start working with in the layer. I completed Naval Arc in 2001 and Marine Systems in 2002 and I also enjoyed the fish on Friday, in fact my co-workers and I went back last week and it is still good. Cheers, Jon

Hi, Jon.  I happened to read your question in the comments.  Normally I would not have seen this, since I only get notifications when there is a question or follow up posted.

There may also be a space in your macro line.  If you are using the drop down immediately after running the layers.scr, then it would make sense that there is a space in the macro.  Remember, space is the same as enter, and hitting enter without a command repeats the last command.  If so, remove the space before (setvar "clayer" "B-TAB-ALL").

Check it out, and let me know.

Cheers!
scott  

AutoCAD

All Answers


Answers by Expert:


Ask Experts

Volunteer


Scott Wilcox

Expertise

I have been using AutoCAD since R11, and can answer questions regarding general AutoCAD, menus, toolbars, fonts, linetypes, plotting, CUI, Some Civil 3D

Experience

23 years AutoCAD user (R11- R2015), AUGI Director

Organizations
AUGI

Publications
CADALYST

Education/Credentials
Instructor @ Alberta School of Drafting

©2016 About.com. All rights reserved.