+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Junior Member
    Computer Details
    alm865's Computer Details
    Operating System:
    Windows 10
    Computer:
    Various
    Using
    AutoCAD 2017
    Join Date
    Jun 2016
    Location
    Australia
    Posts
    13

    Default Can't get verticies of viewport

    Registered forum members do not see this ad.

    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.




    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?




    Attached Images
    Last edited by alm865; 11th Aug 2016 at 12:48 pm.

  2. #2
    Junior Member
    Computer Details
    alm865's Computer Details
    Operating System:
    Windows 10
    Computer:
    Various
    Using
    AutoCAD 2017
    Join Date
    Jun 2016
    Location
    Australia
    Posts
    13

    Default

    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
    Last edited by alm865; 11th Aug 2016 at 12:52 pm.

  3. #3
    Senior Member
    Using
    not applicable
    Join Date
    Jun 2016
    Posts
    463

    Default

    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:
    Code:
    (entget (entnext (car (entsel))))
    BricsCAD 16

  4. #4
    Junior Member
    Computer Details
    alm865's Computer Details
    Operating System:
    Windows 10
    Computer:
    Various
    Using
    AutoCAD 2017
    Join Date
    Jun 2016
    Location
    Australia
    Posts
    13

    Default

    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.

  5. #5
    Junior Member
    Computer Details
    alm865's Computer Details
    Operating System:
    Windows 10
    Computer:
    Various
    Using
    AutoCAD 2017
    Join Date
    Jun 2016
    Location
    Australia
    Posts
    13

    Default

    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:

    Code:
    (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:

    Code:
    (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.

  6. #6
    Forum Deity David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    2,496

    Default

    There is also CONVERTPOLY that's been around for a long time. -David
    R12 (Dos) - A2K

  7. #7
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,260

    Default

    Thank you for bringing this issue to my attention - I have now updated my Viewport Outline program to account for this.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  8. #8
    Junior Member
    Computer Details
    alm865's Computer Details
    Operating System:
    Windows 10
    Computer:
    Various
    Using
    AutoCAD 2017
    Join Date
    Jun 2016
    Location
    Australia
    Posts
    13

    Default

    Thanks Lee Mac.

    You have some very impressive samples on your webpage! They've certainly helped me learn many things in Autolisp.

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,260

    Default

    Registered forum members do not see this ad.

    Thank you!
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. HELP: LISP to create multiple & resized viewport base on an existing viewport
    By vernonlee in forum AutoLISP, Visual LISP & DCL
    Replies: 31
    Last Post: 10th Jun 2015, 01:17 am
  2. Lisp routine for multiple polyline verticies to ascii
    By bsimpson in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 19th Jul 2010, 01:47 pm
  3. Replies: 4
    Last Post: 25th Feb 2009, 05:25 pm

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts