Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Macro- pick object first or run command first

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
m_rogoff
1948 Views, 8 Replies

Macro- pick object first or run command first

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

8 REPLIES 8
Message 2 of 9
hmsilva
in reply to: m_rogoff

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

EESignature

Message 3 of 9
m_rogoff
in reply to: hmsilva

^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,

Message 4 of 9
Kent1Cooper
in reply to: m_rogoff

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 Cooper, AIA
Message 5 of 9
m_rogoff
in reply to: Kent1Cooper

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

Message 6 of 9
Kent1Cooper
in reply to: m_rogoff

[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.

Kent Cooper, AIA
Message 7 of 9
hmsilva
in reply to: m_rogoff


@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

 

 

EESignature

Message 8 of 9
JBerns
in reply to: Kent1Cooper

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

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 9 of 9
JBerns
in reply to: JBerns

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

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost