Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Valued Contributor
stevesfr
Posts: 67
Registered: ‎03-21-2009
Message 11 of 18 (369 Views)

Re: Polyline Vertex Counter

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

Ah ha, mleaderstyle...  thanks

Steve

Distinguished Contributor
GegH1
Posts: 119
Registered: ‎03-12-2004
Message 12 of 18 (368 Views)

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
*Expert Elite*
Lee_Mac
Posts: 1,138
Registered: ‎12-29-2009
Message 13 of 18 (365 Views)

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 ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Distinguished Contributor
GegH1
Posts: 119
Registered: ‎03-12-2004
Message 14 of 18 (357 Views)

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
Distinguished Mentor
_Tharwat
Posts: 599
Registered: ‎07-02-2010
Message 15 of 18 (348 Views)

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

____________________________________________________
Get learn and learn and practice , to become experienced guy .
*Expert Elite*
Lee_Mac
Posts: 1,138
Registered: ‎12-29-2009
Message 16 of 18 (337 Views)

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 ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Distinguished Mentor
_Tharwat
Posts: 599
Registered: ‎07-02-2010
Message 17 of 18 (334 Views)

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

 

____________________________________________________
Get learn and learn and practice , to become experienced guy .
*Expert Elite*
Lee_Mac
Posts: 1,138
Registered: ‎12-29-2009
Message 18 of 18 (329 Views)

Re: Polyline Vertex Counter

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

:smileywink:

Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)
Expert Elite
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.