Macro change layer

Macro change layer

jostroopers
Collaborator Collaborator
3,583 Views
12 Replies
Message 1 of 13

Macro change layer

jostroopers
Collaborator
Collaborator

I use this macro to make the layer active when I activate a certain command.
This works well if I use the icon in the ribbon.
But if I use the shortcut then the layer does not become active.
Can someone tell me why it doesn't work with the shortcut?

 

^C^C-layer;m;Maatvoering;c;3;;;_dimlinear;\\\layerp;

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
0 Likes
Accepted solutions (3)
3,584 Views
12 Replies
Replies (12)
Message 2 of 13

ВeekeeCZ
Consultant
Consultant

Are you on LT?

I tried that and it works the same (bad) no matter where from is used.

The problem is that the LAYERP returns the last change of layers properties, which can be just a color! 

 

Think of what is actually returned by LAYERP when:

- your layer does not exist

- your layer does exist but not current

- your layer does exist and is already current

- your layer is off...

 

0 Likes
Message 3 of 13

jostroopers
Collaborator
Collaborator

Iam not on LT.

I changed the macro and i deleted \\\layerp;

But it didn't work.

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
0 Likes
Message 4 of 13

jostroopers
Collaborator
Collaborator

If i use the icon, on the commandline i see _dimlinear.

When i use the shortcut i see on the commandline dimlinear, no underscore.

I changed the .pgp file to _dimlinear but that didn't change.

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
0 Likes
Message 5 of 13

ВeekeeCZ
Consultant
Consultant

Don't do that. It does not matter unless you use non-english autocad.

 

So what we can do... we could either try to search what's going on... In that case, you need to give me more information... like command line listing, record video of what you do... 

 

... or simply use a LISP as your macro. And because it gives you better and predictable performance I suggest to use that. Adjusting a menu-macro to similar performance would be rather challenging, possibly not possible.

((lambda (/ l) (setq l (getvar 'clayer)) (command "_.-layer" "_t" "Maatvoering" "_m" "Maatvoering" "_c" 3 "" "") (command-s "_.dimlinear") (setvar 'clayer l) (princ)))

Above code in a more understandable format with comments:

((lambda (/ l)									; annonymous function
   (setq l (getvar 'clayer))							; save current layer name
   (command "_.-layer" "_t" "Maatvoering" "_m" "Maatvoering" "_c" 3 "" "")	; thaw, make new or just current, change the color in needed
   (command-s "_.dimlinear")							; run the command with as many user inputs as he needs
   (setvar 'clayer l)								; get currnt layer back
   (princ)))									; silence finish

 

 

 

0 Likes
Message 6 of 13

jostroopers
Collaborator
Collaborator

I have made a movie so you can see what iam doing.

https://www.screencast.com/t/eMgm3Ebf

 

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
0 Likes
Message 7 of 13

ВeekeeCZ
Consultant
Consultant
Accepted solution

Thanks. Now it's clear.

 

Original command is named DIMLINEAR. In PGP file you can create/change an ALIAS for that. But still you'll be calling the original command.

This original command is also used in RIBBON as part of a MENU-MACRO with some other expressions around (like ^C^C). So what you did in RIBBON was changing just surroundings expressions, not the original command itself.

To make it work that way you would need to UNDEFINE the original command and DEFINE a new-one by using LISP routine. It's not complicated, but t wouldn't recommend that because it's rather confusing. And also...

 

...since you're on 2020, why don't you simply set DIMLAYER?

 

 

BTW The term "Shortcut" in AutoCAD is used of function keys combinations only (eg. Crtl+I). 

 

0 Likes
Message 8 of 13

jostroopers
Collaborator
Collaborator

Strange, it works for you and in earlier versions it worked for me too.
Dimlayer is a good tip, but it's not for other commands such as Text or Mleader.
I will search further and I may use the lisp routine.
Thanks for your help.

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
0 Likes
Message 9 of 13

ВeekeeCZ
Consultant
Consultant

@jostroopers wrote:

Strange, it works for you and in earlier versions it worked for me too.
....


 

It worked for me as a "Shortcut", not as "Alias". You had to have some other tool for that. Older versions are no different in this behavior.

 

But speaking of LISP, you can try THIS Lee's routine.

0 Likes
Message 10 of 13

Kent1Cooper
Consultant
Consultant

@jostroopers wrote:

.... if I use the shortcut ….


 

What do you mean by "the shortcut"?

Kent Cooper, AIA
0 Likes
Message 11 of 13

jostroopers
Collaborator
Collaborator

It's not a shortcut but i mean the aliases i changed in the .pgp file.

D, *DIMLINEAR

For dimlinear it's the letter D. 

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
0 Likes
Message 12 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

@jostroopers wrote:

... i mean the aliases i changed in the .pgp file.

D, *DIMLINEAR .... 


 

That merely calls up the command, and has no relationship to your macro.  BUT in the case of Dimensions [and similarly with Hatch patterns], in new-enough versions of AutoCAD there's a DIMLAYER System Variable that you can set, and all new Dimensions will go on that Layer, regardless of the current Layer at the time, without changing the current Layer.  Set that [and in your drawing template files], and your D alias will result in Dimensions on that Layer, and you won't need your macro at all.

Kent Cooper, AIA
0 Likes
Message 13 of 13

jostroopers
Collaborator
Collaborator
Accepted solution

I now made a panel in the ribbon with the most used commands and changed the macro.

For the dim command i used DIMLAYER.

It now works fine fore me.

 

Thanks for the tips.

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
0 Likes