Help with lisp

Help with lisp

Anonymous
Not applicable
891 Views
7 Replies
Message 1 of 8

Help with lisp

Anonymous
Not applicable

I have created a routine that stores the vertices of a pline and creates a string of the coordinates. However, i cannot figure out how to add a circle at each of the vertices in the string. Any help would be greatly appreciated below is my code so far:

 

(defun c:somefunc (/ i n vlaobj)
(command "._pline")
(while (/= 0 (getvar 'cmdactive)) (command pause))
(print
(setq lst (reverse (cdr (reverse (vl-remove-if-not 'listp (mapcar 'cdr (entget (entlast)))))))))
(setq vlaobj (vlax-ename->vla-object (entlast))
i 1
n (vlax-curve-getendparam vlaobj))
(while (<= i n) (setq l (vlax-curve-getdistatparam vlaobj i)) (setq i (1+ i))))

0 Likes
Accepted solutions (2)
892 Views
7 Replies
Replies (7)
Message 2 of 8

DannyNL
Advisor
Advisor

You might be over complicating things.

You can filter the vertices (DXF code 10) directly from the entity list and use these as points for your circle.

 

In this example I've set the radius of the circles to 5.

 

(defun c:somefunc (/ lst)
   (command "._pline")
   (while (/= 0 (getvar 'cmdactive)) (command pause))
   
   (setq lst (vl-remove-if-not '(lambda (item) (= (car item) 10)) (entget (entlast))))
   (mapcar '(lambda (pt) (command "_CIRCLE" (cdr pt) 5)) lst)
   
   (princ)
)

 

0 Likes
Message 3 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

Or [untested]:

 

(defun c:somefunc (/ n pl)
  (command "._pline")
  (while (/= 0 (getvar 'cmdactive)) (command pause))
  (repeat (setq n (+ (fix (vlax-curve-getEndParam (setq pl (entlast)))) (if (vlax-curve-isClosed pl) 0 1)))

;; EDIT: fixed something in the line above

    (command "_.circle" "_none" (vlax-curve-getPointAtParam pl (setq n (1- n))) 5)

  )

)

Kent Cooper, AIA
0 Likes
Message 4 of 8

Anonymous
Not applicable

sorry i am new to all of this visual lisp coding. Why can i not add the underline in? It messes it around and puts some mtext files at some of the vertices and some of the circles at the others.

 

(defun c:somefunc (/ n pl)
(command "._pline")
(while (/= 0 (getvar 'cmdactive)) (command pause))
(repeat (setq n (+ (fix (vlax-curve-getEndParam (setq pl (entlast)))) (if (vlax-curve-isClosed pl) 0 1)))
(command "_.circle" "_none" (vlax-curve-getPointAtParam pl (setq n (1- n))) 5)

 

(command "mtext" (vlax-curve-getPointAtParam pl (setq n (1- n))) "w" "100" "any text" "")


)
)

0 Likes
Message 5 of 8

DannyNL
Advisor
Advisor

Do you have any running objects snaps which are messing things up?

 

Try

(command "mtext" "_none" (vlax-curve-getPointAtParam pl (setq n (1- n))) "w" "100" "any text" "")
0 Likes
Message 6 of 8

Anonymous
Not applicable

Hi, 

I have tried it with snaps off and on now and it will do exactly the same. adding "_none" didn't do anything... 

 

if i draw 2 plines and therefore 3 vertices. it will draw circles at the first and last vertices and put an mtext in the centre. i think it might be when it runs through the coordinate list when it gets confused. there are loads of errors that crop up when i run the lisp routine

0 Likes
Message 7 of 8

DannyNL
Advisor
Advisor
Accepted solution

That's because you change n multiple times and the circle and mtext use different points.

Just set n with the circle and use the same n at the mtext.

 

(defun c:somefunc (/ n pl)
   (command "._pline")
   (while (/= 0 (getvar 'cmdactive)) (command pause))
   (repeat (setq n (+ (fix (vlax-curve-getEndParam (setq pl (entlast))))
                      (if (vlax-curve-isClosed pl)
                         0
                         1
                      )
                   )
           )
      (command "_.circle" "_none" (vlax-curve-getPointAtParam pl (setq n (1- n))) 5)

      (command "mtext" "_none" (vlax-curve-getPointAtParam pl n) "w" "100" "any text" "")

   )
)
0 Likes
Message 8 of 8

john.uhden
Mentor
Mentor

That would be correct if PLINETYPE were not 0.  But the vlax-curve functions work the same for both heavies and lights.

John F. Uhden

0 Likes