Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Contributor
BlueVue
Posts: 26
Registered: ‎04-16-2012
Message 1 of 5 (398 Views)
Accepted Solution

Using $ and * special characters in a Custom Command

398 Views, 4 Replies
05-04-2012 05:15 PM

I'm trying to write a simple Custom Command that sets any layer that matches "$-*" to a specific color. But as soon as AutoCAD sees the $, it thinks I'm trying to do a DIESEL expression. Supposedly, the quote marks specify that the enclosed characters should be treated as plain text, but that doesn't happen.

 

Here's what I've got:

^C^C-LAYER;C;252;"$-*";;

 

And this is what I get:

Command: -LAYER

Current layer:  "$-HATCH-00-002-PW-BOAT"
Enter an option 
[?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck
/Unlock/stAte/Description/rEconcile]: C

New color [Truecolor/COlorbook] : 252

Enter name list of layer(s) for color 252 <$-HATCH-00-002-PW-BOAT>: "

No matching layer names found.
Enter an option 
[?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck
/Unlock/stAte/Description/rEconcile]:

It stops, hanging at the incompleted -LAYER command prompt. 

 

Can anyone tell me what I'm missing?? Thanks!

================================
Vanilla AutoCAD 2010

Hi,

 

you are right it seems that is' s not possible with menu macro but with AutoLISP it is

replace your macro with this:

 

^C^C(if (null c:setGrayColor) (load "setGrayColor")) setGrayColor

 

create a lisp file and name it setGrayColor.lsp and put it on one of your support file search path

copy and paste this:

 

(defun c:setGrayColor ()
 (command "-layer" "c" 252 "$-*" "")
)

 

close and save the file

 

Cheers,

Moshe

 

Try

 

^C^C-LAYER;C;252;(strcat (CHR 36) "-*");;

 

Cheers,

Henrique

Distinguished Mentor
Moshe-A
Posts: 827
Registered: ‎09-14-2003
Message 2 of 5 (383 Views)

Re: Using $ and * special characters in a Custom Command

05-05-2012 07:41 AM in reply to: BlueVue

Hi,

 

you are right it seems that is' s not possible with menu macro but with AutoLISP it is

replace your macro with this:

 

^C^C(if (null c:setGrayColor) (load "setGrayColor")) setGrayColor

 

create a lisp file and name it setGrayColor.lsp and put it on one of your support file search path

copy and paste this:

 

(defun c:setGrayColor ()
 (command "-layer" "c" 252 "$-*" "")
)

 

close and save the file

 

Cheers,

Moshe

 

*Expert Elite*
hmsilva
Posts: 3,342
Registered: ‎12-17-2004
Message 3 of 5 (360 Views)

Re: Using $ and * special characters in a Custom Command

05-07-2012 04:22 AM in reply to: BlueVue
Try

 

^C^C-LAYER;C;252;(strcat (CHR 36) "-*");;

 

Cheers,

Henrique

Active Contributor
BlueVue
Posts: 26
Registered: ‎04-16-2012
Message 4 of 5 (342 Views)

Re: Using $ and * special characters in a Custom Command

05-07-2012 10:16 AM in reply to: hmsilva

Thanks guys!!

Both solutions work, though I'm going to use Henrique's, as it will be easier to deploy to other users here.

(Sorry Moshe, your solution is good too!)

 

Henrique, I'm assuming the "CHR" allows you to specify any ASCII character? (36=$)

 

Cheers!

================================
Vanilla AutoCAD 2010
*Expert Elite*
hmsilva
Posts: 3,342
Registered: ‎12-17-2004
Message 5 of 5 (333 Views)

Re: Using $ and * special characters in a Custom Command

05-07-2012 12:38 PM in reply to: BlueVue

Yes, you are assuming correctly, "chr" allows you to specify any ASCII character,
and if you do not know the specific ASCII character, just type

(ASCII "$")

and returns
36

Glad to help you.

 

Henrique

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.