I really like this simple routine. It shows the power of AutoLISP. You can take an existing command in AutoCAD (CHSPACE in this example) and add an option.
The CHSPACE command (CHange SPACE) allows you to move objects from a paper space viewport to model space or from model space to paper space. It moves these objects and keeps their scaling proportional to the viewport scale. The command is limited to moving objects. That’s where this routine comes in handy. With this routine, you now have an easy way to copy objects through viewports in the same manner as the CHSPACE command moves objects.
Here’s how:
- CHSPACECOPY <enter> to start
- Select objects to copy to model space or paper space (depending on your current “space”)
hit <enter> to execute and finish
~enjoy
Shown below: Copying objects from model space to paper space.
Shown below: Copying objects from paper space to model space.
(defun c:CHSpaceCopy (/ ss2 ss i) (vl-load-com) (if (setq ss2 (ssadd) ss (ssget "_:L") ) (progn (repeat (setq i (sslength ss)) (ssadd (vlax-vla-object->ename (vla-copy (vlax-ename->vla-object (ssname ss (setq i (1- i)))))) ss2 ) ) (vl-cmdf "_.chspace" ss2 "") ) ) (princ) )
Very nice! I made a slight mod to make copy an option. (Note: I’m using the DOSLib utility for the prompt: http://www.en.na.mcneel.com/doslib.htm.)
(defun c:CHSpaceCopy (/ ss2 ss i)
(vl-load-com)
(if (setq ss2 (ssadd)
ss (ssget “_:L”)
)
(progn
(if (= 1 (dos_msgboxex “Do you want CHSpace to \”copy\” or \”move\” the selected objects?” “CHSpace” ‘(“Move objects” “Copy objects”) 4))
(repeat (setq i (sslength ss))
(ssadd
(vlax-vla-object->ename (vla-copy (vlax-ename->vla-object (ssname ss (setq i (1- i))))))
ss2
)
)
)
(vl-cmdf “_.chspace” ss2 “”)
)
)
(princ)
)
Minor tweak:
(defun c:CHSpaceCopy (/ ss2 ss i)
(vl-load-com)
(if (setq ss2 (ssadd)
ss (ssget “_:L”)
)
(progn
(if (= 1 (dos_msgboxex “Do you want CHSpace to \”copy\” or \”move\” the selected objects?” “CHSpace” ‘(“Move objects” “Copy objects”) 4))
(repeat (setq i (sslength ss))
(ssadd
(vlax-vla-object->ename (vla-copy (vlax-ename->vla-object (ssname ss (setq i (1- i))))))
ss2
)
)
(setq ss2 ss)
)
(vl-cmdf “_.chspace” ss2 “”)
)
)
(princ)
)
Pingback: Quantum entanglement of sorts – lisp365