model or paper space then react

Discussion in 'AutoCAD' started by Clarence, Jan 13, 2005.

  1. Clarence

    Clarence Guest

    I want the following to read what space you're in and react accordingly. I've noted the portion that needs to change. I just can't get it to work when I try to modify the way I thought would work.

    (DEFUN C:na (/ prevlayr tstlay)
    (setq quietplz (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (command "undo" "begin")
    (setq olderr *error*)
    (defun *error* (errmes)
    (princ
    (strcat "\n North Arrow Insertion halted by: " errmes)
    )
    (command "undo" "end")
    (setq *error* olderr)
    (command "undo" "1")
    (prin1)
    )
    (command "-layer" "a" "s" "ADDLAYERTOBEREMOVED" "" "" "")
    (graphscr)
    (setq PREVLAYR (getvar "CLAYER"))
    (COMMAND "ATTDIA" "0")
    (COMMAND "FILEDIA" "0")
    (setq NOR90 (getvar "osmode"))
    (setvar "osmode" 0)
    (setq tstlay (cdr (assoc 62 (tblsearch "layer" "*view*"))))
    (cond
    ((< tstlay 0)
    (progn
    (= (strcase "*view*") (strcase (getvar "clayer")))
    (command "-layer" "s" "0" "")
    (command "-layer" "on" "*view*" "")
    )
    )
    )
    (alert "\nBegin this command from Paperspace.")
    (vscale)
    )
    (defun paper ();;<<<<<this is where I need to change things
    (> 2 (getvar "cvport") (getvar "tilemode")) ; port=1 & tile=0
    )
    (defun getx (n data)
    (nth n (cdadr (assoc -3 data)))
    )
    (defun sslist (SS / N P)
    (repeat (setq N (sslength SS)) ;seed N
    (setq N (1- N) ;index number
    P (cons (ssname SS N) P)
    ) ;setq
    ) ;repeat
    ) ; sslist
    (defun findvp (vp# / vplist)
    (setq vplist (ssget "X" '((0 . "viewport")))
    vplist (sslist vplist)
    )
    (while
    (and (/= (dxf 69) vp#)
    (setq ent (car vplist))
    )
    (setq data (entget ent)
    vplist (cdr vplist)
    )
    ) ;while
    )
    (defun vscale (/ dxf ent data cvsize cvhgt)
    (defun dxf (code) (cdr (assoc code data)))
    (if (paper)
    (setq ent (car (entsel "\n\n\nSelect edge of viewport: \n\n")))
    (setq ent (findvp (getvar "cvport")))
    )
    (cond
    ((and
    ent
    (setq data (entget ent '("ACAD")))
    (= "VIEWPORT" (dxf 0))
    ) ;and
    (setq cvhgt (dxf 41) ; viewport height
    cvsize (cdr (getx 6 data)) ; viewsize from extended data
    )
    (vpinsert)
    )
    (T
    (alert " No Viewport Found. ")
    (setq *error* olderr)
    (command "undo" "end")
    (command "undo" "1")
    )
    ) ;cond
    ) ;c:vscale
    (defun vpinsert
    (/ twang nainspt scalewhat
    2xwhatscale 2xscale scaletxt tstlayagin
    DOC LOCK
    )
    (command "-layer" "a" "r"
    "ADDLAYERTOBEREMOVED" "D"
    "ADDLAYERTOBEREMOVED" ""
    "" ""
    )
    (setq tstlayagin (cdr (assoc 62 (tblsearch "layer" "*view*"))))
    (cond
    (not
    (= tstlayagin 0)
    (progn
    (= (strcase "*view*") (strcase (getvar "clayer")))
    (command "-layer" "s" "0" "")
    )
    )
    )
    (SETQ DOC (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT)))
    (IF (= (VLA-GET-ACTIVESPACE DOC) 0)
    (PROGN
    (SETQ LOCK (VLA-GET-DISPLAYLOCKED (VLA-GET-ACTIVEPVIEWPORT DOC)))
    (IF (= LOCK :VLAX-FALSE)
    (progn
    (COMMAND "-VPORTS" "L" "ON" "ALL" "")
    (command "-layer" "off" "*view*" "")
    )
    (command "-layer" "off" "*view*" "")
    )
    )
    )
    ;;added this to check lock/unlock status and then do appropriate action
    (prompt
    "\n\nPick inside the viewport that this is for <this is also the insertion point>: \n"
    )
    (command "mspace")
    (SETQ pntofins (GETPOINT))
    (setq twang (getvar "viewtwist"))
    (setq twang (/ (* twang 180.0) PI))
    (setq nainspt (trans (trans pntofins 1 2) 2 3))
    (COMMAND "PSPACE")
    (cond
    (
    (setq scalewhat (/ cvsize cvhgt))
    )
    )
    (setq 2xwhatscale (* scalewhat 2))
    (setq scaletxt (rtos scalewhat 2 0))
    (setq 2xscale (rtos 2xwhatscale 2 0))
    (COMMAND "LAYER" "S" 0 "")
    (COMMAND "-INSERT" "i:/blocks/autolisp_blocks/barscale"
    NAINSPT "1" ""
    "" 2xscale scaletxt
    scaletxt
    )
    (COMMAND "-INSERT" "i:/blocks/autolisp_blocks/Narrow"
    NAINSPT "1"
    "" twang
    )

    (setvar "OSMODE" NOR90)
    (COMMAND "ATTDIA" "1")
    (COMMAND "FILEDIA" "1")
    (setvar "cmdecho" quietplz)
    (setq *error* olderr)
    (command "undo" "end")
    (prompt "\nDone....\n")
    (princ)
    )

    I tried adding something similar to the following but it only screwed everything else up.

    (if (= (getvar "CTAB") "Model")
    (setq prevspace (setvar "ctab" "model"))
    (if (> (getvar "CVPORT") 1)
    (setq prevspace "Pspace")
    (setq prevspace "pspace")
    )
    )

    My goal is:

    I want it to cancel and send alerts if they're in model tab, so they can start over from the correct tab.

    If in Modelspace to switch to paper.

    If in Paperspace to continue with no problems.

    Thanks for any suggestions or comments.
    Clarence
     
    Clarence, Jan 13, 2005
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.