home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p024 / 5.img / R11SUPP.EXE / XREFCLIP.LSP < prev   
Encoding:
Lisp/Scheme  |  1990-10-02  |  13.5 KB  |  455 lines

  1. ;;;   XrefClip.lsp
  2. ;;;   Copyright (C) 1990 by Autodesk, Inc.
  3. ;;;  
  4. ;;;   Permission to use, copy, modify, and distribute this software and its
  5. ;;;   documentation for any purpose and without fee is hereby granted.  
  6. ;;;
  7. ;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 
  8. ;;;   ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 
  9. ;;;   MERCHANTABILITY ARE HEREBY DISCLAIMED.
  10. ;;;   
  11. ;;;   by Jan S. Yoder
  12. ;;;   02 July 1990
  13. ;;;
  14. ;;;----------------------------------------------------------------------------
  15. ;;; DESCRIPTION
  16. ;;;   
  17. ;;;   This routine is intended to make the task of inserting, sizing, and 
  18. ;;;   positioning of external references easier, by clearing the screen of
  19. ;;;   all graphics, creating a viewport exclusively for the XREF, creating 
  20. ;;;   a layer on which to attach the XREF, and zooming to the extents of 
  21. ;;;   the XREF in current UCS plan view.
  22. ;;;   
  23. ;;;   The routine may be called with either XC or XREFCLIP.
  24. ;;;   
  25. ;;;   If TILEMODE is set to 1 or ON, you are asked whether you want to reset
  26. ;;;   it, and if not, you are exited from the routine.  If you elect to change
  27. ;;;   it, or it is already 0 or OFF, then you are prompted:
  28. ;;;   
  29. ;;;     XrefClip, Version 1.00, (c) 1990 by Autodesk, Inc. 
  30. ;;;     Xref name: 
  31. ;;;     XrefClip onto what layer? 
  32. ;;;     
  33. ;;;   The XREF name must be a valid drawing file name that can be found on 
  34. ;;;   AutoCAD's search paths.  The layer name must not be the name of an 
  35. ;;;   existing layer name;  if it is you are so informed and asked for a 
  36. ;;;   new name.
  37. ;;;   
  38. ;;;   At this point, all of the viewports are turned off, and all thawed 
  39. ;;;   layers are frozen.  A new viewport is fit to the screen, and the 
  40. ;;;   XREF is attached to the layer specified in that viewport.  The XREF
  41. ;;;   is zoomed to its extents so that you may select the area you want to
  42. ;;;   clip (inclusively.)
  43. ;;;   
  44. ;;;   You are prompted for the two clip points;
  45. ;;;   
  46. ;;;     First point of clip box:  
  47. ;;;     Other point of clip box:
  48. ;;;     
  49. ;;;   and the zoom ratio;
  50. ;;;   
  51. ;;;     Enter the ratio of paper space units to model space units...  
  52. ;;;     Number of paper space units.  <1.0>:  
  53. ;;;     Number of model space units.  <1.0>: (8)
  54. ;;;   
  55. ;;;   All of the viewports are restored to their former state, and a box 
  56. ;;;   designating the clipped viewport can be dragged around and you are 
  57. ;;;   prompted for a location for the clipped view.
  58. ;;;   
  59. ;;;     Insertion point for XrefClip: 
  60. ;;;     
  61. ;;;   A new viewport containing the clipped view of the XREF will be inserted 
  62. ;;;   at the location specified.
  63. ;;;   
  64. ;;;----------------------------------------------------------------------------;
  65. ;;;   
  66. ;;;   
  67. (defun xcmain ( / xc_err s xc_oer xc_oce xc_oem xc_olu xc_ocv 
  68.                   curlay xc_nam lay xc:sov xc_vpn xc:ltg xc:ltl)
  69.  
  70.   ;;
  71.   ;; Internal error handler defined locally
  72.   ;;
  73.  
  74.   (defun xc_err (s)                   ; If an error (such as CTRL-C) occurs
  75.                                       ; while this command is active...
  76.     (if (/= s "Function cancelled")
  77.       (if (= s "quit / exit abort")
  78.         (princ)
  79.         (princ (strcat "\nError: " s))
  80.       )
  81.     )
  82.     (command "undo" "en")
  83.     (if xc_oer                        ; If an old error routine exists
  84.       (setq *error* xc_oer)           ; then, reset it 
  85.     )
  86.     (if xc_oce (setvar "cmdecho" xc_oce)) ; Reset command echoing on error
  87.     (if xc_oem (setvar "expert" xc_oem)) ; Reset expert mode on error
  88.     (princ)
  89.   )
  90.   
  91.   (if *error*                         ; If there is an error routine defined
  92.     (setq xc_oer   *error*            ; Store AutoLisp error routine
  93.           *error*  xc_err)            ; Temporarily replace it
  94.   )
  95.   
  96.   (setq xc_oce (getvar "cmdecho"))
  97.   (setq xc_oem (getvar "expert"))
  98.   (setvar "cmdecho" 0)                ; Turn off command echoing
  99.   (setvar "expert" 5)                 ; Turn expert mode way up.
  100.   (command "undo" "group")            ; Set start of Undo group
  101.   (if (xc_ctm)                        ; Is Tile-mode on? T or nil
  102.     (progn
  103.       (xc_sxc)                        ; Set up for Xref Clip
  104.       (xc_dxc)                        ; Do XREF clipping
  105.     )
  106.   )
  107.   (if (/= xc_ocv 1) (setvar "cvport" xc_ocv) (command "pspace"))
  108.   (command "layer" "set" curlay "")
  109.   (if xc_oer                          ; If an old error routine exists
  110.     (setq *error* xc_oer)             ; then, reset it 
  111.   )
  112.   (command "undo" "end")              ; Set Undo End
  113.  
  114.   (if xc_oem (setvar "expert" xc_oem)) ; Reset expert mode
  115.   (if xc_oce (setvar "cmdecho" xc_oce)) ; Reset command echoing
  116.   (princ)
  117. )
  118. ;;;
  119. ;;; Check Tile-mode.  Returns T if ON and nil if not on.
  120. ;;;
  121. ;;; xc_ctm == MView_Check_TileMode
  122. ;;;
  123. (defun xc_ctm (/ ans)
  124.   (if (= (getvar "TILEMODE") 1) 
  125.     (progn
  126.       (initget "Yes No")
  127.       (setq ans (getkword (strcat
  128.         "\nPaperspace/Modelspace is disabled.  This routine will not "
  129.         "\nrun unless it is enabled.  Enable Paper/Modelspace?  <Y>: "))
  130.       )
  131.       (if (= ans "No")
  132.         nil
  133.         (progn
  134.           (setvar "TILEMODE" 0)
  135.           T
  136.         )
  137.       )
  138.     )
  139.     T
  140.   )
  141. )
  142. ;;;
  143. ;;; Get set up for reference file clipping; get the file name, the layer to 
  144. ;;; put it on, and make the layers, and set up all of the layers correctly
  145. ;;; to minimize "viewports".
  146. ;;; 
  147. ;;; xc_sxc == MView_Setup_for_Xref_Clip
  148. ;;;
  149. (defun xc_sxc (/ xc_ver xc_xdf xc_xlf xref)
  150.  
  151.   (setq xc_ver "1.00")                ; Reset this local if you make a change.
  152.   
  153.   (setq xc_ocv (getvar "cvport"))
  154.   (if (/= xc_ocv 1)
  155.     (command "pspace")                ; Change to paperspace
  156.   )
  157.                                         
  158.   (princ (strcat 
  159.     "\nXrefClip, Version " xc_ver ", (c) 1990 by Autodesk, Inc. "))
  160.  
  161.   (setq xref T)
  162.  
  163.  
  164.   ;; Save the current layer name.
  165.   (setq curlay (getvar "clayer"))
  166.   
  167.   ;; Get the name of the xref...
  168.   (setq xc_nam (xc_gxn))
  169.  
  170.   ;; Get a layer name for the Xref.  It must not already exist!
  171.   (setq lay (xc_gln))
  172.  
  173.   ;; Make a layer for the new viewport.
  174.   (command "vplayer" "new" (strcat lay "-vp") "")
  175.   (command "vplayer" "f" (strcat lay "-vp") "all" "t" (strcat lay "-vp") "" "")
  176.   (command "layer" "set" (strcat lay "-vp") "")
  177.   
  178.   ;; Save the names of all the layers that are thawed globally.
  179.   (xc_sgt) 
  180.  
  181.   ;; Freeze all of 'em except the current layer.
  182.   (command "layer" "f" (strcat "~" lay "-vp") "")
  183.   
  184.   ;; Save the names of all the viewports that are ON.
  185.   (xc_sov) 
  186.  
  187.   ;; Freeze all of 'em except the current layer.
  188.   (command "mview" "off" xc:sov "")
  189.   
  190.   ;; Create a new viewport on the viewport layer.  Fit it to the screen.
  191.   (command "mview" "f")
  192.  
  193.   ;; Make a new layer for the Xref.  Make it exclusive.
  194.   (command "vplayer" "new" lay "")
  195.   (command "vplayer" "f" lay "all" "t" lay "s" "l" "" "")
  196.   
  197.   ;; Save the entity name of the viewport.
  198.   (setq xc_vpn (entlast))
  199.  
  200.   (if (= (getvar "cvport") 1)
  201.     (command "mspace")                ; Change to modelspace
  202.   )
  203.                                         
  204.   (command "layer" "set" lay "")
  205.   (command "plan" "w")
  206.  
  207.   (command "vplayer" "f" (strcat "~" lay) "" "")
  208.  
  209.   ;; Do the Xref attach or block insertion.
  210.   (command "xref" "" xc_nam "0,0" "" "" "")
  211.  
  212.   ;; Zoom extents in plan view
  213.   (command "zoom" "e")
  214. )
  215. ;;;
  216. ;;; 
  217. ;;; 
  218. ;;;
  219. ;;; xc_dxc == MView_Do_Xref_Clip
  220. ;;;
  221. (defun xc_dxc (/ xc:cp1 xc:cp2 xc_vps xs ys nxs nys ip)
  222.   ;; Get the first point of the clip box.
  223.   (setq xc:cp1 (getpoint "\nFirst point of clip box: "))
  224.   
  225.   ;; Get the other point of the clip box.
  226.   (setq xc:cp2 (getcorner xc:cp1 "\nOther point of clip box: "))
  227.  
  228.   (if (/= (getvar "cvport") 1)
  229.     (command "pspace")                ; Change to paperspace
  230.   )
  231.                                         
  232.   ;; Get the scale of the clip region.
  233.   (setq xc_vps (xc_ssi))
  234.  
  235.   ;; Set the X and Y scale factors based on the two points 
  236.   ;; and the scale factor entered.
  237.   (setq xs (- (car  xc:cp2) (car  xc:cp1))
  238.         ys (- (cadr xc:cp2) (cadr xc:cp1))
  239.         nxs (/ xs xc_vps)
  240.         nys (/ ys xc_vps)
  241.   )
  242.  
  243.   ;; Delete the last viewport.
  244.   (entdel xc_vpn)
  245.  
  246.   ;; Turn back ON all of the viewports.
  247.   (command "mview" "on" xc:sov "")
  248.  
  249.   ;; Thaw the layers which we froze earlier.
  250.   (command "layer")
  251.   (foreach n xc:ltg (command "thaw" n))
  252.   (command "")
  253.   (command "layer" "set" curlay "")
  254.  
  255.   (if (tblsearch "block" "xc_box")
  256.     (progn
  257.       (princ "\nInsertion point for XrefClip: ")
  258.       (command "insert" "xc_box" "xscale" nxs "yscale" nys "rotate" 0 pause)
  259.     )
  260.     (progn
  261.       (command "pline" "0,0" "w" "0" "" "1,0" "1,1" "0,1" "cl")
  262.       (command "chprop" (entlast) "" "c" "bylayer" "lt" "bylayer" "la" "0" "")
  263.       (command "block" "xc_box" "0,0" (entlast) "")
  264.       (princ "\nInsertion point for XrefClip: ")
  265.       (command "insert" "xc_box" "xscale" nxs "yscale" nys "rotate" 0 pause)
  266.     )
  267.   )
  268.   
  269.   ;; Get the block insertion point and scale factors.
  270.   (setq ip (xc_val 10 (entlast) nil))
  271.  
  272.   ;; Delete the block.
  273.   (entdel(entlast))
  274.  
  275.   ;;(princ "\nModifying the new viewport. ")
  276.  
  277.   ;; Create the new viewport.
  278.   (command "layer" "set" (strcat lay "-vp") "")
  279.   (command "vplayer" "f" lay "c" "")
  280.   (command "mview" ip (strcat "@" (rtos nxs) "," (rtos nys) "," "0.0"))
  281.  
  282.   (setq xc_vpn (entlast))
  283.   (setq temp (xc_val 69 xc_vpn nil))
  284.                                         
  285.   (if (= (getvar "cvport") 1)
  286.     (command "mspace")                ; Change to modelspace
  287.   )
  288.   
  289.   (command "vplayer" "f" lay "all" "t" lay "s" "l" "" "")
  290.  
  291.   (if (> (xc_val 68 xc_vpn nil) 0)
  292.     (progn
  293.   
  294.       (setvar "cvport" temp)
  295.       
  296.       (command "plan" "")
  297.       (command "zoom" "c" (xc_a2p xc:cp1 xc:cp2) ys)
  298.     )
  299.     (princ "\nViewport is too small. ")
  300.   )
  301.   
  302. )
  303. ;;;
  304. ;;; Get the midpoint between two points.
  305. ;;;
  306. ;;; xc_a2p == XrefClip_Average_2_Points
  307. ;;;
  308. (defun xc_a2p (a b / c)
  309.   (setq c (list (/ (+ (car  a) (car  b)) 2.0)
  310.                 (/ (+ (cadr a) (cadr b)) 2.0)
  311.                 0.0
  312.           )
  313.   )
  314. )
  315. ;;;
  316. ;;; Get the value associated with key "n" in "e".
  317. ;;; If "f" is T the "e" is an entity list, else it is an entity name.
  318. ;;;
  319. ;;; xc_val == XrefClip_assoc_VALue
  320. ;;;
  321. (defun xc_val (n e f) 
  322.   (if f ; if f then e is an entity list.
  323.     (cdr (assoc n e))
  324.     (cdr (assoc n (entget e)))
  325.   )
  326.  
  327. ;;;
  328. ;;; Save the names of all the viewports that are ON,
  329. ;;; because we are going to temporarily turn them all OFF.
  330. ;;;
  331. ;;; xc_sov == XrefClip_Save_On_Viewports
  332. ;;;
  333. (defun xc_sov (/ ss sov sslen)
  334.   (setq xc:sov (ssadd)
  335.         j      0
  336.   )
  337.   (setq ss (ssget "x" '((0 . "viewport")))) ; Get all vports in database.
  338.   (setq sslen (sslength ss))
  339.   (while (< j sslen)
  340.     (setq sov (ssname ss j))
  341.     (if (and (> (xc_val 68 sov nil) 1) (/= (xc_val 69 sov nil) 1))
  342.       (ssadd sov xc:sov)
  343.     )
  344.     (setq j (1+ j))
  345.   )
  346.   xc:sov
  347. )
  348. ;;;
  349. ;;; Save the layer names of all the layers that are globally Thawed,
  350. ;;; because we are going to temporarily Freeze all of them.
  351. ;;;
  352. ;;; xc_sgt == XrefClip_Save_Globally_Thawed_layers
  353. ;;;
  354. (defun xc_sgt (/ lay)
  355.   (setq lay (tblnext "layer" T))      ; Get first layer in database.
  356.   (if (/= (logand (cdr(assoc 70 lay)) 1) 1)
  357.     (setq xc:ltg (list (cdr(assoc 2 lay))))
  358.   )
  359.   (while (setq lay (tblnext "layer"))
  360.     (if (/= (logand (cdr(assoc 70 lay)) 1) 1)
  361.       (setq xc:ltg (append xc:ltg (list (cdr(assoc 2 lay)))))
  362.     )
  363.   )
  364.   xc:ltg
  365. )
  366. ;;;
  367. ;;; Save the layer names of all the layers in the current viewport that 
  368. ;;; are locally thawed, because we are going to temporarily freeze them.
  369. ;;;
  370. ;;; xc_slt == XrefClip_Save_Locally_Thawed_layers
  371. ;;;
  372. (defun xc_slt (/ lay)
  373.   (setq lay (tblnext "layer" T))      ; Get first layer in database.
  374.   (if (/= (logand (cdr(assoc 70 lay)) 2) 2)
  375.     (setq xc:ltl (list (cdr(assoc 2 lay))))
  376.   )
  377.   (while (setq lay (tblnext "layer"))
  378.     (if (/= (logand (cdr(assoc 70 lay)) 2) 2)
  379.       (setq xc:ltl (append xc:ltl (list (cdr(assoc 2 lay)))))
  380.     )
  381.   )
  382.   xc:ltl
  383. )
  384. ;;;
  385. ;;; Set a layer if it exists?  Create it otherwise?
  386. ;;;
  387. ;;; xc_gln == XrefClip_Get_Layer_Name
  388. ;;;
  389. (defun xc_gln (/ temp)
  390.   (while (null temp)
  391.     (initget 1)
  392.     (setq temp (getstring
  393.       "\n\nXrefClip onto what layer? ")
  394.     )
  395.     (if (tblsearch "layer" temp)
  396.       (progn
  397.         (princ "\nLayer exists. ")
  398.         (setq temp nil)
  399.       )
  400.     )
  401.   )
  402.   temp
  403. )
  404. ;;;
  405. ;;; Get the xref file name and verify that it exists.
  406. ;;;
  407. ;;; xc_gxn == XrefClip_Get_Xref_Name
  408. ;;;
  409. (defun xc_gxn (/ temp xc_nam)
  410.   (while (null xc_nam)
  411.     (initget 1)
  412.     (setq temp (getstring (strcat
  413.       "\nXref name: "))
  414.     )
  415.     (if (setq xc_nam (findfile (strcat temp ".dwg")))
  416.       (princ)
  417.       (princ (strcat "\n" temp " not found. "))
  418.  
  419.     )
  420.   )
  421.   xc_nam
  422. )
  423. ;;;
  424. ;;; Interactively set the scale of each viewport.
  425. ;;;
  426. ;;; xc_ssi == XrefClip_Setup_Scale_Interactively
  427. ;;;
  428. (defun xc_ssi (/ ans)
  429.   (princ "\nEnter the ratio of paper space units to model space units... ")
  430.   (initget 6)
  431.   (setq ans (getreal 
  432.     "\nNumber of paper space units.  <1.0>: ")
  433.   )
  434.   (if (= (type ans) 'REAL)
  435.     (setq xc_vps ans)
  436.     (setq xc_vps 1.0)
  437.   )
  438.   (initget 6)
  439.   (setq ans (getreal 
  440.     "\nNumber of model space units.  <1.0>: ")
  441.   )
  442.   (if (= (type ans) 'REAL)
  443.     (setq xc_vps (/ xc_vps ans))
  444.     (setq xc_vps (/ xc_vps 1.0))
  445.   )
  446.   xc_vps
  447. )
  448. ;;; --------------------------------------------------------------------------;
  449. (defun c:xc       () (xcmain))
  450. (defun c:xrefclip () (xcmain))
  451. (princ 
  452.   "\n\tC:XrefClip loaded.  Start command with XC or XREFCLIP.")
  453. (princ)
  454.