Author Topic: Create viewport boundary from model space polyline  (Read 339 times)

0 Members and 1 Guest are viewing this topic.

Topographer

  • Swamp Rat
  • Posts: 529
Create viewport boundary from model space polyline
« on: September 12, 2018, 06:03:43 PM »
Hi i have a lisp code when i select a viewport create viewport boundary from model space polyline. Some timew i need to do the opposite. Create viewport boundary from model space polyline. Is any one  have a lisp code  to do this ?

Thanks

Topographer

  • Swamp Rat
  • Posts: 529
Re: Create viewport boundary from model space polyline
« Reply #1 on: September 12, 2018, 07:04:27 PM »
I want to select a polyline or polygon from ny model space and create a new viewport in layout  (if i have more layouts show me a list to select the layout i want). Then opens the layout and give me the option toy pick were to place the new viewport.
The model space rectagle has length dimension (x , y). In viewport the (x,y) dimensions must be (Vx,Vy) and i calculate that

Vx = 1000 * x / scale  , and Vy = 1000 * y / scale        x and y are the rectangle dimensions from the model space

Thanks

smemo

  • Mosquito
  • Posts: 14
Re: Create viewport boundary from model space polyline
« Reply #2 on: September 13, 2018, 04:20:15 AM »
I have updated the lisp of the post http://www.theswamp.org/index.php?topic=42149.msg474945#msg474945
now it's only in Italian, I hope it can still be useful
« Last Edit: September 13, 2018, 04:49:23 AM by smemo »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10311
Re: Create viewport boundary from model space polyline
« Reply #3 on: September 13, 2018, 09:11:47 AM »
Translated web site:https://goo.gl/C2QSo9
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Topographer

  • Swamp Rat
  • Posts: 529
Re: Create viewport boundary from model space polyline
« Reply #4 on: September 13, 2018, 01:06:16 PM »
Hi smemo. I try to run the code ...i write  cfl  to the command line and gives me this error

I use Autocad 2017
« Last Edit: September 13, 2018, 01:18:40 PM by Topographer »

Topographer

  • Swamp Rat
  • Posts: 529
Re: Create viewport boundary from model space polyline
« Reply #5 on: September 13, 2018, 01:45:20 PM »
I find this code but is not working on meters . Can any one change the code  to suport this

Vx = 1000 * x / scale  , and Vy = 1000 * y / scale   

I think the problem is here

Code - Auto/Visual Lisp: [Select]
  1. (setq vpxd (* sf (abs (- (car vpc2) (car vpc1))))) ; Determine horizontal length of selected window
  2. (setq vpyd (* sf (abs (- (cadr vpc2) (cadr vpc1))))) ; Determine vertical height of selected window
  3.  

Code - Auto/Visual Lisp: [Select]
  1. (defun c:igalvp (/ vpl vplyes l0 ln layers cp cl cs ofs vpc1 vpc2 vpxd vpyd vpc svpc ssvp ssvp1 sf lpno vpno ssnum vpent nvpc1 nvpc2 nvpc1x nvpc1y nvpc2x nvpc2y)
  2. ; Creates layout of Paper Space viewports of specified 2D orthagonal views from Model Space
  3. ; Used when all 2D design is done in Model Space at full scale and all dimensioning is done in Paper Space as associated scale
  4. ; Start command from destination layout tab
  5. ; Program will switch to Model Space for selection of desired objects
  6. ; Program will return to layout tab for creation of viewport frames
  7. ; First a single viewport is made that includes all relevant views of desired part at the desired zoom level
  8. ; The single viewport is copied over itself the number of desired separate views
  9. ; Then the overlaying viewports are individually clipped to the edges of the separate views
  10. ; The separate views will maintain their original orientation and alignment
  11. ; The separate views can be rectangular by specifying opposite corners or circular by specifying a center and radius
  12. ; Afterwards move the individual views orthogonally, if needed, to allow space for dimensions
  13. (setvar "cmdecho" 0) ; Turn off command line echoing
  14. (setvar "tilemode" 0)
  15. (setq cp (getvar "ctab")) ; Store current tab name
  16. (setq cl (getvar "clayer")) ; Store current layer name
  17. (setq cs (getvar "osmode")) ; Store current osnap mode
  18. (setq vpl "TPZ-VPort") ; ==>> Assume using Viewport layer for viewport frames, change code value here if needed <> Set viewport border offset from actual detail, change code value here if needed <<==
  19. (setvar "osmode" 0) ; Turn osnap on
  20. (if (/= cp "Model") ; Must be started from a layout tab to establish destination, quit quietly if on Model tab
  21. (princ "\n") ; Clean up command line
  22. (setq vplyes 0) ; Assume viewport doesn't exist
  23. (setq l0 (tblnext "LAYER" 1)) ; Get past 0 layer in layer list
  24. (while (setq layers (tblnext "LAYER")) ; Loop through layer list collection
  25. (setq ln (cdr (assoc 2 layers))) ; Extract layer name from list
  26. (if (= (strcase ln) (strcase vpl)) (setq vplyes 1)) ; Check if viewport layer exists
  27. )
  28. (if (= vplyes 0) (command "layer" "NEW" vpl "COLOR" "7" vpl "")) ; Make viewport layer and assign color to magenta if doesn't exist
  29. (setvar "clayer" vpl) ; Change to viewport layer
  30. (command "layer" "ON" (strcat "0," vpl) "UNLOCK" (strcat "0," vpl) "") ; Turn on and unlock viewport and 0 layer
  31. (command "zoom" "e") ; View entire layout tab
  32. (setvar "ctab" "Model") ; Activate Model tab
  33. (command "zoom" "e") ; View entire Model Space area
  34. (setq vpc1 (getpoint "\nSpecify first corner of model space window area: ")) ; Just pick rough area including all relavent details, will fine-tune border area later in Paper Space
  35. (if vpc1 ; Quietly quit if no point specified
  36. (setq vpc2 (getcorner vpc1 "\nSpecify opposite corner of model space window area: ")) ; Window rectangle can be designated in any direction
  37. (if vpc2 ; Quietly quit if no point specified
  38. (princ "\n") ; Clean up command line
  39. (setvar "ctab" cp) ; Return to layout tab program was started from
  40. (command "pspace") ; Switch to Paper Space of layout tab
  41. (setq svpc (getpoint "\nSpecify destination of paper space viewport center: ")) ; Can't change layout tabs manually here
  42. (if svpc ; Quietly quit if no point specified
  43. (setq sf (getreal "\nViewport zoom scale factor : ")) ; Default to full-scale if no value is inputted
  44. (if (= sf nil) (setq sf 1.0) (setq sf (abs sf))) ; Make sure scale factor is positive number
  45. (setq vpxd (* sf (abs (- (car vpc2) (car vpc1))))) ; Determine horizontal length of selected window
  46. (setq vpyd (* sf (abs (- (cadr vpc2) (cadr vpc1))))) ; Determine vertical height of selected window
  47. (setq vpc (list (/ (+ (car vpc1) (car vpc2)) 2.0) (/ (+ (cadr vpc1) (cadr vpc2)) 2.0) 0.0)) ; Determine center point of selected model window
  48. (command "mview" (list (- (car svpc) (/ vpxd 2.0)) (- (cadr svpc) (/ vpyd 2.0))) (strcat "@" (rtos vpxd) "," (rtos vpyd))) ; Create Paper Space viewport
  49. (setq ssvp (ssget "L")) ; Start selection set with last viewport frame
  50. (setq ssvp1 (ssget "L")) ; Another copy of viewport frame selection set
  51. (command "mspace") ; Open viewport window to Model Space
  52. (command "ucsicon" "ON") ; Turn on UCS icon for viewport
  53. (command "ucs" "WORLD") ; Reset UCS to WCS
  54. (command "zoom" "C" vpc (rtos vpyd)) ; Center view of viewport window using determined point
  55. (command "zoom" "SCALE" (strcat (rtos sf) "XP")) ; Set zoom scale of viewport window
  56. (command "vports" "LOCK" "ON" ssvp "") ; Lock scale and position of model in viewport
  57. (command "pspace") ; Close viewport window
  58. (command "zoom" (list (- (car svpc) (/ vpxd 2.0)) (- (cadr svpc) (/ vpyd 2.0))) (strcat "@" (rtos vpxd) "," (rtos vpyd))) ; Zoom in on just created viewport extremes
  59. (command "zoom" "0.95X") ; Back zoom off slightly to see edges clearly
  60. (setq lpno 2) ; Loop counter for making separate viewports
  61. (setq vpno (getint "\nNumber of separate viewports to make from this viewport : ")) ; Will divide single viewport into separate viewports for othagonal views of 2D part
  62. (if (>= vpno 2) ; Proceed to copy current viewport if 2 or more separate viewports desired
  63. (while (<= lpno vpno) ; Check if viewport loop counter less than number of viewports desired
  64. (command "copy" ssvp "" "0,0" "@0,0") ; Make copy of new viewport laying exactly on top of first viewport
  65. (setq lpno (1+ lpno)) ; Increment viewport loop counter
  66. (ssadd (entlast) ssvp1) ; Add viewport copy to selection set
  67. )
  68. )
  69. )
  70. (setq ssnum 0) ; Loop counter for fine-tuning separate viewports
  71. (while (= vpno 2) ; Check for multiple viewports
  72. (setq clt (strcat " #" (rtos (+ ssnum 1) 2 0))) ; Make command prompt string if using multiple viewports
  73. (setq clt "") ; Make command prompt string if using single viewport
  74. )
  75. (initget 128) ; Enable string responses from point prompt
  76. (setq nvpc1 (getpoint (strcat "\nSpecify first corner of viewport" clt " window area or [Center point of circle]: "))) ; Pick actual part corner, program will apply offset
  77. (if nvpc1 ; Will repeat asking for first corner if none specified
  78. (if (= 'STR (type nvpc1)) ; Check if string was inputted instead of corner point
  79. (if (= "C" (strcase (substr nvpc1 1 1))) ; Check if asking for circular viewport area
  80. (setq nvpc1 (getpoint (strcat "\nSpecify center of viewport" clt " window area: "))) ; Pick center of separate circular viewport window
  81. (if nvpc1 ; Will return to asking for first corner if center not specified
  82. (setvar "osmode" 0) ; Turn osnap off
  83. (princ (strcat "\nSpecify radius of viewport" clt " window area: ")) ; Make command prompt for circle viewport
  84. (command "circle" nvpc1 pause) ; Make circle to clip existing viewport
  85. (setvar "osmode" 2559) ; Turn osnap on
  86. (setq ssvp (ssget "L")) ; Select last circle
  87. (command "vpclip" vpent ssvp) ; Clip existing viewport to circle
  88. (setq ssnum (1+ ssnum)) ; Increment fine-tuned viewport loop counter
  89. )
  90. )
  91. )
  92. )
  93. )
  94. (setq nvpc2 (getcorner nvpc1 (strcat "\nSpecify opposite corner of viewport" clt " window area: "))) ; Window rectangle can be designated in any direction, pick actual part corner, program will apply offset
  95. (if nvpc2 ; Will repeat asking for first corner if none specified
  96. (setq nvpc1x (car nvpc1)) ; Find X portion of first corner
  97. (setq nvpc1y (cadr nvpc1)) ; Find Y portion of first corner
  98. (setq nvpc2x (car nvpc2)) ; Find X portion of second corner
  99. (setq nvpc2y (cadr nvpc2)) ; Find Y portion of second corner
  100. (if (> nvpc2x nvpc1x) ; Determine horizontal direction of viewport window rectangle
  101. (setq nvpc2x (+ nvpc2x ofs)) ; Add horizontal offset to right of specified left-to-right window rectangle
  102. (setq nvpc1x (- nvpc1x ofs)) ; Add horizontal offset to left of specified left-to-right window rectangle
  103. )
  104. (setq nvpc2x (- nvpc2x ofs)) ; Add horizontal offset to left of specified right-to-left window rectangle
  105. (setq nvpc1x (+ nvpc1x ofs)) ; Add horizontal offset to right of specified right-to-left window rectangle
  106. )
  107. )
  108. (if (> nvpc2y nvpc1y) ; Determine vertical direction of viewport window rectangle
  109. (setq nvpc2y (+ nvpc2y ofs)) ; Add vertical offset to top of specified lower-to-upper window rectangle
  110. (setq nvpc1y (- nvpc1y ofs)) ; Add vertical offset to bottom of specified lower-to-upper window rectangle
  111. )
  112. (setq nvpc2y (- nvpc2y ofs)) ; Add vertical offset to bottom of specified upper-to-lower window rectangle
  113. (setq nvpc1y (+ nvpc1y ofs)) ; Add vertical offset to top of specified upper-to-lower window rectangle
  114. )
  115. )
  116. (setvar "osmode" 0) ; Turn osnap off
  117. (command "rectang" (list nvpc1x nvpc1y) (list nvpc2x nvpc2y)) ; Make rectangle with offset to clip existing viewport
  118. (setvar "osmode" 2559) ; Turn osnap on
  119. (setq ssvp (ssget "L")) ; Select last rectange
  120. (command "vpclip" vpent ssvp) ; Clip existing viewport to rectangle
  121. (setq ssnum (1+ ssnum)) ; Increment fine-tuned viewport loop counter
  122. )
  123. )
  124. )
  125. )
  126. )
  127. )
  128. )
  129. )
  130. )
  131. )
  132. )
  133. )
  134. )
  135. )
  136. (princ "\nThis command must be started from a layout sheet!") ; Need to start on a layout tab so program knows where to create the new viewports
  137. )
  138. (setvar "ctab" cp) ; Reset to stored tab name
  139. (setvar "clayer" cl) ; Reset to stored layer name
  140. (setvar "osmode" cs) ; Reset to stored osnap mode
  141. (setvar "cmdecho" 1) ; Turn on command line echoing
  142. (princ) ; Clean up and exit
  143. )
  144.  
  145.  
  146.  

Thanks

Topographer

  • Swamp Rat
  • Posts: 529
Re: Create viewport boundary from model space polyline
« Reply #6 on: September 13, 2018, 06:20:51 PM »
Any ideas ?

smemo

  • Mosquito
  • Posts: 14
Re: Create viewport boundary from model space polyline
« Reply #7 on: September 14, 2018, 06:42:12 AM »
Hi smemo. I try to run the code ...i write  cfl  to the command line and gives me this error

I use Autocad 2017
Hi Topographer, the ai_utils.lsp file is required to run. In my Autocad is in "C:\Program Files\Autodesk\AutoCAD 2015\Support\it-IT".
Usually installed with Express Tools
« Last Edit: September 14, 2018, 06:50:25 AM by smemo »

Topographer

  • Swamp Rat
  • Posts: 529
Re: Create viewport boundary from model space polyline
« Reply #8 on: September 19, 2018, 02:19:50 AM »
Hi smemo . The correct path in my pc  for the ai_utils.lsp is  C:\Program Files\Autodesk\AutoCAD 2017\Support\en-us


Can you update the code ?

Thanks

smemo

  • Mosquito
  • Posts: 14
Re: Create viewport boundary from model space polyline
« Reply #9 on: September 19, 2018, 05:03:00 AM »
Hi Topographer,
from "ai_utils.lsp" I use the functions: ai_dcl, ai_abort,ai_acadapp, ai_table.
from line 69 to 76
Code: [Select]
(cond
     ((and ai_dcl (listp ai_dcl)))      ; it's already loaded.
     ((not (findfile "ai_utils.lsp"))   ; find it
       (ai_abort "CreaFinLay" "Non trovato il file AI_UTILS.LSP.\n   Verifica la cartella di supporto."))
 
     ((eq "failed" (load "ai_utils" "failed"))  ; load it
      (ai_abort "CreaFinLay" "Impossibile caricare il file AI_UTILS.LSP"))
  )
if "ai_utils.lsp" is not loaded probably the path is not present in the file search path options
« Last Edit: September 19, 2018, 05:11:07 AM by smemo »

Topographer

  • Swamp Rat
  • Posts: 529
Re: Create viewport boundary from model space polyline
« Reply #10 on: Today at 03:10:19 AM »
Thanks  smemo