Jump to content

Polyline vertext - set "name" of every vertex- possible?


Recommended Posts

Posted

Hello everybody,

I want to define points in autolisp, like this: select a polyline, and the first vertex to be set as P1, the second vertex P2......and so on... vertex n to be Pn .... something possible? how? Any idea? Thanks!

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • flopo

    7

  • malkasun

    4

  • Stefan BMR

    2

  • Dipesh Kalasaria

    2

Posted

You can do this

(setq i 0)
(foreach n lst
 (set (read (strcat "P" (itoa (setq i (1+ i))))) n)
 )

... but, IMO, you can always use (nth n lst) when you need Pn value...

Posted (edited)

try this :

 

 

(defun c:test( / es ent str vtxlist c txtsize)
(defun make_TEXT (content textstyle layer color coo degree textsize / txt_list)
;;entmake text
 (if (null textstyle) (setq textstyle "standard"))
 (setq txt_list (list (cons 0 "TEXT") (cons 1 content) (cons 7 textstyle) (cons 8 layer) (cons 62 color) (cons 10 coo) (cons 50 degree) (cons 40 textsize)))  
 (entmake txt_list)
 (entlast)
)
(if (setq es (car (entsel "\nSelect Polyline >> ")))
 (progn
  (setq ent (entget es))
  (setq str "name");;;
  (setq vtxlist '())
  (mapcar '(lambda (x)
   (if (eq (car x) 10)
    (setq vtxlist (append vtxlist (list (cdr x))))
   )
           )
  ent);mapcar
  (setq c 1 txtsize 1)
  (foreach vtx vtxlist
   (make_text (strcat str (itoa c)) nil (getvar "clayer") 10 vtx 0 txtsize)
   (setq c (1+ c))
  )
 )
 (alert "CANCELED")
)
(princ)
)

Edited by SLW210
Place code in tags!!!
Posted

Hi Kraz,

I want to use P1 , P2...Pn to draw somethig else with them... shoult be somethig like polar function in autolisp, to define that point. To explain better, i want to draw lines from P1, P2...Pn to other points already defined with polar function - i don't need to add text in drawing for each vertex... i just want to set these points ...

Let's say i want to make a lisp that will draw vertical lines from every vertex of a polyline, perpendicular on a horizontal line - this is why i need P1, P2...Pn. I hope you understand me.

Thanks!

Posted

Now i use a lisp that need to select every vertex of a polyline to define P1, P2, ..Pn. And i want to define these points only by selecting that polyline...

Posted

I thought I answered your question in previous post but if you want more, here it is

 

(defun C:TEST ( / i ss)
 (if
   (setq i 0 ss (ssget ":E:S" '((0 . "LWPOLYLINE"))))
   (foreach n
     (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (ssname ss 0))))
     (set (read (strcat "P" (itoa (setq i (1+ i))))) n) ; - here you can draw a line like (entmakex (list '(0 . "LINE") (cons 10 n) (cons 11 some_point)))
   )
 )
)

However, I still think that your approach is wrong. You can draw those lines without setting (global) variables P1 ... Pn

Posted

You should be able to do what you're wanting (bigger picture) without declaring global variables... If you're going to use Visual LISP, then just go straight for the vlax-curve* functions (IMO). :wink:

Posted

Thanks Stefan it's exactly what i want... You are right, is not a good approach , but i already have a big lisp that use in many places P1, P2.... Thanks!

Posted
Thanks Stefan it's exactly what i want... You are right, is not a good approach , but i already have a big lisp that use in many places P1, P2.... Thanks!

So in the end of rountine, you should put

(repeat i
   (set (read (strcat "P" (itoa i))) nil )(setq i (1- i))
)

or sth similar to clear global variables ...

Posted

maybe

 

 
(defun c:test ( / e n )
 (while
   (not
     (and (setq e (car (entsel "\nSelect polyline: ")))
       (eq "LWPOLYLINE" (cdr (assoc 0 (setq e (entget e)))))
       (setq n 0)
     )
   )
 )
 (foreach x e
   (if (eq 10 (car x))
     (set 
       (read 
         (strcat "p" 
           (itoa 
             (setq n (1+ n))
           )
         )
       ) (cdr x)
     )
   )
 ) (princ)
)

Posted

" number of vertex is n=....15..... can you add something like this at the end of the lisp? To count the number of vertex...

Posted (edited)

As a lisper, can't you do it by yourself ? ^^ Hi hi.

Maybe like this ?

(defun C:TEST ( / i ss)
 (if
   (setq i 0 ss (ssget ":E:S" '((0 . "LWPOLYLINE"))))
   (progn 
   (foreach n
     (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (ssname ss 0))))
     (set (read (strcat "P" (itoa (setq i (1+ i))))) n) 
     (princ (strcat "\nP" (itoa i) " : " (vl-princ-to-string n)))            
   )
   (princ  (strcat "\nTotal number of vertex is n = " (itoa i) "\n"))    
   
   ;Do sth other
   (repeat i
   (set (read (strcat "P" (itoa i))) nil )(setq i (1- i))
   )
   )
   )
(princ)
 )

Edited by ketxu
Posted
or sth similar to clear global variables ...
A lot "similar": http://forums.augi.com/showthread.php?t=126660

Just take note to be careful about global variables - especially when generating arbitrary numbers of them like with this code. In AutoLisp (and nearly all other languages) a global variable can cause quite many headaches as anything might modify / rely on it being there. Thus some other routine might rely on a pt2 being saved somewhere, but then fail because this one's modified / cleared the value. Or some other routine might clear one of these values and cause this routine to fail. The point is that you cannot think of all possibilities, since you cannot see the future (never mind that the present is a huge task to test for every possibility).

 

Though we haven't seen where these are supposed to be used. Are they meant to stay as global to be reused many times from different routines? We'd be able to give much better advise if we knew exactly what was supposed to happen with these points.

Posted

It's ok now, i use 2 separate lisps, and the result you can see in the attached drawing. Sorry, is not english in the drawing (IS ABOUT GROUND PROFILE, WITH HORIZONTALDISTANCES , ELEVATION VALUE - SORRY, NOT IN ENGLISH) And maybe somebody have a routine to do something similar like in the drawing... but anyhow it's ok now, thanks for help guys! I can show those 2 lisps that i use, but they are so bad...i'm afraid to do this :)

Drawing1.dwg

  • 2 months later...
Posted
Drawing2.dwgWhat about a (let's say) "horizontal" polyline, intersected by many vertical lines, through vertices and through other points(not vertices)? I mean, to count first line -L1, second line - L2...and so on, from left to right, for example... HOW? see the drawing...
Posted

If you use the "VL-curve-getclosetpointto" command it will reduce your code immensely you just use the pline vertice and the VL it works out the perp point for you so simple, just pick pline, pick horizontal line and say datum level and vert scale = numbers just loop through the pline vertices does not matter how many.

 

Stole this from elsewhere whilst looking around today

 

(setq pd1 (getpoint "\nSelect first point "))
       (setq pd (car (entsel "\nSelect line to extend to:  ")))
                        (setq pt (vlax-curve-getClosestPointTo pd pd1 T))

  • 4 years later...
Posted

how to load this code in to autocad

(defun C:TEST ( / i ss)
 (if
   (setq i 0 ss (ssget ":E:S" '((0 . "LWPOLYLINE"))))
   (progn 
   (foreach n
     (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (ssname ss 0))))
     (set (read (strcat "P" (itoa (setq i (1+ i))))) n) 
     (princ (strcat "\nP" (itoa i) " : " (vl-princ-to-string n)))            
   )
   (princ  (strcat "\nTotal number of vertex is n = " (itoa i) "\n"))    
   
   ;Do sth other
   (repeat i
   (set (read (strcat "P" (itoa i))) nil )(setq i (1- i))
   )
   )
   )
(princ)
 )

 

@ketxu

Posted

Save this file as .lsp and give "ap" command in autocad and load it

Posted

what is the command in to command line LWPOLYLINE or other

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...