CHSPACE

Does anyone know of a way to replicate the CHSPACE command in Bricscad?  This command moves items from paperspace to floating model space (in the same location) and applies the correct scale factor based on the target viewport scale.  I am handy with LISP but do not feel I can write code for this.  Thanks! 

Comments

  • Woody, I do that all the time, but I do it manually -- except that I have a lisp routine that (among other things) changes the dimscale of any leaders or dimensions, and I run that first. Then I make a temporary block of all the stuff to be moved, snapping on a point in the viewport to define the insertion point of the block. Finally, I go into the viewport and insert the block there at the appropriate scale and then explode it.

    I don't think it would be hard to automate the latter part, using the inverse of the viewport's scale (activeX property CustomScale) as the insertion scale factor of the block as well as the dimscale for the dimensions and leaders, and the center of the viewport (DXF code 10 and 12 for the paperspace and modelspace coordinates) as the insertion point of the block. The user could just select the viewport and the objects to be moved into it, and the lisp function would do all the rest.

    If you'd like, we can work on it together at <a href="http://www.theswamp.org/index.php?board=2.0">The Swamp</a>. The Swamp is more convenient for posting code. I can get it started with code I already have for the dimscale part. Better lisp programmers will probably help out. If you're interested, reply and I'll start a thread at The Swamp and link to it from here.

  • Ah, there's a new link-maker since last time I posted a link, and my old method doesn't work any more. Let's see if I can get the new method to work: The Swamp.

    A shame you can't edit posts. I think The Swamp does allow it.

  • Here's something I found

    (I forget who made it, does somebody recognize it? the auther deserves recognition and thanks)

    It works very well, m2p and c2p moves or copies to paperspace, respectively,

    and m2m amd c2m does the same to modelspace into a viewport.

  • oof, here's the lisp:

    (defun c:c2p () 
    (to-paperspace 1)
    )
    (defun c:m2p ()
    (to-paperspace 0)
    )
    (defun to-paperspace (val / exprt omode cecho cvprt trig ss msctr ssv en ed nm
    rt
    sz vd psctr dcl_id x y what_next temp cntr message
    )
    (setq exprt nil
    omode nil
    cvprt nil
    trig nil
    ss nil
    msctr nil
    ssv nil
    en nil
    ed nil
    nm nil
    rt nil
    sz nil
    vd nil
    psctr nil
    dcl_id nil
    x nil
    y nil
    what_next nil
    temp nil
    cntr nil
    message nil)
    (setq cecho (getvar "cmdecho")
    exprt (getvar "expert")
    omode (getvar "osmode")
    cvprt (getvar "cvport"))
    (setvar "cmdecho" 0)
    (setvar "expert" 2)
    (setvar "osmode" 0)
    (command "undo" "begin")
    (defun dtr (d)
    (/ (* d pi) 180.0)
    )
    (defun rtd (r)
    (/ (* r 180.0) pi)
    )
    (if (= (getvar "tilemode") 1)
    (princ "\n \n \n** Command not allowed unless TILEMODE is set to 0 **")
    (if (= (length (vports)) 1)
    (princ "\n \n \n \nThere are no active Model space viewports.")
    (progn
    (setq err *ERROR*)
    (defun *ERROR* (st)
    (cond
    ((or (= st "Function cancelled") (= st "console break")))
    )
    (sp2sp_reset)
    )
    (command "mspace")
    (if (= val 1)
    (princ "\n \nSelect objects to copy: \n ")
    (princ "\n \nSelect objects to move: \n ")
    )
    (setq SS (ssget))
    (command "pspace")
    (setq pspace_ucs_name (getvar "ucsname"))
    (command "ucs" "world")
    (setq SSV (ssget "x" (list (cons 0 "VIEWPORT"))))
    (if (/= SS nil)
    (progn
    (if (= val 1)
    (princ
    "\n \nCopy to Paper space in progress. \n \nPlease wait..."
    )
    (princ
    "\n \nMove to Paper space in progress. \n \nPlease wait..."
    )
    )
    (while (= trig nil)
    (setq EN (ssname SSV 0))
    (setq ED (entget EN '("ACAD")))
    (setq NM (cadr (assoc '-3 ED)))
    (setq SZ (rtos (/ (cdr (assoc'41 ED)) (cdr (nth 7 NM))) 2 6))
    (if (= (cdr (assoc '68 ED)) 2)
    (setq trig 1)
    )
    (ssdel EN SSV)
    )
    (setq psctr (cdr (assoc'10 ED)))
    (command "mspace")
    (setq mspace_ucs_name (getvar "ucsname"))
    (command "ucs" "view")
    (setq msctr (getvar "viewctr"))
    (setvar "highlight" 0)
    (if (= val 1)
    (command "block" "to-paperspace" msctr ss "" "oops")
    (command "block" "to-paperspace" msctr ss "")
    )
    (if (= mspace_ucs_name "")
    (command "ucs" "world")
    (command "ucs" "r" mspace_ucs_name)
    )
    (command "pspace")
    (command "insert" "*to-paperspace" psctr SZ "0")
    (if (= pspace_ucs_name "")
    (command "ucs" "world")
    (command "ucs" "r" pspace_ucs_name)
    )
    (princ "\n \n \n ")
    (princ "\n \n \nDONE... ")
    )
    (progn
    (princ "\n \n \n")
    (alert "Your selection set was empty!")
    )
    )
    (if (= cvprt 1)
    (command "pspace")
    (command "mspace")
    )
    )
    )
    )
    (setvar "expert" exprt)
    (setvar "cmdecho" cecho)
    (setvar "osmode" omode)
    (setvar "highlight" 1)
    (setq exprt nil
    omode nil
    cvprt nil
    trig nil
    ss nil
    msctr nil
    ssv nil
    en nil
    ed nil
    nm nil
    rt nil
    sz nil
    vd nil
    psctr nil
    dcl_id nil
    x nil
    y nil
    what_next nil
    temp nil
    cntr nil
    message nil)
    (command "undo" "end")
    (princ)
    )
    (defun c:c2m ()
    (to-modelspace 1)
    )
    (defun c:m2m ()
    (to-modelspace 0)
    )
    (defun to-modelspace (val / exprt omode cecho cvprt trig ss msctr ssv en ed nm
    rt
    sz vd psctr dcl_id x y what_next temp cntr message
    )
    (setq exprt nil
    omode nil
    cvprt nil
    trig nil
    ss nil
    msctr nil
    ssv nil
    en nil
    ed nil
    nm nil
    rt nil
    sz nil
    vd nil
    psctr nil
    dcl_id nil
    x nil
    y nil
    what_next nil
    temp nil
    cntr nil
    message nil)
    (setq cecho (getvar "cmdecho")
    exprt (getvar "expert")
    omode (getvar "osmode")
    cvprt (getvar "cvport"))
    (setvar "cmdecho" 0)
    (setvar "expert" 2)
    (setvar "osmode" 0)
    (command "undo" "begin")
    (defun dtr (d)
    (/ (* d pi) 180.0)
    )
    (defun rtd (r)
    (/ (* r 180.0) pi)
    )
    (if (= (getvar "tilemode") 1)
    (princ "\n \n \n** Command not allowed unless TILEMODE is set to 0 **")
    (if (= (length (vports)) 1)
    (princ "\n \n \n \nThere are no active Model space viewports.")
    (progn
    (setq err *ERROR*)
    (defun *ERROR* (st)
    (cond
    ((or (= st "Function cancelled") (= st "console break")))
    )
    (sp2sp_reset)
    )
    (command "pspace")
    (if (= val 1)
    (princ "\n \nSelect objects to copy: \n ")
    (princ "\n \nSelect objects to move: \n ")
    )
    (setq SS (ssget '((-4 . "<NOT") (0 . "VIEWPORT")
    (-4 . "NOT>")
    )
    ))
    (if (/= SS nil)
    (progn
    (command "mspace")
    (if (> (length (vports)) 2)
    (if (= val 1)
    (getpoint (strcat "\n \n \n" (itoa (- (length
    (vports)
    ) 1
    )
    )
    " Model space viewports defined.\n \nPick inside viewport to copy to: "
    )
    )
    (getpoint (strcat "\n \n \n" (itoa (- (length
    (vports)
    ) 1
    )
    )
    " Model space viewports defined.\n \nPick inside viewport to move to: "
    )
    )
    )
    )
    (if (= val 1)
    (princ
    "\n \nCopy to Model space in progress. \n \nPlease wait..."
    )
    (princ
    "\n \nMove to Model space in progress. \n \nPlease wait..."
    )
    )
    (command "pspace")
    (setq SSV (ssget "x" (list (cons 0 "VIEWPORT"))))
    (while (= trig nil)
    (setq EN (ssname SSV 0))
    (setq ED (entget EN '("ACAD")))
    (setq NM (cadr (assoc '-3 ED)))
    (setq SZ (rtos (/ (cdr (nth 7 NM)) (cdr (assoc'41 ED))) 2 6))
    (if (= (cdr (assoc '68 ED)) 2)
    (setq trig 1)
    )
    (ssdel EN SSV)
    )
    (setq psctr (cdr (assoc'10 ED)))
    (setq pspace_ucs_name (getvar "ucsname"))
    (command "ucs" "world")
    (setvar "highlight" 0)
    (if (= val 1)
    (command "block" "to-modelspace" psctr ss "" "oops")
    (command "block" "to-modelspace" psctr ss "")
    )
    (if (= pspace_ucs_name "")
    (command "ucs" "world")
    (command "ucs" "r" pspace_ucs_name)
    )
    (command "mspace")
    (setq mspace_ucs_name (getvar "ucsname"))
    (command "ucs" "view")
    (setq msctr (getvar "viewctr"))
    (command "insert" "*to-modelspace" msctr SZ "0")
    (if (= mspace_ucs_name "")
    (command "ucs" "world")
    (command "ucs" "r" mspace_ucs_name)
    )
    (princ "\n \n \n ")
    (princ "\n \n \nDONE... ")
    )
    (progn
    (princ "\n \n \n")
    (alert "Your selection set was empty!")
    )
    )
    (if (= cvprt 1)
    (command "pspace")
    (command "mspace")
    )
    )
    )
    )
    (setvar "expert" exprt)
    (setvar "cmdecho" cecho)
    (setvar "osmode" omode)
    (setvar "highlight" 1)
    (setq exprt nil
    omode nil
    cvprt nil
    trig nil
    ss nil
    msctr nil
    ssv nil
    en nil
    ed nil
    nm nil
    rt nil
    sz nil
    vd nil
    psctr nil
    dcl_id nil
    x nil
    y nil
    what_next nil
    temp nil
    cntr nil
    message nil)
    (command "undo" "end")
    (princ)
    )
    (defun sp2sp_reset ()
    (setq *ERROR* err)
    (princ "\n \n \n")
    (if (= mspace_ucs_name)
    (command "mspace" "ucs" "r" mspace_ucs_name)
    )
    (if (= pspace_ucs_name)
    (command "pspace" "ucs" "r" pspace_ucs_name)
    )
    (if (= cvprt 1)
    (command "pspace")
    (command "mspace")
    )
    (setvar "expert" exprt)
    (setvar "cmdecho" cecho)
    (setvar "osmode" omode)
    (setvar "highlight" 1)
    (setq exprt nil
    omode nil
    cecho nil
    cvprt nil
    trig nil
    ss nil
    msctr nil
    ssv nil
    en nil
    ed nil
    nm nil
    rt nil
    sz nil
    vd nil
    psctr nil
    dcl_id nil
    x nil
    y nil
    what_next nil
    temp nil
    cntr nil
    message nil)
    (princ "\n \n \nECS trapped the Error \n")
    (command "undo" "end")
    (princ)
    )
    (princ "\n \n \nC2P = copy to paperspace M2P = move to paperspace")

    (princ "\nC2M = copy to modelspace M2M = move to modelspace")
    (princ)
  • Thanks for the responses, I am going to give Yaakov's code a try!  Woody

This discussion has been closed.