Author Topic: viewport from model space to layout  (Read 367 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Bull Frog
  • Posts: 277
viewport from model space to layout
« on: July 17, 2021, 01:42:23 PM »
Hi .I am searching aa lisp to create new vieport to layout from model space in the same coordinates (the user gives the viwport scale every time).

I was thinking two way to do this.

1) To select a rectangle in model spece that appears in Layout with Viewport at the same coordinates.
2) Specify an area in the Model that appears in Layout with Viewport at the same coordinates.

I find LeeMac lisp code ms2psV1-0.lsp but is not exactly what i am searching

Code - Auto/Visual Lisp: [Select]
  1. ;;-------------------=={ Modelspace to Paperspace }==-------------------;;
  2. ;;                                                                      ;;
  3. ;;  This program allows the user to copy a selection of objects from    ;;
  4. ;;  Modelspace to Paperspace through an active viewport.                ;;
  5. ;;                                                                      ;;
  6. ;;  This functionality is similar to the standard CHSPACE command,      ;;
  7. ;;  however, this program will copy the selection of objects as         ;;
  8. ;;  opposed to moving the objects from Modelspace to Paperspace.        ;;
  9. ;;                                                                      ;;
  10. ;;  Upon issuing the command 'ms2ps' at the AutoCAD command-line, the   ;;
  11. ;;  user is prompted to make a selection of objects to copy.            ;;
  12. ;;                                                                      ;;
  13. ;;  Following a valid selection, the program will copy the objects to   ;;
  14. ;;  the active Paperspace layout, before performing the necessary       ;;
  15. ;;  matrix transformations to maintain the visual appearance of the     ;;
  16. ;;  objects as displayed through the active viewport.                   ;;
  17. ;;                                                                      ;;
  18. ;;  The program is compatible with rectangular & polygonal viewports,   ;;
  19. ;;  under all UCS & view settings, and with objects constructed in      ;;
  20. ;;  any UCS construction plane.                                         ;;
  21. ;;                                                                      ;;
  22. ;;  Note that the command is only available when a Paperspace Layout    ;;
  23. ;;  is set current, with a viewport active.                             ;;
  24. ;;                                                                      ;;
  25. ;;----------------------------------------------------------------------;;
  26. ;;  Author:  Lee Mac, Copyright 2014  -  www.lee-mac.com              ;;
  27. ;;----------------------------------------------------------------------;;
  28. ;;  Version 1.0    -    2014-02-16                                      ;;
  29. ;;                                                                      ;;
  30. ;;  First release.                                                      ;;
  31. ;;----------------------------------------------------------------------;;
  32.  
  33. (defun c:ms2ps ( / *error* ang doc enx idx lst mat nor scl sel )
  34.  
  35.     (defun *error* ( msg )
  36.         (LM:endundo (LM:acdoc))
  37.         (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
  38.             (princ (strcat "\nError: " msg))
  39.         )
  40.         (princ)
  41.     )
  42.  
  43.     (LM:startundo (LM:acdoc))
  44.     (cond
  45.         (   (= 1 (getvar 'tilemode))
  46.             (prompt "\nCommand only available in Paperspace.")
  47.         )
  48.         (   (= 1 (getvar 'cvport))
  49.             (prompt "\nPlease activate a viewport.")
  50.         )
  51.         (   (setq sel (ssget '((410 . "Model"))))
  52.             (repeat (setq idx (sslength sel))
  53.                 (setq lst (cons (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))) lst))
  54.             )
  55.             (setq enx (entget (ssname (ssget "_X" (list '(0 . "VIEWPORT") (cons 69 (getvar 'cvport)))) 0))
  56.                   ang (cdr (assoc 51 enx))
  57.                   nor (cdr (assoc 16 enx))
  58.                   scl (/ (cdr (assoc 41 enx)) (cdr (assoc 45 enx)))
  59.             )
  60.             (setq mat
  61.                 (vlax-tmatrix
  62.                     (append
  63.                         (mapcar '(lambda ( a b ) (append a (list b)))
  64.                             (setq mat ;; The following is adapted from gile's WCS2PCS function:
  65.                                 (mxm
  66.                                     (list
  67.                                         (list (cos ang) (- (sin ang)) 0.0)
  68.                                         (list (sin ang)    (cos ang)  0.0)
  69.                                        '(0.0 0.0 1.0)
  70.                                     )
  71.                                     (mapcar (function (lambda ( v ) (vxs (trans v nor 0 t) scl)))
  72.                                        '(
  73.                                             (1.0 0.0 0.0)
  74.                                             (0.0 1.0 0.0)
  75.                                             (0.0 0.0 1.0)
  76.                                         )
  77.                                     )
  78.                                 )
  79.                             )
  80.                             (mapcar '+
  81.                                 (mxv mat (mapcar '- (cdr (assoc 17 enx))))
  82.                                 (vxs (cdr (assoc 12 enx)) (- scl))
  83.                                 (cdr (assoc 10 enx))
  84.                             )
  85.                         )
  86.                        '((0.0 0.0 0.0 1.0))
  87.                     )
  88.                 )
  89.             )
  90.             (foreach obj
  91.                 (vlax-invoke (setq doc (vla-get-activedocument (vlax-get-acad-object))) 'copyobjects lst
  92.                     (vla-get-block
  93.                         (vla-item
  94.                             (vla-get-layouts doc)
  95.                             (getvar 'ctab)
  96.                         )
  97.                     )
  98.                 )
  99.                 (vla-transformby obj mat)
  100.             )
  101.         )
  102.     )
  103.     (LM:endundo (LM:acdoc))
  104.     (princ)
  105. )
  106.  
  107. ;; Matrix Transpose  -  Doug Wilson
  108. ;; Args: m - nxn matrix
  109.  
  110. (defun trp ( m )
  111.     (apply 'mapcar (cons 'list m))
  112. )
  113.  
  114. ;; Matrix x Matrix  -  Vladimir Nesterovsky
  115. ;; Args: m,n - nxn matrices
  116.  
  117. (defun mxm ( m n )
  118.     ((lambda ( a ) (mapcar '(lambda ( r ) (mxv a r)) m)) (trp n))
  119. )
  120.  
  121. ;; Matrix x Vector  -  Vladimir Nesterovsky
  122. ;; Args: m - nxn matrix, v - vector in R^n
  123.  
  124. (defun mxv ( m v )
  125.     (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
  126. )
  127.  
  128. ;; Vector x Scalar  -  Lee Mac
  129. ;; Args: v - vector in R^n, s - real scalar
  130.  
  131. (defun vxs ( v s )
  132.     (mapcar '(lambda ( n ) (* n s)) v)
  133. )
  134.  
  135. ;; Start Undo  -  Lee Mac
  136. ;; Opens an Undo Group.
  137.  
  138. (defun LM:startundo ( doc )
  139.     (LM:endundo doc)
  140.     (vla-startundomark doc)
  141. )
  142.  
  143. ;; End Undo  -  Lee Mac
  144. ;; Closes an Undo Group.
  145.  
  146. (defun LM:endundo ( doc )
  147.     (while (= 8 (logand 8 (getvar 'undoctl)))
  148.         (vla-endundomark doc)
  149.     )
  150. )
  151.  
  152. ;; Active Document  -  Lee Mac
  153. ;; Returns the VLA Active Document Object
  154.  
  155. (defun LM:acdoc nil
  156.     (LM:acdoc)
  157. )
  158.  
  159. ;;----------------------------------------------------------------------;;
  160.  
  161.     (strcat
  162.         "\n:: ms2ps.lsp | Version 1.0 | \\U+00A9 Lee Mac "
  163.         (menucmd "m=$(edtime,0,yyyy)")
  164.         " www.lee-mac.com ::"
  165.         "\n:: Type \"ms2ps\" to Invoke ::"
  166.     )
  167. )
  168.  
  169. ;;----------------------------------------------------------------------;;
  170. ;;                             End of File                              ;;
  171. ;;----------------------------------------------------------------------;;
  172.  
  173.  

Thanks

BIGAL

  • Swamp Rat
  • Posts: 830
  • 30 + years of using Autocad
Re: viewport from model space to layout
« Reply #1 on: July 17, 2021, 07:16:21 PM »
Something like this, PM me if want want more info.

A man who never made a mistake never made anything

sanju2323

  • Newt
  • Posts: 68
Re: viewport from model space to layout
« Reply #2 on: July 22, 2021, 03:01:21 AM »
Hi Bigal, do you share this lisp?

BIGAL

  • Swamp Rat
  • Posts: 830
  • 30 + years of using Autocad
Re: viewport from model space to layout
« Reply #3 on: July 22, 2021, 10:54:56 PM »
I can but there is a little bit of custom stuff in it like making the rectangs are based on a known size and the layout has a title block and the mview is pre sized. Need a sample dwg to look at.
A man who never made a mistake never made anything