Lisp command with select previous not working

Lisp command with select previous not working

Anonymous
Not applicable
1,683 Views
5 Replies
Message 1 of 6

Lisp command with select previous not working

Anonymous
Not applicable

Can anyone tell me how to make this small script work? It used to work when using pselect instead of select, but now I'm using AutoCAD 2017, and pselect can't be used anymore.

 

What I want to do is create a button that'll move a given object 150 units to the left. So I select a rectangle on my drawing and then press the button three times, then I want the rectangle to move 450 units to the left.

 

 

move;d;-150,0,0;select;p;;

 

Thanks in advance.

Accepted solutions (1)
1,684 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant
MOVE WHAT WHERE

move;p;;d;-150,0,0;
0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

What I want to do is create a button that'll move a given object 150 units to the left. So I select a rectangle on my drawing and then press the button three times, then I want the rectangle to move 450 units to the left.

....


Welcome to these Forums!

 

[That's not a Script, by the way -- "SCRIPT" has a specific and different meaning in AutoCAD.  It's a "command macro."  Nor is it a "Lisp command" as in the Subject line, but I can imagine that's a description of what you are assuming might be needed, not what you're starting with.]

 

You don't need PSELECT as a command anyway.  You can just select things ahead of time if you have PICKFIRST turned on.  In that situation, the problem with @ВeekeeCZ's suggestion is that if you give "P" as an option to a Move command that was called up with pre-selected objects, you are responding to the base-point-or-displacement prompt, for which P is not a valid option, and you get a "Point or option keyword required" error message, and it goes back to the prompt.

 

This works [in limited testing] if you start with a pre-selection and then hit the macro button multiple times [yes, even in a macro, in which some AutoLisp functions can be used -- I'll assume from the Subject line that you're not using Acad LT ]:

 

(if (ssget "_I") (command "_.move" "-150,0" "") (command "_.move" "_p" "" "-150,0" ""))

 

The (ssget "_I") is checking whether there's an Implied selection [your pre-selected object(s)], which will be true the first time you hit the button, so it will just give the displacement.  On subsequent picks, the pre-selection won't still be in effect, but the same thing(s) will be the "Previous" selection, so it will use that.

 

If there is no pre-selection when you first pick the macro button, it will of course Move whatever qualifies as "Previous" [if anything], as will BeekeeCZ's suggestion, so it does need you to pick things before the first use.

Kent Cooper, AIA
0 Likes
Message 4 of 6

ВeekeeCZ
Consultant
Consultant

Erased by the user. Bad day.

0 Likes
Message 5 of 6

Anonymous
Not applicable

Hi,

 

Thanks a lot! However, I can't get it to work. I'm surely doing something wrong. I went into CUI, then toolbar, and then opened the properties for the button I've created for this script. I tried copy-pasting the script into the "macro" line in the properties window. That didn't have any effect when I pressed the button. It's like the script doesn't launch.

 

Then I read somewhere that to use a script like this, I should first insert ^C^C$M=$, so I tried that:

 

^C^C$M=$(if (ssget "_I" (command "_.move" "-150,0" "") (command "_.move" "_p" "" "-150,0" ""))

But that didn't work either, when I pre-select the rectangle I want to move and then press the button I've created, it just displays these messages:

 

Command: $M=(ssget Unknown command "$M=(SSGET".  Press F1 for help.
Command: "_I" Unknown command ""_I"".  Press F1 for help.
Command: (command "_.move" "-150,0" "") _.move
Select objects: -150,0 0 found
Select objects:
Command: nil

 

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... I can't get it to work. I'm surely doing something wrong. ....

 

^C^C$M=$(if (ssget "_I" (command "_.move" "-150,0" "") (command "_.move" "_p" "" "-150,0" ""))

.... 


I don't know about the ^C^C$M=$ part [I suspect the ^C^C double-cancel will undo any pre-selection].  But you somehow missed the right parenthesis after "_I").

Kent Cooper, AIA