Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
GegH1
Posts: 119
Registered: ‎03-12-2004
Message 1 of 18 (1,706 Views)
Accepted Solution

Polyline Vertex Counter

1706 Views, 17 Replies
07-29-2011 10:50 PM

I am looking to create a utility that will count the vertices of a polyline and display the number in the form of a multileader attached to the last vertex, Maybe with the ability to add a code to the multileader by way of an attribute.

 

The reason for this is that at every vertex there will be a block depicting a tree, the code will identify the tree type, a schedule will then pick up the tree type and numbers & add them together to give me a tree schedule.

 

Can anyone help with this, i don't have much experience with lisp but i am keen to learn.

Creative Intentions
AutoCAD Certified Professional
Win 7 Pro 64bit, Dell Precision M6500
Distinguished Mentor
_Tharwat
Posts: 580
Registered: ‎07-02-2010
Message 2 of 18 (1,702 Views)

Re: Polyline Vertex Counter

07-30-2011 12:02 AM in reply to: GegH1

Can you please upload an image of your desired result ?

 

What is the scale of your drawing ?

 

Thanks.

 

Tharwat

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Distinguished Contributor
GegH1
Posts: 119
Registered: ‎03-12-2004
Message 3 of 18 (1,694 Views)

Re: Polyline Vertex Counter

07-30-2011 03:38 AM in reply to: _Tharwat

Tharwat,

Thankyou for your response.

 

Attached is an image of what i am looking to achieve.

The scale i work at is 1:1 in millimetres. Generally the output is 1:100 in paperspace

Creative Intentions
AutoCAD Certified Professional
Win 7 Pro 64bit, Dell Precision M6500
Distinguished Mentor
_Tharwat
Posts: 580
Registered: ‎07-02-2010
Message 4 of 18 (1,691 Views)

Re: Polyline Vertex Counter

07-30-2011 03:55 AM in reply to: GegH1

Hope this what you mean .

 

(defun c:Test (/ spc e l p1 p2 led)
; Tharwat 30. 07. 2011
(vl-load-com) (setq spc (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)) ) ) (if (and (setq e (car (entsel "\n Select a Polyline :"))) (member (cdr (assoc 0 (entget e))) '("LWPOLYLINE" "POLYLINE") ) ) (progn (setq l (/ (length (vlax-get (vlax-ename->vla-object e) 'Coordinates)) 2 ) ) (setq p1 (vlax-curve-getendpoint e)) (setq p2 (polar p1 0.785398 1.0)) (setq led (vlax-invoke spc 'Addmleader (append p1 p2) 0)) (vla-put-textstring led (itoa l)) ) (princ "\n Missed the entity or it's not a Polyline !! ") ) (princ) )

 Tharwat

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Distinguished Contributor
GegH1
Posts: 119
Registered: ‎03-12-2004
Message 5 of 18 (1,685 Views)

Re: Polyline Vertex Counter

07-30-2011 04:49 AM in reply to: _Tharwat

That was quick. Thankyou.

 

I seem to get the following error though?

 

Command: test
; error: no function definition: VLAX-GET-ACAD-OBJECT

Creative Intentions
AutoCAD Certified Professional
Win 7 Pro 64bit, Dell Precision M6500
*Expert Elite*
Kent1Cooper
Posts: 5,267
Registered: ‎09-13-2004
Message 6 of 18 (1,682 Views)

Re: Polyline Vertex Counter

07-30-2011 04:58 AM in reply to: _Tharwat

TharwaT313 wrote:

.....

(if

  (and

    (setq e (car (entsel "\n Select a Polyline :")))

    (member (cdr (assoc 0 (entget e))) '("LWPOLYLINE" "POLYLINE"))

  )

  (progn

    (setq l

      (/

        (length (vlax-get (vlax-ename->vla-object e) 'Coordinates))

        2

      )

    )

....


For "heavy" Polylines [2D or 3D], the 'Coordinates VLA Property lists all three XYZ coordinates for each vertex.  So if you might have that kind of Polyline, I think you would need to either:

A.  use an (if) function to make that divisor 3 if it's a "POLYLINE" and 2 if it's a "LWPOLYLINE"; or

B.  use some other method of finding the number of vertices instead, such as this, which works for any Polyline type:

 

(if

  (and

    (setq e (car (entsel "\n Select a Polyline :")))

    (member (cdr (assoc 0 (entget e))) '("LWPOLYLINE" "POLYLINE"))

  )

  (progn

    (setq l (1+ (fix (vlax-curve-getEndParam e))))

....

 

On the other hand, if you would never encounter "heavy" Polylines, test for only the "LWPOLYLINE" entity type, and just divide the 'Coordinates VLA Property by 2, or take another approach such as this:

 

    (setq l (cdr (assoc 90 (entget e))))

Kent Cooper
Distinguished Mentor
_Tharwat
Posts: 580
Registered: ‎07-02-2010
Message 7 of 18 (1,658 Views)

Re: Polyline Vertex Counter

07-30-2011 10:03 AM in reply to: GegH1

Hi Geg .

 

You may have old version of Autocad so that's why the routine did not work for you .

 

Anyway here is another way of coding and with the same result .

 

(defun c:Test (/ e l p1 p2)
 ; Tharwat 30. 07. 2011
  (vl-load-com)
  (if
    (and
      (setq e (car (entsel "\n Select a Polyline :")))
      (member (cdr (assoc 0 (entget e)))
              '("LWPOLYLINE" "POLYLINE")
      )
    )
     (progn
       (if (eq (vla-get-objectname (vlax-ename->vla-object e))
               "AcDb3dPolyline"
           )
         (setq l
                (/ (length (vlax-get (vlax-ename->vla-object e) 'Coordinates))
                   3
                )
         )
         (setq l
                (/ (length (vlax-get (vlax-ename->vla-object e) 'Coordinates))
                   2
                )
         )
       )
       (setq p1 (vlax-curve-getendpoint e))
       (setq p2 (polar p1 0.785398 1.0))
       (command "_.mleader" "_non" p1 "_non" p2 (itoa l))
     )
     (princ "\n Missed the entity or it's not a Polyline !! ")
  )
  (princ)
)

 Tharwat

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Distinguished Mentor
_Tharwat
Posts: 580
Registered: ‎07-02-2010
Message 8 of 18 (1,657 Views)

Re: Polyline Vertex Counter

07-30-2011 10:10 AM in reply to: Kent1Cooper

Thanks Kent .

 

I do understand what you mean and I would consider that your idea is another way of counting vertices and both are

working perfectely .

 

Tharwat

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Valued Contributor
stevesfr
Posts: 67
Registered: ‎03-21-2009
Message 9 of 18 (1,651 Views)

Re: Polyline Vertex Counter

07-30-2011 01:57 PM in reply to: Kent1Cooper

what part of the code determines the size of the mleader... it is being shown very tiny and I can't figure out what part of the code addresses the size of the mleader and text.

TIA

Steve

*Expert Elite*
azrdgldr
Posts: 1,250
Registered: ‎01-09-2007
Message 10 of 18 (1,645 Views)

Re: Polyline Vertex Counter

07-30-2011 02:41 PM in reply to: stevesfr

Hey Stevesfr, none of the code.  Your current settings of your multileader style determines that.  Adjust your settings to your current style and try again

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

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 to get help installing your software.

Ask the Community