• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Visual LISP, AutoLISP and General Customization

    Reply
    Valued Contributor
    Posts: 61
    Registered: ‎03-21-2009

    Re: Polyline Vertex Counter

    07-30-2011 04:20 PM in reply to: azrdgldr

    Ah ha, mleaderstyle...  thanks

    Steve

    Please use plain text.
    Distinguished Contributor
    Posts: 114
    Registered: ‎03-12-2004

    Re: Polyline Vertex Counter

    07-30-2011 04:37 PM in reply to: _Tharwat

    Great tool, works perfectly.

     

    As it happens i'm using AutoCAD 2011 64bit, it's probably the 64bit that stopped the original solution. I've been trying to learn VBSCRIPT, it took me a week to just get it to debug on a 64bit machine, nobody said the language had changed.

     

    Thankyou so much for your time.

    Creative Intentions
    AutoCAD Certified Professional
    Win 7 Pro 64bit, Dell Precision M6500
    Please use plain text.
    Valued Mentor
    Posts: 308
    Registered: ‎12-29-2009

    Re: Polyline Vertex Counter

    07-30-2011 04:51 PM in reply to: GegH1

    GegH1,

     

    You received the error because the Visual LISP extensions hadn't been loaded with (vl-load-com).

     

    Most users include this in their ACADDOC.lsp so that the Visual LISP functions are always available for programs that use them. This function only need be called once per drawing session to ensure the Visual LISP extensions are available throughout the session, which makes more sense than calling the function for each loaded program.

     

    Another way to approach it:

     

    (defun c:test ( / e s p )
        (if (setq s (ssget '((0 . "*POLYLINE"))))
            (while (setq e (ssname s 0))
                (vl-cmdf "_.mleader" "_non"
                    (setq p (trans (vlax-curve-getendpoint e) 0 1)) "_non"
                    (polar p (/ pi 4.) (* 4 (getvar 'DIMTXT)))
                    (itoa (1+ (fix (vlax-curve-getendparam e))))
                )
                (ssdel e s)
            )
        )
        (princ)
    )
    (vl-load-com)

     

    Lee Mac Programming
    With Mathematics there is the possibility of perfect rigour, so why settle for less?
    Just another Swamper
    Please use plain text.
    Distinguished Contributor
    Posts: 114
    Registered: ‎03-12-2004

    Re: Polyline Vertex Counter

    07-30-2011 06:23 PM in reply to: stevesfr

    Lee,

    Thanks for that, The code seems a lot shorter.

    It constantly amaizes me how many ways there are to skin a Cat in AutoCAD.

     

     

    Creative Intentions
    AutoCAD Certified Professional
    Win 7 Pro 64bit, Dell Precision M6500
    Please use plain text.
    Valued Mentor
    _Tharwat
    Posts: 460
    Registered: ‎07-02-2010

    Re: Polyline Vertex Counter

    07-31-2011 12:48 AM in reply to: Lee_Mac

    Lee .

     

    Your routine would consider the rectanle LWpolyline ( square shapes ) as five points . :smileywink:

     

    Tharwat

    Please use plain text.
    Valued Mentor
    Posts: 308
    Registered: ‎12-29-2009

    Re: Polyline Vertex Counter

    07-31-2011 04:36 AM in reply to: _Tharwat

    @ GegH1,

     

    You're very welcome :smileyhappy:

     

    There are indeed many ways to approach the same problem with AutoCAD, especially since the drawing database can be accessed using both Vanilla AutoLISP and Visual LISP, providing effectively two interfaces for most entities. Of course, some things are easier manipulated using Vanilla (such as dictionaries), whilst others are only possible through VL.

     

    @ Tharwat,

     

    Good spot :smileywink:  This is because my code uses the value End Parameter (since the vertices of a Polyline have integer parameter values), however, my code didn't consider a closed polyline wherein the endpoint and startpoint are coincident.

     

    This should fix that problem:

     

    (defun c:test ( / e s p )
        (if (setq s (ssget '((0 . "*POLYLINE"))))
            (while (setq e (ssname s 0))
                (vl-cmdf "_.mleader" "_non"
                    (setq p (trans (vlax-curve-getendpoint e) 0 1)) "_non"
                    (polar p (/ pi 4.) (* 4 (getvar 'DIMTXT)))
                    (itoa (+ (fix (vlax-curve-getendparam e)) (if (vlax-curve-isclosed e) 0 1)))
                )
                (ssdel e s)
            )
        )
        (princ)
    )
    (vl-load-com)

     

    Also, you might want to consider UCS for your code :smileywink:

    Lee Mac Programming
    With Mathematics there is the possibility of perfect rigour, so why settle for less?
    Just another Swamper
    Please use plain text.
    Valued Mentor
    _Tharwat
    Posts: 460
    Registered: ‎07-02-2010

    Re: Polyline Vertex Counter

    07-31-2011 04:47 AM in reply to: Lee_Mac

     

     

     


    Lee_Mac wrote:

    Also, you might want to consider UCS for your code :smileywink:


    Yeah ... that's right .

     

    (**** for tat) :smileyvery-happy:

     

    Thanks

     

    Please use plain text.
    Valued Mentor
    Posts: 308
    Registered: ‎12-29-2009

    Re: Polyline Vertex Counter

    07-31-2011 05:03 AM in reply to: _Tharwat

    :smileywink:

    Lee Mac Programming
    With Mathematics there is the possibility of perfect rigour, so why settle for less?
    Just another Swamper
    Please use plain text.