<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Viewport with specific scale in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/viewport-with-specific-scale/m-p/8187539#M101320</link>
    <description>&lt;P&gt;Hi, we have a similar process where I work.&amp;nbsp; Instead of a program creating the viewports, we have them defined in the templates.&amp;nbsp; That way they are always centered when you use the template.&amp;nbsp; Then it's just a matter of scaling the viewport.&amp;nbsp; Here is some code to find the viewport to change its scale.&amp;nbsp; We put our viewports on layer "Viewport", so that's what it looks for (there are usually 2 viewports that it will find, even if you only created one in your template).&lt;/P&gt;&lt;P&gt;We call our layouts "P1", "P2", ... so layoutNum is the tab.&lt;/P&gt;&lt;PRE&gt;(setvar "ctab" (vla-get-name layoutNum)) ;"P2", "P3", "P4"....
    ;--- Change Viewport Scale ---
    ;Create a selection set of the viewports on the current layout tab only
    (setq vpSS (ssget "X" (list '(0 . "VIEWPORT")(cons 410 (getvar "ctab")))))
    (setq vpCounter 0)
    (while (&amp;lt; vpCounter (sslength vpSS))
     ;Make sure you have the correct viewport (the one on layer "VIEWPORT")
     (setq vpLayer (cdr (assoc 8 (entget (ssname vpSS vpCounter)))))
     (if (= vpLayer "VIEWPORT")
      ;Set the scale of the viewport to 1:1
      (vla-put-customscale (vlax-ename-&amp;gt;vla-object (ssname vpSS vpCounter)) 1.0)
     ) ;ends if
     (setq vpCounter (+ vpCounter 1))
    ) ;ends while&lt;/PRE&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;</description>
    <pubDate>Wed, 08 Aug 2018 22:34:30 GMT</pubDate>
    <dc:creator>mgorecki</dc:creator>
    <dc:date>2018-08-08T22:34:30Z</dc:date>
    <item>
      <title>Viewport with specific scale</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/viewport-with-specific-scale/m-p/8183627#M101317</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working in a bigger lisp that will create new layouts containing titleblock and viewport. I have the first part figure out, but I don't know how to proceed with the viewports. I want to make a new viewport that will fit in a rectangle in the paperspace and will have a specific scale determined by the drawing and will be center to fit in another rectangle in the model space.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My idea so far is the following:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a new viewport&lt;/LI&gt;&lt;LI&gt;Origin and dimension of the rectangle are known (not a problem)&lt;/LI&gt;&lt;LI&gt;Read an attribute in the drawing to know the scale (we use different templates for different scales)&lt;/LI&gt;&lt;LI&gt;Take that scale and apply it to the viewport&lt;/LI&gt;&lt;LI&gt;And somehow align the rectangle within the viewport (model space) with the rectangle of the viewport.&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I know how to do the first steps, but I am not sure about number 4 and completely lost with 5.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Any ideas about how to solve it this way or with other approach?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;PS. I was thinking that I could make the rectangle in model space a block, and when I create the viewport I can zoom to object (and that should make the scale work)&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 20:53:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/viewport-with-specific-scale/m-p/8183627#M101317</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-07T20:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: Viewport with specific scale</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/viewport-with-specific-scale/m-p/8183814#M101318</link>
      <description>&lt;P&gt;#4 is similar to what you would do manually. But I would do this step after #5.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#5 to do what you suggested, use this command sequence:&lt;/P&gt;&lt;P&gt;(command"_.MSPACE""_.ZOOM""_OBJECT""_ALL""")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once you've zoomed into the rectangular object, then to do #4 will depend on how your scale information is stored.&amp;nbsp; For example, if your scale is always stored in this pattern 1"=8'-0", then I would create a list with this pattern:&lt;/P&gt;&lt;P&gt;(setq scl-lst (list "1\"=8'-0\"" "1\"=4'-0\"" &lt;SPAN&gt;"1\"=2'-0\"&lt;/SPAN&gt;" ))&lt;/P&gt;&lt;P&gt;Also&amp;nbsp;create a matching list with the actual xp zoom factor:&lt;/P&gt;&lt;P&gt;(setq zm-lst (list "0.010416xp" "0.02083xp" "0.04166xp"))&lt;/P&gt;&lt;P&gt;So let's say you've retrieved the scale information from the attribute and stored it as a text in symbol scl-txt:&lt;/P&gt;&lt;P&gt;(if(setq match (member scl-txt scl-lst))&lt;/P&gt;&lt;P&gt;&amp;nbsp;(progn ; if matching scale pattern found&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;(setq match-len (- (length scl-lst)(length match))) ; find&amp;nbsp;position in the scale list&lt;/P&gt;&lt;P&gt;&amp;nbsp; (setq zmfac(nth match-len zm-lst)) ; get the matching zoom factor position from the&amp;nbsp;zoom list&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;;; Finally, use&amp;nbsp;this lisp sequence to complete #4:&lt;/P&gt;&lt;P&gt;&amp;nbsp; (command"_.ZOOM"&amp;nbsp;zmfac)&lt;/P&gt;&lt;P&gt;&amp;nbsp;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;(princ"\nNo Matching Scale Found")&lt;/P&gt;&lt;P&gt;)&lt;/P&gt;&lt;P class="MsoNormal"&gt;&lt;A href="http://apps.exchange.autodesk.com/ACD/en/Detail/Index?id=appstore.exchange.autodesk.com%3aareaobjectlink_windows32and64%3aen" target="_blank"&gt;Area Object Link&lt;/A&gt; | &lt;A href="https://apps.exchange.autodesk.com/ACD/en/Detail/Index?id=appstore.exchange.autodesk.com%3addattmod_windows32and64%3aen" target="_blank"&gt;Attribute Modifier&lt;/A&gt; | &lt;A href="http://apps.exchange.autodesk.com/ACD/en/Detail/Index?id=appstore.exchange.autodesk.com%3addsetup_windows32and64%3aen" target="_blank"&gt;Dwg Setup&lt;/A&gt; | &lt;A href="https://apps.exchange.autodesk.com/ACD/en/Detail/Index?id=appstore.exchange.autodesk.com%3addcalc_windows32and64%3aen" target="_blank"&gt;Feet-Inch Calculator &lt;/A&gt;&lt;SPAN style="font-family: Arial,sans-serif; text-shadow: auto;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;A href="https://apps.exchange.autodesk.com/ACD/en/Detail/Index?id=appstore.exchange.autodesk.com%3alayerapps_windows32and64%3aen" target="_blank"&gt;Layer Apps&lt;/A&gt; | &lt;A href="https://apps.exchange.autodesk.com/ACD/en/Detail/Index?id=appstore.exchange.autodesk.com%3addlist_windows32and64%3aen" target="_blank"&gt;List on Steroids&lt;/A&gt; | &lt;A href="https://apps.exchange.autodesk.com/ACD/en/Detail/Index?id=appstore.exchange.autodesk.com%3addzmscl_windows32and64%3aen" target="_blank"&gt;VP Zoom Scales&lt;/A&gt; | &lt;A href="https://apps.exchange.autodesk.com/ACD/en/Home/Index" target="_blank"&gt;Exchange App Store&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 23:01:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/viewport-with-specific-scale/m-p/8183814#M101318</guid>
      <dc:creator>paullimapa</dc:creator>
      <dc:date>2018-08-07T23:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Viewport with specific scale</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/viewport-with-specific-scale/m-p/8184152#M101319</link>
      <description>&lt;P&gt;Thank you Pli!&lt;BR /&gt;I will be trying out you suggestions. I will have to tweak the step to zoom in the rectangle in model space because we have a palette tool outside of the drawing area, and zoom all won't work.&lt;BR /&gt;I will come back once I have some time to give it another try, hopefully to post the solution.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2018 05:39:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/viewport-with-specific-scale/m-p/8184152#M101319</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-08-08T05:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: Viewport with specific scale</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/viewport-with-specific-scale/m-p/8187539#M101320</link>
      <description>&lt;P&gt;Hi, we have a similar process where I work.&amp;nbsp; Instead of a program creating the viewports, we have them defined in the templates.&amp;nbsp; That way they are always centered when you use the template.&amp;nbsp; Then it's just a matter of scaling the viewport.&amp;nbsp; Here is some code to find the viewport to change its scale.&amp;nbsp; We put our viewports on layer "Viewport", so that's what it looks for (there are usually 2 viewports that it will find, even if you only created one in your template).&lt;/P&gt;&lt;P&gt;We call our layouts "P1", "P2", ... so layoutNum is the tab.&lt;/P&gt;&lt;PRE&gt;(setvar "ctab" (vla-get-name layoutNum)) ;"P2", "P3", "P4"....
    ;--- Change Viewport Scale ---
    ;Create a selection set of the viewports on the current layout tab only
    (setq vpSS (ssget "X" (list '(0 . "VIEWPORT")(cons 410 (getvar "ctab")))))
    (setq vpCounter 0)
    (while (&amp;lt; vpCounter (sslength vpSS))
     ;Make sure you have the correct viewport (the one on layer "VIEWPORT")
     (setq vpLayer (cdr (assoc 8 (entget (ssname vpSS vpCounter)))))
     (if (= vpLayer "VIEWPORT")
      ;Set the scale of the viewport to 1:1
      (vla-put-customscale (vlax-ename-&amp;gt;vla-object (ssname vpSS vpCounter)) 1.0)
     ) ;ends if
     (setq vpCounter (+ vpCounter 1))
    ) ;ends while&lt;/PRE&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2018 22:34:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/viewport-with-specific-scale/m-p/8187539#M101320</guid>
      <dc:creator>mgorecki</dc:creator>
      <dc:date>2018-08-08T22:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Viewport with specific scale</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/viewport-with-specific-scale/m-p/8279772#M101321</link>
      <description>&lt;P&gt;Pli's solution was good! For future references I will paste my code for the whole sequence.&lt;/P&gt;&lt;PRE&gt;    (defun VP ();Main function
        ;;DECLARING SUB-FUNCTIONS

        ;GETATT finds the scale of the drawing
        (defun GETATT ()
            (setq att_tag "SCALE");attribute that defines scale
            (setq blkname "TITLE-L1");block that holds the attribute
            (if (and(/= blkname nil) (/= att_tag nil))
                (progn  
                    (ssget "x" (list '(0 . "INSERT") (cons 2 (strcat blkname ",`*U*")) '(66 . 1)));select block
                    (vlax-for item (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
                        (if (eq (strcase blkname) (strcase (vla-get-effectivename item)));(dynamic blocks when modified change their names)
                            (foreach att (vlax-safearray-&amp;gt;list (vlax-variant-value (vla-getattributes item)));look for attributes inside of block
                                (if (= (strcase att_tag) (vla-get-tagstring att)) (setq scl-txt (vla-get-textstring att)));save scale value from attribute
                            );;foreach
                        );;if
                    )
                );;progn
            );;if/=
        );End of GETATT
        ;;-------------------------------------------------------------------------


        ;ZOOMVP will zoom to the drawing area defined by the chosen paper size 
        (defun ZOOMVP ()

            (if (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 PS))));select block PS (eg. 18x24)
                (progn
                    (COMMAND "ZOOM" "OBJECT" ss "");zoom to the object
                )
            )        
        );End of ZOOMVP
        ;;----------------------------------------------------------------

        (defun VPSC ();VPSC Sets up viewport scale with the values got in GETATT
        (if (= MS "IMP")
            (progn
                (setq scl-lst (list "1'-0\"=1'-0\"" "6\"=1'-0\"" "3\"=1'-0\"" "1 1/2\"=1'-0\"" "1\"=1'-0\"" "3/4\"=1'-0\"" "1/2\"=1'-0\"" "3/8\"=1'-0\"" "1/4" "3/16\"=1'-0\"" "1/8\"=1'-0\"" "3/32\"=1'-0\"" "1/16\"=1'-0\"" "1/32\"=1'-0\"" "1/64\"=1'-0\"" "1/128\"=1'-0\""))
                (setq zm-lst (list "1xp" "1/2xp" "1/4xp" "1/8xp" "1/12xp" "1/16xp" "1/24xp" "1/32xp" "1/48xp" "1/64xp" "1/96xp" "1/128xp" "1/192xp" "1/384xp" "1/768xp" "1/1536xp"))
            )
            (progn
                (setq scl-lst (list "1:1" "1:2" "1:5" "1:10" "1:20" "1:25" "1:50" "1:75" "1:100" "1:125" "1:150" "1:200" "1:250" "1:300" "1:500" "1:1000" ))
                (setq zm-lst (list "1xp" "1/2xp" "1/5xp" "1/10xp" "1/20xp" "1/25xp" "1/50xp" "1/75xp" "1/100xp" "1/125xp" "1/150xp" "1/200xp" "1/300xp" "1/500xp" "1/1000xp"))
            )
        )

        (if(setq match (member scl-txt scl-lst))
            (progn ; if matching scale pattern found
                (setq match-len (- (length scl-lst)(length match))) ; find position in the scale list
                (setq zmfac(nth match-len zm-lst)) ; get the matching zoom factor position from the zoom list
                (command"_.ZOOM" zmfac)
            )
            (princ"\nNo Matching Scale Found")
        )
        );end VPSC
        ;;--------------------------------------------------------------------


        ;MAIN FUNCTION
        (if (setq VPSELECT (ssget "_X" '((0 . "VIEWPORT"))));select viewport (already created in template)
           (progn
               (setq d (vla-get-activedocument (vlax-get-acad-object)))
               (vla-put-mspace d :vlax-true);step into viewport
            )
        )

        (GETATT)
        (ZOOMVP)
        (VPSC)
        (vla-put-mspace d :vlax-false);step out of viewport
        (COMMAND "ZOOM" "E")
        (command "mview" "l" "ON" VPSELECT "") ;lock viewport
        (princ)
    );end of VP&lt;/PRE&gt;&lt;P&gt;This code is part of a bigger script, so it it missing the&lt;/P&gt;&lt;PRE&gt;(defun &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;C:&lt;/FONT&gt;&lt;/STRONG&gt;VPSC ()&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Sep 2018 22:45:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/viewport-with-specific-scale/m-p/8279772#M101321</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-09-19T22:45:00Z</dc:date>
    </item>
  </channel>
</rss>

