How can I write a macro to have a user option to either select the object first then run the macro, or run the macro then pick the object.
I would like to combine this all into one macro.
Thanks
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Hi m_rogoff,
may you be a little bit more specific.
By 'macro' do you mean a menu macro?
And when you say 'or run the macro then pick the object.' what will the macro do before selecting the object?
Can you explain to us what's the code final goal.
Henrique
^C^C_.select;\_.chprop;p;;p;LA;S-3;c;BYLAYER;lw;BYLAYER;;
This macro will change the layer of an object to S-3. The way it's written, you run the macro then select the object. I would like the option to select the object first and then run the macro. Ideally, this is all in one macro if possible. Thanks,
As an equivalent to your macro [it's not one, but you could have a macro invoke it], you could use a check for whether there's anything pre-selected with (ssget "_I"), something like this [minimally tested]:
(defun C:CLS3 (); = Change to Layer S-3
(command
"_.chprop"
(cond
((ssget "_I")); something(s) already selected
((ssget)); nothing yet -- ask User to
); cond
""
"_layer" "S-3" "_color" "bylayer" "_lweight" "bylayer" ""
); command
); defun
With that loaded, then a macro in a menu item could contain:
^C^CCLS3
One nice thing about doing it this way is that the User has the option of either picking the macro or typing the command name if that's easier than navigating to find the macro [toward which end you might want to come up with some kind of two-letter or all-left-hand command name].
Kent, this is perfect. However, half of my company uses LT. If I can get this in macro too that would be great!
Your help is appreciated
[It's not as perfect as I intended -- the macro menu item calling it should not contain the starting ^C^C, which would un-select any pre-selected object(s).]
I'm not sure it's possible to do that in no-AutoLISP macro form. Macros can contain Lisp expressions, but those still won't be usable in LT. And I don't know of a way to go one way under one circumstance and another way under another circumstance, except with Lisp (if) or (cond) functions. The only thing I can suggest is to try your original without the ^C^C at the beginning [I haven't tried it], and see whether any pre-selection holds into the Select command, with that User-input backslash requiring only an Enter to complete the selection. It would still require that Enter, unlike the Lisp routine, but it should at least let you start with a pre-selection in place before you run the macro.
@m_rogoff wrote:
However, half of my company uses LT. If I can get this in macro too that would be great!
Hi m_rogoff,
have been a long time I don't write 'macros' (many years), but what I thought it would be a way, has resulted in a nonfunctional macro, it was:
- run the select command
- test the sysvsr LASTPROMPT
- do different actions as a result of lastprompt test...
Would be anything like this:
NONFUNCTIONAL MACRO (just to expose my idea)
^C^C_.select;$M=$(if,$(=,$(getvar,lastprompt),Select objects:),_.select;\_.chprop;p;;p;LA;S3;c;BYLAYER;lw;BYLAYER;;,_.chprop;p;;p;LA;S-3;c;BYLAYER;lw;BYLAYER;;)
Maybe someone who write more macros than me, could write this macro in the correct way... Just a thought...
Henrique
Kent,
Thanks for this post. I tried the code in AutoCAD 2019, but errors occur if objects are pre-selected (Implied). It works well without objects pre-selected.
Any thoughts what system variables might be causing it to fail? Current values follow, but I have tried different settings with same results - command fails if objects pre-selected.
PICKFIRST=1
PICKADD=2
I look forward to your reply.
Regards,
Jerry
After more experimenting, I was able to get this code to work, but it is not as efficient as I had hoped.
(defun C:CLS3 () ;; Change to Layer S-3
(cond
((ssget "_I") (command "_.chprop" "_layer" "S-3" "_color" "bylayer" "_lweight" "bylayer" "")) ;; implied objects
(T (command "_.chprop" (ssget) "" "_layer" "S-3" "_color" "bylayer" "_lweight" "bylayer" "")) ;; none implied
) ;_cond
) ;_defun
I added extra spaces for easy comparison purposes.
I welcome any feedback to improve efficiency.
Regards,
Jerry
Can't find what you're looking for? Ask the community or share your knowledge.