Jump to content

Can't get verticies of viewport


alm865

Recommended Posts

So, this is a weird problem.

 

I can't get the vertices of the polyline that makes up a non-rectangular viewport. To replicate my problem, start with a rectangular viewport, rotate it in the paper space and move one of it's vertices. Now for some reason property number 340 is not the polyline that makes up the viewport.

 

I was originally using lee-mac's 'vpoutline' lisp script (can't add link since I'm a newbie) to draw an outline of the viewport but that doesn't even work (if lee-mac's script can't work it out then something is very wrong!!)

 

As you can see on the left is the viewport. Prop 340 should be the pline. Go into the pline and it has no vertices (middle)!

 

On the right and bottom are me finding the correct pline a different way (not programmatically) and the vertices are all there and indeed correct.

 

attachment.php?attachmentid=58948&cid=1&stc=1

To be very clear, if you draw a polygonal viewport from scratch everything is fine, that's not my problem. This only applies to a rectangular viewport you have rotated and moved one of it's vertices.

 

So how do I get the vertices of the pline that makes up the viewport?

 

 

 

 

Untitled.jpg

Edited by alm865
Link to comment
Share on other sites

Here is an example of a viewport that I am referring to.

 

It appears polygonal until you try and get the pline details. Something just isn't right and I can't work it out... I'm hoping I'm doing something silly and someone can point out what I have missed.

 

Please try the 'vpoutline' lisp script from lee-mac's website for a starting point.

 

(not the same drawing as above by the way so the entity names are going to be different. Sorry)

 

Drawing1.dwg

Edited by alm865
Link to comment
Share on other sites

For some strange reason the polyline is an "AcDb2dPolyline" and not an "AcDbPolyline". The vertices for an "AcDb2dPolyline" are stored as separate entities which is why you do not see them in the entity list.

For the first vertex:

(entget (entnext (car (entsel))))

Link to comment
Share on other sites

Awesome! That works. Thanks for the help.

 

It's an easy enough check too to see if it's a "AcDb2dPolyline" or a normal "AcDbPolyline".

 

This has been doing my head in for a while now. Thanks again.

Link to comment
Share on other sites

For anyone looking to make lee-mac's 'vpoutline.lsp' work for these weird viewports, download lee-mac's script from his webpage then change this function:

 


(defun c:vpo ( / *error* _lwvertices cen ent lst ocs vpe vpt vpt2)

   (defun *error* ( msg )
       (LM:endundo (LM:acdoc))
       (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )

   (LM:startundo (LM:acdoc))
   (cond
       (   (/= 1 (getvar 'cvport))
           (princ "\nCommand not available in Modelspace.")
       )
       (   (setq vpt (LM:ssget "\nSelect viewport: " '("_+.:E:S" ((0 . "VIEWPORT")))))
           
       (setq vpt2 (ssname vpt 0))
       (setq vpt (entget vpt2))
           (if (setq ent (cdr (assoc 340 vpt)))
         (progn
       (if (member '(100 . "AcDb2dPolyline") (entget ent))
         (progn
                       (setq lst (vpo:lw2dvertices (entnext vpt2)))
           )
         (progn
                   (setq lst (vpo:lwvertices (entget ent)))
           )
         )
         )
         (progn
       (setq cen (mapcar 'list (cdr (assoc 10 vpt))
                             (list
                                 (/ (cdr (assoc 40 vpt)) 2.0)
                                 (/ (cdr (assoc 41 vpt)) 2.0)
                             )
                         )
                     lst (mapcar
                            '(lambda ( a ) (cons (mapcar 'apply a cen) '(42 . 0.0)))
                            '((- -) (+ -) (+ +) (- +))
                         )
       )
         )
           )
           (setq vpe (cdr (assoc -1 vpt))
                 ocs (cdr (assoc 16 vpt))
           )
           (entmake
               (append
                   (list
                      '(000 . "LWPOLYLINE")
                      '(100 . "AcDbEntity")
                      '(100 . "AcDbPolyline")
                       (cons 90 (length lst))
                      '(070 . 1)
                      '(410 . "Model")
                   )
                   (apply 'append
                       (mapcar
                          '(lambda ( x )
                               (list (cons 10 (trans (pcs2wcs (car x) vpe) 0 ocs)) (cdr x))
                           )
                           lst
                       )
                   )
                   (list (cons 210 ocs))
               )
           )
       )
   )
   (LM:endundo (LM:acdoc))
   (princ)
)

 

... and add in this extra function:

 


(defun vpo:lw2dvertices ( e / ent)
 (setq ent e)
 (setq e (entget e))
 (if (eq (assoc 42 e) nil)
      (progn
    ;;For whatever reason the first vertex is not to be used
       (if (setq e (member (assoc 10 e) e))
       (vpo:lw2dvertices (entnext ent))
       )
    )
   (progn
       (if (setq e (member (assoc 10 e) e))
           (cons
               (cons (cdr (assoc 10 e)) (assoc 42 e))
               (vpo:lw2dvertices (entnext ent))
           )
       )

     )

 )
)

 

It's an ugly hack but works. Thanks lee-mac for the original example BTW.

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...