Jump to content

Viewport Checker


Mostly Nice

Recommended Posts

Gents,

 

I'm sure ive seen this somewhere, a viewport checker?

 

In short, i'm working with muli-sheet dwg's (new to me) and ending up with between 25 - 150 per dwg. The process we're using to create individual sheets resets the viewport to a scale regardless of viewport lock.

 

I'm training a lad at the moment with this process and to ensure he doesn't miss a viewport, i have to check them. Problem is, he may have done 200 before i get a chance to check.

 

So my query is; is there a lisp routine that will check all sheets viewports against a set standard? say 1:1, 1:5, 1:10, 1:20, 1:25 & 1:50? :?

 

If you've read the above, you'll understand this could save me days & weeks of work, and as such, will owe you a drink! :wink:

 

Regards,

Nice, Mostly.

Link to comment
Share on other sites

Am I correct in my understanding that you have multiple tabs (Layouts) within a single drawing, and you want to 'check' each tab's(Layout's) viewport(s) against a specified scale?

Link to comment
Share on other sites

This might get things started...

 

(defun _vpScales (/ _scale ss i e a n l)

 (defun _scale (e) (/ 1. (vla-get-customscale (vlax-ename->vla-object e))))

 (if (setq ss (ssget "_X" '((0 . "VIEWPORT") (-4 . ">") (69 . 1))))
   (vl-sort
     (repeat (setq i (sslength ss))
       (if
         (setq a (assoc (setq n (cdr (assoc 410 (entget (setq e (ssname ss (setq i (1- i)))))))) l))
          (setq l (subst (cons n (cons (_scale e) (cdr a))) a l))
          (setq l (cons (list n (_scale e)) l))
       )
     )
     '(lambda (a b) (< (car a) (car b)))
   )
 )
)

Link to comment
Share on other sites

This might get things started...

 

](defun _vpScales (/ _scale ss i e a n l)

 (defun _scale (e) (/ 1. (vla-get-customscale (vlax-ename->vla-object e))))

 (if (setq ss (ssget "_X" '((0 . "VIEWPORT") (-4 . ">") (69 . 1))))
   (vl-sort
     (repeat (setq i (sslength ss))
       (if
         (setq a (assoc (setq n (cdr (assoc 410 (entget (setq e (ssname ss (setq i (1- i)))))))) l))
          (setq l (subst (cons n (cons (_scale e) (cdr a))) a l))
          (setq l (cons (list n (_scale e)) l))
       )
     )
     '(lambda (a b) (< (car a) (car b)))
   )
 )
)

 

~Nice job :)

 

Great usage of (-4 . "

 

In order to step outside my dependance on selection sets, my attempt steps through the Block Object for each Layout Item:

 

(defun c:VPS () (c:VPSCALES))
(defun c:VPSCALES ()
 (princ "\rVIEWPORT SCALES ")
 (vl-load-com)
 ((lambda (layouts / activeDoc oLayouts)
   (foreach lay layouts
     (vlax-for x (vla-get-block
                   (vla-item
                     (cond (oLayouts)
                           ((setq oLayouts
                                   (vla-get-layouts
                                     (setq activeDoc
                                            (vla-get-activedocument
                                               (vlax-get-acad-object)))))))
                     lay))
       (if (and
             (= "AcDbViewport" (vla-get-objectname x))
             ;|
             (= :vlax-true
                (vla-get-hasextensiondictionary
                  (vla-objectidtoobject activeDoc (vla-get-objectid x))))
             |;     
             (/= "0" (vla-get-layer x))
             )
         (prompt
           (strcat "\n  >>  Layout: \""
                   lay
                   "\"  >>  Viewport Scale: \"1:"
                   (rtos (/ 1. (vla-get-customscale x)) 2 4)
                   "\""))))))
   (layoutlist))
 (princ)) 

 

... However, I don't remember how I properly accounted for the Layout's Viewport itself using this method, (I think it had to do with vla-ObjectIdToObject ...)? In any event, my offering assumes that the user does not place viewports on the zero "0" layer.

Link to comment
Share on other sites

Works for me. Out of curiosity, why the aversion to using a selection set?

 

No aversion... I simply rely on them for nearly everything, which isn't to say that's even a bad thing.

 

Perhaps it's part of my beginning to code in C# & VB.NET, that I am making the attempt to learn how to do things (even in LISP) outside of my comfort zone. The caveat being, of course, if it's for production then I'm going to use whatever is easiest for me so long as the API can accomplish the task. LoL

 

... More of a personal challenge than anything else. :geek:

Link to comment
Share on other sites

No aversion... I simply rely on them for nearly everything, which isn't to say that's even a bad thing.

 

Perhaps it's part of my beginning to code in C# & VB.NET, that I am making the attempt to learn how to do things (even in LISP) outside of my comfort zone. The caveat being, of course, if it's for production then I'm going to use whatever is easiest for me so long as the API can accomplish the task. LoL

 

... More of a personal challenge than anything else. :geek:

Right on.................

Link to comment
Share on other sites

In order to step outside my dependance on selection sets, my attempt steps through the Block Object for each Layout Item:

 

(defun c:VPSCALES ()

.. <snip> ..

Hi Renderman,

 

I would be inclined to approach it in the following way:

 

([color=BLUE]defun[/color] VPScales ( doc [color=BLUE]/[/color] _assoc++ lay lst pvp )

[color=darkgreen]    ;; Call the function with a VLA Document Object
   ;; whether it be the Active Document or through an ObjectDBX Interface[/color]

   ([color=BLUE]defun[/color] _assoc++ ( key value alist [color=BLUE]/[/color] item )
       ([color=BLUE]if[/color] ([color=BLUE]setq[/color] item ([color=BLUE]assoc[/color] key alist))
           ([color=BLUE]subst[/color] ([color=BLUE]cons[/color] key ([color=BLUE]cons[/color] value ([color=BLUE]cdr[/color] item))) item alist)
           ([color=BLUE]cons[/color]  ([color=BLUE]list[/color] key value) alist)
       )
   )
   
   ([color=BLUE]vlax-for[/color] layout ([color=BLUE]vla-get-layouts[/color] doc)
       ([color=BLUE]setq[/color] lay ([color=BLUE]vla-get-name[/color] layout)
             pvp [color=BLUE]nil[/color]
       )
       ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]eq[/color] [color=MAROON]"MODEL"[/color] ([color=BLUE]strcase[/color] lay)))
           ([color=BLUE]vlax-for[/color] object ([color=BLUE]vla-get-block[/color] layout)
               ([color=BLUE]if[/color] ([color=BLUE]and[/color] pvp ([color=BLUE]eq[/color] [color=MAROON]"AcDbViewport"[/color] ([color=BLUE]vla-get-objectname[/color] object)))
                   ([color=BLUE]setq[/color] lst (_assoc++ lay ([color=BLUE]/[/color] 1. ([color=BLUE]vla-get-customscale[/color] object)) lst))
                   ([color=BLUE]setq[/color] pvp [color=BLUE]t[/color])
               )
           )
       )
   )
   ([color=BLUE]reverse[/color] lst)
)

[color=darkgreen];; Example to query the Active Document[/color]

([color=BLUE]defun[/color] c:VPS [color=BLUE]nil[/color]
   (VPScales ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])))
)
([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

... However, I don't remember how I properly accounted for the Layout's Viewport itself

 

In Vanilla AutoLISP you have the convenience of the DXF 69 flag as Alan has demonstrated in his code. However, with Visual LISP, to my knowledge, there isn't a property that sets the Paperspace Viewport object apart from other Viewports; so, as shown in my code, I use the fact that the Paperspace Viewport will always be the first object in the Layout Block Definition - not ideal, but it appears to work.

 

No aversion... I simply rely on them for nearly everything, which isn't to say that's even a bad thing.

 

Perhaps it's part of my beginning to code in C# & VB.NET, that I am making the attempt to learn how to do things (even in LISP) outside of my comfort zone.

 

Its definitely worthwhile having knowledge of how to create code with no dependence on SelectionSets, since this would be required should the function be used through an ObjectDBX interface. However, with regard to your code, I would be inclined to have the subfunction accept a Document Object to provide more versatility and compatibility with ObjectDBX.

 

My 2 cents.

Link to comment
Share on other sites

  • 12 years later...
On 6/23/2011 at 10:07 PM, alanjt said:

This might get things started...

 

 

(defun _vpScales (/ _scale ss i e a n l)

 (defun _scale (e) (/ 1. (vla-get-customscale (vlax-ename->vla-object e))))

 (if (setq ss (ssget "_X" '((0 . "VIEWPORT") (-4 . ">") (69 . 1))))
   (vl-sort
     (repeat (setq i (sslength ss))
       (if
         (setq a (assoc (setq n (cdr (assoc 410 (entget (setq e (ssname ss (setq i (1- i)))))))) l))
          (setq l (subst (cons n (cons (_scale e) (cdr a))) a l))
          (setq l (cons (list n (_scale e)) l))
       )
     )
     '(lambda (a b) (< (car a) (car b)))
   )
 )
)
 

 

Please help me, if there is some method to identify the viewport types(Plan, Profile, Section or Undefined) on all layouts and turn of some layers only inside the plan view of alignment sheets. thanks in advance.

Link to comment
Share on other sites

Only if the layout has some form of description, like an attribute in a title block "Cross Section" "Plan" etc. 

 

Why do you need it ? If you have by the info provided a good civil software the layouts will be created automatically with correct layers on, eg  CIV3D or "Civil Site Design".

Edited by BIGAL
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...