Lisp without user input during command

Lisp without user input during command

BriannaWong98
Participant Participant
1,962 Views
13 Replies
Message 1 of 14

Lisp without user input during command

BriannaWong98
Participant
Participant

Hi all,

 

I have an existing lisp where currently theres shorthand commands to change previous selection to a different layer. However, there's no way to simply highlight and change it. Currently I have to highlight, use select command, then use change command to change layers.

 

Despite all my fuddling, there seems to be no way to code lisp so it simply makes my highlight the selection then changes it. It clears my selection when Select command runs, then errors because it wants me to select before moving onto Change command. How can I make it so whatever I highlight becomes the selection, then have Change command change the layer of the selection?

 

 

Current Code (Shorthand substitutes have been fully typed out instead):

 

(Defun C:SEC9 ()                [this example is for changing to layer named "9"]
(COMMAND "SELECT" "")

(Command "CHANGE" "P" "" "P" "LA" "9" "")

)

0 Likes
Accepted solutions (1)
1,963 Views
13 Replies
  • Lisp
Replies (13)
Message 2 of 14

john.uhden
Mentor
Mentor

 

 

(Defun C:C9 ( / ss)
  (and
    (setq ss (ssget "P"))
    (vl-cmdf "_.CHANGE" ss "" "P" "LA" "9" "")
  )
)

 

Of course that doesn't keep you from having to type in "C9", but once I complete my psychic interface app things will be easier on the fingers.  🙂

Which reminds me of a comic act I saw on TV...

"All those who believe in telekinesis, please raise my hand."

 

John F. Uhden

0 Likes
Message 3 of 14

BriannaWong98
Participant
Participant

Hi John, 

That code does what mine already does. I have to highlight something, then do some sort of command or use SELECT command to make it previous, and only then does it the change command do something to it.

 

I'm looking for a way to highlight something, then have the program successfully use the change command somehow, without me doing anything. I hope I'm making sense 

0 Likes
Message 4 of 14

Sea-Haven
Mentor
Mentor

If you select object/s then chprop P the p implies previous/current selection set, so a simple mod of Johns code.

 

(command "chprop" "P" "c" 1 "")

0 Likes
Message 5 of 14

Kent1Cooper
Consultant
Consultant
Accepted solution

The (ssget) function has an "_I" mode for Implied selection, that is, pre-selected object(s):

 

(defun C:SEC9 ()
  (command "_.chprop"

    (cond

      ((ssget "_I")); there's a pre-selection -- use it

      ((ssget)); otherwise, ask User for selection

    ); cond

    "" "_layer" "9" ""

  ); command
  (princ)
)

Kent Cooper, AIA
Message 6 of 14

Kent1Cooper
Consultant
Consultant

@Sea-Haven wrote:

....the p implies previous/current selection set....

(command "chprop" "P" "c" 1 "")


For me [Acad2019] that does not work.  It uses the previous selection for whatever I did before, not the current selection.  And if you invoke it without any pre-selection, of course it does the same -- you don't get to select things.

Kent Cooper, AIA
0 Likes
Message 7 of 14

john.uhden
Mentor
Mentor
Well, until I build the psychic interface you're going to have to do
SOMETHING.
The key here is that once you've gripped the objects they become the
previous selection set without having to use the SELECT command, that is if
PICKFIRST is set to 1 (which is stored in the registry not the drawing).

John F. Uhden

0 Likes
Message 8 of 14

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:
.... once you've gripped the objects they become the previous selection set ....

I repeat, not for me [see my previous Reply].  To elaborate:  I defined a command modeled after by @Sea-Haven 's suggestion:

 

(defun C:L9 () (command "_.chprop" "_previous" "" "_layer" "9" ""))

 

[including completing the selection, which wasn't in theirs].  I MOVEd a couple of things to make them the Previous selection.  I then Pick-first-pre-selected some different things, and with them selected/highlighted/gripped, called that L9 command.  Those different things were not the ones changed to Layer 9, but rather the earlier couple of things.  Pre-selected objects do not become the Previous selection.  [And yes, my PICKFIRST & PICKADD settings are appropriate.]

Kent Cooper, AIA
0 Likes
Message 9 of 14

john.uhden
Mentor
Mentor
I screwed up. It's Implied, not Previous...
(setq ss (ssget "I"))

John F. Uhden

0 Likes
Message 10 of 14

Sea-Haven
Mentor
Mentor

Thanks Kent had a play unless you use "select" to pick objects it will change the previous selection not the new one that you want to use, like others I would be more inclined to use a ssget method.

 

There really is not much difference enter command pick objects for me that is my habit of changing stuff.

0 Likes
Message 11 of 14

BriannaWong98
Participant
Participant

Sorry to revive this so soon, but is there any way to macro this? The ability to push a button and have it auto select what's highlighted and change it to layer x is invaluable to me

0 Likes
Message 12 of 14

john.uhden
Mentor
Mentor
My psychic interface will be ready in about 15 years, if I'm still around.

John F. Uhden

0 Likes
Message 13 of 14

BriannaWong98
Participant
Participant

Nevermind, I just discovered the -LAYMCH command which is everything I need    ^u^

0 Likes
Message 14 of 14

Kent1Cooper
Consultant
Consultant

Though you may not need it any more, there is a way to macro [macro-ize? macrify?] it.  If you set it up to ensure a command like SEC9 at Message 5 is loaded in every drawing, you can put into a button a macro that contains merely:

 

SEC9

Kent Cooper, AIA
0 Likes