AutoLISP: ChangeSpace with Copy

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)

)
Advertisement

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, Modifying. Bookmark the permalink.

3 Responses to AutoLISP: ChangeSpace with Copy

  1. 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)
    )

  2. 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)
    )

  3. Pingback: Quantum entanglement of sorts – lisp365

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s