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

Moving objects in AutoCAD is risky!

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
JamaL9722060
1150 Views, 16 Replies

Moving objects in AutoCAD is risky!

 

Moving objects in AutoCAD is risky!

 

It happens very frequently that I move particular drawing when other objects are:

 

  1. Turned off
  2. Frozen
  3. Locked
  4. Annotative visibility is off

 

And then as these features are ON I found out what catastrophe I made!

 

I’m not sure if there is a lisp file that can turn ON all these features such that one can apply it before moving any objects

 

Clip_310.jpg

 

 

Thank you

 

Best

 

Jamal

---------------------------
Jamal Numan
16 REPLIES 16
Message 2 of 17
pbejse
in reply to: JamaL9722060


@JamaL9722060 wrote:

 

Moving objects in AutoCAD is risky!

 

It happens very frequently that I move particular drawing when other objects are:

 

  1. Turned off
  2. Frozen
  3. Locked
  4. Annotative visibility is off

 

And then as these features are ON I found out what catastrophe I made!

 

Thank you

 

Best

 

Jamal


 

Try this reactor

 

(vl-load-com)
(if _moveR (vlr-remove _moveR))
(if _moveA (vlr-remove _moveA))

(setq _moveA (vlr-command-reactor nil '((:vlr-commandWillStart . StartMove_))))
(setq _moveR (vlr-command-reactor nil '((:vlr-commandended . Reset_))))
(defun StartMove_ (calling-reactor endcommandInfo / thecommandstart)
  (setq thecommandStart (nth 0 endcommandInfo))
  (if (= thecommandStart "MOVE")
    (_LayerAnnotativeState)
  )
)
(defun Reset_ (calling-reactor endcommandInfo / thecommandEnd)
  (setq thecommandEnd (nth 0 endcommandInfo))
  (if (= thecommandEnd "MOVE")
    (_LayerAnnotativeStateR)
  )
)
(Defun _force (e l1 l2 / v)
  (mapcar (function (lambda (j k) (setq v (vlax-get e j)) (vlax-put e j k) v)) l1 l2)
)
(defun _LayerAnnotativeState (/ aDoc Layers)
  (setq aDoc   (vla-get-ActiveDocument (vlax-get-acad-object))
        Layers (vla-get-layers aDoc)
        p      nil
        cl     (getvar 'clayer)
        AV     (getvar 'annoallvisible)
  )
  (setvar "ANNOALLVISIBLE" 1)
  (vlax-for l Layers
    (setq curv (if (eq (vla-get-name l) cl)
                 (_force l '("LayerOn" "Lock") '(-1 0))
                 (_force l '("Freeze" "LayerOn" "Lock") '(0 -1 0))
               )
    )
    (setq p (cons (list (vla-get-name l) curv) p))
  )
  (vla-regen aDoc acActiveViewport)
)

(defun _LayerAnnotativeStateR (/ aDoc Layers prop aDoc Layers)
  (setq aDoc   (vla-get-ActiveDocument (vlax-get-acad-object))
        Layers (vla-get-layers aDoc)
        prop   '("Freeze" "LayerOn" "Lock")
  )
  (foreach itm p
    (_force (vla-item Layers (Car itm))
            (if (= (length (Cadr itm)) 2)
              (cdr prop)
              prop
            )
            (cadr itm)
    )
  )
  (setvar "ANNOALLVISIBLE" AV)
  (vla-regen aDoc acActiveViewport)
)

 

Save this as Move_reactor and load it on youir startup suite/acaddoc.lsp

 

HTH

 

 

 

Message 3 of 17
JamaL9722060
in reply to: pbejse

Many thanks pbejse for the prompt effort,

 

The lisp file is loaded (and the AutoCAD is restarted) but the command doesn’t come up

 Clip_320.jpg

 

 

Clip_322.jpg

 

What might be the issue? how should i run it?

 

Best

 

Jamal

---------------------------
Jamal Numan
Message 4 of 17
pbejse
in reply to: JamaL9722060


@JamaL9722060 wrote:

Many thanks pbejse for the prompt effort,

 

The lisp file is loaded (and the AutoCAD is restarted) but the command doesn’t come up

 

What might be the issue? how should i run it?

 

Best

 

Jamal


My bad Jamall, I edited my post after you copy the code

 

Copy the code again and overwrite your previous file.

 

Try it and tell me what you think

 

Message 5 of 17
JamaL9722060
in reply to: pbejse

That’s fantastic! you are really a star.

 

 

Could this command be stand alone? To turn ON/unlock/visible/thaw everything but not necessarily associated with the move command. This is quite important, for example, when using the “export” command. We need to make sure that everything is ON.

 

Best

 

Jamal

---------------------------
Jamal Numan
Message 6 of 17
Kent1Cooper
in reply to: JamaL9722060

@JamaL9722060 wrote:

.... 

It happens very frequently that I move particular drawing when other objects are:

 

  1. Turned off
  2. Frozen
  3. Locked
  4. Annotative visibility is off

.... 

I’m not sure if there is a lisp file that can turn ON all these features such that one can apply it before moving any objects

....


Be conscious of the riskiness of unlocking Layers -- usually they are locked for a reason, so you need to be careful about overriding that.

 

There's one quirk I haven't figured out, but if there's a solution to that, or if you can live with that, the much simpler way to go about this is to Redefine the Move command.

 

;;  MoveAllOn.lsp [command name: MOVE (undefined & redefined)]
;;  Move command redefined to thaw, unlock and turn on all Layers, so
;;    that nothing is unwittingly left un-Moved that should be Moved.
;;  Kent Cooper, 6 March 2013

;;  To preserve AutoCAD's Move command definition, remove the following lines:
(setq cmde (getvar 'cmdecho))
(setvar 'cmdecho 0)
(command "_.undefine" "MOVE")
(setvar 'cmdecho cmde)
(setq cmde nil)
;;  and redefine Move if necessary, change prompt at end of file, and substitute
;;  different command name at top and bottom of file and in the following line:

(defun C:MOVE (/ cmde)
  (setq cmde (getvar 'cmdecho))
  (setvar 'cmdecho 0); so Layer stuff doesn't scroll by
  (command
    "_.layer"
      "_stAte" "_save" "MoveRedef" "" ""
      "_thaw" "*" "_unlock" "*" "_on" "*"
;;;;; add appropriate option for annotative visibility ;;;;;
"" ; close Layer "_.regen" ; [for things on frozen Layers] ); command (setvar 'cmdecho cmde) (command "_.move") ; invoke native AutoCAD command (while (> (getvar 'cmdactive) 0) (command pause))   (setvar 'cmdecho 0)   (command "_.layer" "_stAte" "_restore" "MoveRedef" "_delete" "MoveRedef" "" "")   (setvar 'cmdecho cmde) (princ) ); defun - MOVE (prompt "\nThe MOVE command has been redefined to make everything visible/movable.")

[I have an old-enough version that I don't have annotative visibility, so those who do will need to account for that.]

 

Save that to a MoveAllOn.lsp file in some location in the Support File Search Path list, and put this line:

 

(load "MoveAllOn")

 

into your acaddoc.lsp, to have it loaded in every drawing.

 

The quirk is that when I use it, object selection doesn't automatically go into Window/Crossing mode if I pick in an empty area.  Maybe there's some setting I have wrong, but it still works right in other commands.  And I can still explicitly call for the W or C option.

 

I haven't worked with Reactors, but would I be right in saying that a Reactor-based approach would do the Layer changes no matter how you call up Move, i.e. that you wouldn't be able to Move things without triggering those changes?  The redefining approach means that if you sometimes want to use Move without making the Layer changes, you can simply type in .MOVE [or just .M], with the period prefix, to get the native command.

Kent Cooper, AIA
Message 7 of 17
Kent1Cooper
in reply to: JamaL9722060


@JamaL9722060 wrote:

.... 

Could this command be stand alone? To turn ON/unlock/visible/thaw everything but not necessarily associated with the move command. This is quite important, for example, when using the “export” command. We need to make sure that everything is ON.

....


Here's what I use:

 

;;;  LayerAllAll.lsp
;;;  To Thaw, Unlock and turn On All Layers, and Regenerate
(defun C:LAA ()
  (command "_.layer" "_thaw" "*" "_unlock" "*" "_on" "*" "" "_.regen")
  (princ)
)

[Again, add whatever is appropriate about annotative visibility, if you need to.]

 

In this case, I have a different line in acaddoc.lsp:

 

(autoload "LayerAllAll" '("LAA"))

 

which means it doesn't load the function unless and until the command name is called for.

Kent Cooper, AIA
Message 8 of 17
pbejse
in reply to: Kent1Cooper


@Kent1Cooper wrote:
Be conscious of the riskiness of unlocking Layers -- usually they are locked for a reason, so you need to be careful about overriding that.

 


In most cases i agree with that thinking, From time to time i "bend the rule" , such as this case wherein the OP specifically ask to unlock the layers.

 


@Kent1Cooper wrote:
 the much simpler way to go about this is to Redefine the Move command.

 



That woul've been my next suggestion. 


@Kent1Cooper wrote:
I haven't worked with Reactors, but would I be right in saying that a Reactor-based approach would do the Layer changes no matter how you call up Move?


Yes, no matter how you call it. Like undefining the command, you can also disable a reactor. thru typing a command or a toolbar

 


@Kent1Cooper wrote:
.....  (command "_.layer" "_stAte" "_restore" "MoveRedef" "_delete" "MoveRedef" "" "")

 



Why not Layerp?

 

pBe

 

Message 9 of 17
pbejse
in reply to: JamaL9722060


@JamaL9722060 wrote:

That’s fantastic! you are really a star.

  

Could this command be stand alone? To turn ON/unlock/visible/thaw everything but not necessarily associated with the move command. This is quite important, for example, when using the “export” command. We need to make sure that everything is ON.

 

Best

 

Jamal


You are welcome Jamal 🙂

 

Yes , Kent already provided you a code for that. then use Layerp button to restore the previous state. (or Layer state if you're more comfortable with that)

 

Also you can easily add "Export" on the reactor code and any other commands if you need to 🙂

 

 

Message 10 of 17
Kent1Cooper
in reply to: pbejse


@pbejse wrote:
.... 
@Kent1Cooper wrote:
.....  (command "_.layer" "_stAte" "_restore" "MoveRedef" "_delete" "MoveRedef" "" "")

Why not Layerp?

.... 


Well, yes -- I don't know why that didn't occur to me.  When I saw your suggestion, I did wonder whether it would only revert the last Layer option used, but it does revert the entire last Layer command.  That eliminates the need to deal with Layer States, and reduces the redefinition part to this:

 

(defun C:MOVE (/ cmde)
  (setq cmde (getvar 'cmdecho))
  (setvar 'cmdecho 0); so Layer stuff doesn't scroll by
  (command

    "_.layer" "_thaw" "*" "_unlock" "*" "_on" "*" ""
;;;;; add appropriate option for annotative visibility ;;;;;
    "_.regen" ; [for things on frozen Layers]
  ); command
  (setvar 'cmdecho cmde)
  (command "_.move") ; invoke native AutoCAD command
  (while (> (getvar 'cmdactive) 0) (command pause))
  (setvar 'cmdecho 0)
  (command "_.layerp")
  (setvar 'cmdecho cmde)
  (princ)
); defun - MOVE

Kent Cooper, AIA
Message 11 of 17
JamaL9722060
in reply to: Kent1Cooper

 

Thank you guys for the help. Very much appreciated.

 

 

The “stand alone” lisp works fine but it misses to turn ON all the annotation scales.

 How this might be included in the code?

 

Clip_330.jpg

 

 

Best

 

Jamal

---------------------------
Jamal Numan
Message 12 of 17
Kent1Cooper
in reply to: JamaL9722060


@JamaL9722060 wrote:

.... 

The “stand alone” lisp works fine but it misses to turn ON all the annotation scales.

 How this might be included in the code?

....


As I said, I don't have a new-enough version to have annotative visibility, so I can't answer that definitively.  If that's an option within the Layer command, add the appropriate entries into the (command) function.  Type -LA [with the hyphen prefix] to get the command-line version of Layer rather than using the Layer Manager, follow the prompts, and keep track of what the option and the choices within it are.  Use "*" after an option designator in the (command) function, as done with the other options already there, to apply an option to all Layers.  If annotative visibility is controlled by something other than the Layer command, you will need to add something else to take care of it.

Kent Cooper, AIA
Message 13 of 17
JamaL9722060
in reply to: pbejse

Could you please pbejse help in sticking the bunch of code that make all the annotative objects ON.

 

Clip_335.jpg

 

Thank you

 

Best

 

Jamal

---------------------------
Jamal Numan
Message 14 of 17
Kent1Cooper
in reply to: JamaL9722060

It looks [judging from the screen shot] as though you could just add a line:

 

....

  (command "_.vplayer" "_thaw" "*" "" "")

  (setvar 'annoallvisible 1)

  (princ)

)

Kent Cooper, AIA
Message 15 of 17
JamaL9722060
in reply to: Kent1Cooper

 

Very much appreciated. It works fine

 

 

Clip_338.jpg

 

All the best

 

Jamal

---------------------------
Jamal Numan
Message 16 of 17
Kent1Cooper
in reply to: JamaL9722060


@JamaL9722060 wrote:

 

Very much appreciated. It works fine

....


That's good -- it's always a relief to find that a guess that I can't test myself turned out to be right!

Kent Cooper, AIA
Message 17 of 17
JamaL9722060
in reply to: Kent1Cooper

This is a guess of an expert not a regular one! This is why it should be correct!

 

Thanks

 

Jamal

---------------------------
Jamal Numan

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

Post to forums  

Autodesk Design & Make Report

”Boost