Author Topic: Macro - User Selects Object  (Read 1576 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Macro - User Selects Object
« on: May 19, 2015, 07:53:42 AM »
I am trying to write a simple macro that will reset the visretain on a selected xref and reload it. I know I can get away with it when I reload all (*). How can I get it to where the user would select an object. I know that the user can pick using the (\).

^C^Cvisretain;0;-xref;reload;(USER SELECTS);visretain;1;

Thank you
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Macro - User Selects Object
« Reply #1 on: May 19, 2015, 08:49:17 AM »
Look into ENTSEL then use ENTGET and retrieve CODE 2 with ASSOC.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Macro - User Selects Object
« Reply #2 on: May 20, 2015, 07:51:38 AM »
Thanks for sharing this. Here is the macro I am messing with below:

The Command I am using:

Code: [Select]
^C^Cvisretain;0;-xref;reload;(setq e (entsel "Please choose an object: "));visretain;1;

The Error I am getting:

Code: [Select]
Command: visretain
Enter new value for VISRETAIN <0>: 0
Command: -xref
Enter an option [?/Bind/Detach/Path/pathType/Unload/Reload/Overlay/Attach] <Attach>: reload
Enter xref name(s) to reload: (setq e (entsel "Please choose an object: "))
Please choose an object: visretain
*Invalid selection*
Expects a point or Last
Please choose an object: nil

Maybe I am not using this in the right sequencing or I need to add more?
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Macro - User Selects Object
« Reply #3 on: May 20, 2015, 09:50:50 AM »
Looks like the command line version is expecting a name of the xref to reload so it won't let you pick it in that sequence. Do you know what (ENTSEL) returns?

Here's a fish  ;)

Code - Auto/Visual Lisp: [Select]
  1. (defun c:vr (/ b)
  2.   (if (and (setq b (car (entsel "\nPick an XREF to reload: ")))
  3.            (= (cdr (assoc 0 (entget b))) "INSERT")
  4.                              (cdr (assoc 2 (entget b)))
  5.                    )
  6.            )
  7.            (minusp (vlax-get b 'isxref))
  8.       )
  9.     (progn (setvar 'visretain 0) (vla-reload b) (setvar 'visretain 1))
  10.   )
  11.   (princ)
  12. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Macro - User Selects Object
« Reply #4 on: May 20, 2015, 09:52:24 AM »
yup it returns this value

Code: [Select]
Please choose an object: visretain
*Invalid selection*
Expects a point or Last
Please choose an object: (<Entity name: 7ffffb9d880> (188827.0 1.73852e+006 0.0))
Civil3D 2020