Author Topic: How to find vertex number  (Read 9261 times)

0 Members and 1 Guest are viewing this topic.

matrix2005in

  • Guest
How to find vertex number
« on: June 03, 2006, 11:18:04 PM »
any lisp for finding vertex number and give the vertex number you selected...

any ideas??
« Last Edit: June 05, 2006, 04:39:38 PM by CAB »

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: HOw to find vertex number
« Reply #1 on: June 04, 2006, 04:09:13 AM »
any lisp for finding vertex number and give the vertex number you selected...

any ideas??

Choice of a segment in a polyline the instruction of a point...
http://www.theswamp.org/index.php?topic=8878.msg114384#msg114384


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: HOw to find vertex number
« Reply #2 on: June 04, 2006, 09:06:27 AM »
Code: [Select]
(defun c:test ()
  (vl-load-com)
  ;;  no error checking

  (setq esel (entsel "\nSelect a pline"))
  (setq ent (car esel))

  ;;  get exact point ON the pline
  (setq pt (vlax-curve-getclosestpointto ent (cadr esel)))


  ;;  Get vertex number, if point is not exactly on a verted the number
  ;;  returned will have the fractional position relivitive to the previous vertex
  (setq par (vlax-curve-getparamatpoint ent pt))

  ;;  get closest vertex number
  (if (> (rem par 1) 0.5)
    (setq vertex# (1+ (fix par)))
    (setq vertex# (fix par))
  )

  (prompt (strcat "\nVertex Number = " (itoa vertex#) ", note that 0 if the first vertex."))
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: HOw to find vertex number
« Reply #3 on: June 04, 2006, 09:43:00 PM »
hi:)
 I want to write a program to draw a pline with arrow at the end.
That is, when I draw a pline, then it automatic change the last segment to an arrowlike shape. (different width at the last segment).
So I should draw the pline first, then modify the pline. First  add one vertex at the last segment, second change the new maked segment width to W (a constant value) ->0.
But I am not familiar with pline operation, could you help me? :)

http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

matrix2005in

  • Guest
Re: HOw to find vertex number
« Reply #4 on: June 05, 2006, 09:45:17 AM »
hi cab

thanks for your code...

actually your code was near to what i was looking...so i changed your code little bit and now i am getting proper vertex number....thanks once again..

Code: [Select]

(defun c:test ()
  (vl-load-com)
  ;;  no error checking

  (setq esel (entsel "\nSelect a pline"))
  (setq ent (car esel))

  ;;  get exact point ON the pline
  (setq pt (vlax-curve-getclosestpointto ent (cadr esel)))


  ;;  Get vertex number, if point is not exactly on a verted the number
  ;;  returned will have the fractional position relivitive to the previous vertex
  (setq par (vlax-curve-getparamatpoint ent pt))

  ;;  get closest vertex number
  (if (> (rem par 1) 0.0)
    (setq vertex# (1+ (fix par)))
    (setq vertex# (fix par))
    )
    (cond
      (= vertex# 0)
      (setq vertex# 1)
    )
 
  (prompt (strcat "\nVertex Number = "
  (itoa vertex#)
 
  )
  )

  (princ)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: HOw to find vertex number
« Reply #5 on: June 05, 2006, 10:15:49 AM »
matrix2005in
If you want the vertex number to start at 1 you will need to increment all vertex returned,
not just the first one. Use this:
Code: [Select]
(defun c:test ()
  (vl-load-com)
  ;;  no error checking

  (setq esel (entsel "\nSelect a pline"))
  (setq ent (car esel))

  ;;  get exact point ON the pline
  (setq pt (vlax-curve-getclosestpointto ent (cadr esel)))


  ;;  Get vertex number, if point is not exactly on a verted the number
  ;;  returned will have the fractional position relivitive to the previous vertex
  (setq par (vlax-curve-getparamatpoint ent pt))

  ;;  get closest vertex number
  (if (> (rem par 1) 0.5)
    (setq vertex# (1+ (fix par)))
    (setq vertex# (fix par))
  )
  (setq vertex# (1+ vertex#))

  (prompt (strcat "\nVertex Number = " (itoa vertex#)))
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

matrix2005in

  • Guest
Re: HOw to find vertex number
« Reply #6 on: June 05, 2006, 10:35:27 AM »
CAB i was tried the same way too..it was not giving proper result..
but if you try the one which i modyfied you know the dfference..

thanks

mathew

matrix2005in

  • Guest
Re: HOw to find vertex number
« Reply #7 on: June 05, 2006, 10:44:02 AM »
HI CAB i am just a beginner of lisp...

i was testing with your lisp, changed some part just like that to see the result and it works fine...
 i just set it up first vertex is =1
but my confusion is the rest of the vertex numbers are correct with respect to the first one..
How come?????????

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: HOw to find vertex number
« Reply #8 on: June 05, 2006, 12:25:08 PM »
matrix2005in
The results are as follows:
Actual Vertex Number, first lisp returns
0 1 2 3 4 ...
Your routine returns
1 1 2 3 4 ....
It should return and my second code does return
1 2 3 4 5 ....
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: HOw to find vertex number
« Reply #9 on: June 05, 2006, 01:09:29 PM »
hi:)
 I want to write a program to draw a pline with arrow at the end.
That is, when I draw a pline, then it automatic change the last segment to an arrowlike shape. (different width at the last segment).
So I should draw the pline first, then modify the pline. First  add one vertex at the last segment, second change the new maked segment width to W (a constant value) ->0.
But I am not familiar with pline operation, could you help me? :)

Here is a quick and easy way to approach your request.
This should give you some ideas you can work with.
Code: [Select]
(defun c:test ()
  (vl-load-com)
  ;;  no error checking

  (prompt "\nDraw your pline.")
  (command "PLINE")
  (while (> (getvar "CMDACTIVE") 0)
     (command pause)
  )
  (setq ent (entlast))

  (setq ArrowLength 5
        ArrowWidth  2
        )
  (setq ArrowBasePt (vlax-curve-getPointAtDist ent ArrowLength))
  (command "_pedit" ent "_e" "_i" "_non" ArrowBasePt "_x" "_e" "_w" "0" ArrowWidth "_x" "" "")

  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

matrix2005in

  • Guest
Re: HOw to find vertex number
« Reply #10 on: June 05, 2006, 02:42:35 PM »
CAB

My code is also returning same..
1,2,3,4...

can you check it..i checked in multiple versions and machines...
results are same...

mathew

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: HOw to find vertex number
« Reply #11 on: June 05, 2006, 04:37:52 PM »
matrix2005in
Here is the result of my test.
The vertext number is placed at the pick point.
Try each one on your drawing.

Code: [Select]
(defun c:yours ()
  (vl-load-com)
  ;;  no error checking

  (setq esel (entsel "\nSelect a pline"))
  (setq ent (car esel))

  ;;  get exact point ON the pline
  (setq pt (vlax-curve-getclosestpointto ent (cadr esel)))


  ;;  Get vertex number, if point is not exactly on a verted the number
  ;;  returned will have the fractional position relivitive to the previous vertex
  (setq par (vlax-curve-getparamatpoint ent pt))

  ;;  get closest vertex number
  (if (> (rem par 1) 0.5)
    (setq vertex# (1+ (fix par)))
    (setq vertex# (fix par))
  )
    (cond
      ((= vertex# 0)
      (setq vertex# 1))
    )

  (prompt (strcat "\nVertex Number = " (itoa vertex#)))

  ;;  Debug On ===================================================
  (setq txt (itoa vertex#))
  ;; If text height is undefined (signified by 0 in the table)
  (if (= (cdr(assoc 40(tblsearch "style" (getvar "textstyle")))) 0)
    (command "_text" "_mc" "_non" (cadr esel) "" 0 txt)
    (command "_text" "_mc" "_non" (cadr esel) 0 txt)
  ) ; endif

  (princ)
)

(defun c:mine ()
  (vl-load-com)
  ;;  no error checking

  (setq esel (entsel "\nSelect a pline"))
  (setq ent (car esel))

  ;;  get exact point ON the pline
  (setq pt (vlax-curve-getclosestpointto ent (cadr esel)))


  ;;  Get vertex number, if point is not exactly on a verted the number
  ;;  returned will have the fractional position relivitive to the previous vertex
  (setq par (vlax-curve-getparamatpoint ent pt))

  ;;  get closest vertex number
  (if (> (rem par 1) 0.5)
    (setq vertex# (1+ (fix par)))
    (setq vertex# (fix par))
  )
  (setq vertex# (1+ vertex#))

  (prompt (strcat "\nVertex Number = " (itoa vertex#)))

  ;;  Debug On ===================================================
  (setq txt (itoa vertex#))
  ;; If text height is undefined (signified by 0 in the table)
  (if (= (cdr(assoc 40(tblsearch "style" (getvar "textstyle")))) 0)
    (command "_text" "_mc" "_non" (cadr esel) "" 0 txt)
    (command "_text" "_mc" "_non" (cadr esel) 0 txt)
  ) ; endif

  (princ)
)
« Last Edit: June 05, 2006, 04:48:21 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to find vertex number
« Reply #12 on: June 05, 2006, 04:49:04 PM »
matrix2005in
I just realized you cond statement is incorrect

Code: [Select]
    (cond
      (= vertex# 0)
      (setq vertex# 1)
    )

Sould be written like this:

Code: [Select]
    (cond
      ((= vertex# 0)
      (setq vertex# 1))
    )

I fixed the one above in the 'yours' code example.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Joe Burke

  • Guest
Re: How to find vertex number
« Reply #13 on: June 06, 2006, 10:58:06 AM »
CAB,

Just a thought regarding this:

  (setq esel (entsel "\nSelect a pline"))
  (setq ent (car esel))

  ;; get exact point ON the pline
  (setq pt (vlax-curve-getclosestpointto ent (cadr esel)))

  ;; always trans the entsel point to WCS
  (setq pt (vlax-curve-getclosestpointto ent (trans (cadr esel) 1 0)))

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to find vertex number
« Reply #14 on: June 06, 2006, 01:08:19 PM »
Good point Joe. <no pun intended> :-)
Thanks
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

matrix2005in

  • Guest
Re: How to find vertex number
« Reply #15 on: June 06, 2006, 01:30:25 PM »
CAB
you are right sorry for the confusion...actually i was looking segment number of selected polyline...
it is my mistake...

do you have any idea how to label polyline vertex by??

!) xy coordinates
2) z elevation

thanks
mathew

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: HOw to find vertex number
« Reply #16 on: June 06, 2006, 11:30:55 PM »
Here is a quick and easy way to approach your request.
This should give you some ideas you can work with.
Code: [Select]
(defun c:test ()
  (vl-load-com)
  ;;  no error checking

  (prompt "\nDraw your pline.")
  (command "PLINE")
  (while (> (getvar "CMDACTIVE") 0)
     (command pause)
  )
  (setq ent (entlast))

  (setq ArrowLength 5
        ArrowWidth  2
        )
  (setq ArrowBasePt (vlax-curve-getPointAtDist ent ArrowLength))
  (command "_pedit" ent "_e" "_i" "_non" ArrowBasePt "_x" "_e" "_w" "0" ArrowWidth "_x" "" "")

  (princ)
)

Dear CAB, you do teach me the pedit command in new way
I dont know how to insert an vertex and dont know how to change the segment in different width in pedit before. I think it should be done by subroutine.

Thank you very much, it seems that I should back to learn the acad command.
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: How to find vertex number
« Reply #17 on: June 07, 2006, 01:11:58 AM »
CAB
you are right sorry for the confusion...actually i was looking segment number of selected polyline...
it is my mistake...

do you have any idea how to label polyline vertex by??

!) xy coordinates
2) z elevation

thanks
mathew
Hi mathew, here is a lisp to label the Z at the coordinate. I leave it to you to modify it to include the XY. I even added a comment where you can get the data to use.
Code: [Select]
(defun c:lblvtx (/ ent i idx pt ss totparam rot)
  (vl-load-com)
  (if (setq ss (ssget '((0 . "*POLY*"))))
    (progn
      (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
      (setq idx -1
    rot (getangle "\nText rotation angle: "))
      (if (not rot)(setq rot 0))
      (while (< (setq idx (1+ idx))(sslength ss))
(setq ent (ssname ss idx))
(setq totparam (fix (vlax-curve-getendparam ent))
      i -1)
(while (< (setq i (1+ i)) totparam)
  (setq pt (vlax-curve-getpointatparam ent i))
  (entmake (list '(0 . "TEXT")
(cons 10 pt)
(cons 7 (getvar "textstyle"))
(cons 40 (getvar "textsize"))
(cons 50 rot)
(cons 1 (rtos (caddr pt) 2 2));;this labels the Z
;;(car pt) is the X, (cadr pt) is the Y
)
   )
  )
)
      (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
      )
    )
  (princ)
  )

matrix2005in

  • Guest
Re: How to find vertex number
« Reply #18 on: June 07, 2006, 10:19:04 AM »
HI jeff

Thank you verymuch for your code...

i am just a begin er of lisp..i edited your code..not sure is it a right method but it works.. :-)
Code: [Select]
(defun c:lblvtx (/ ent i idx pt ss totparam rot)
  (vl-load-com)
  (if (setq ss (ssget '((0 . "*POLY*"))))
    (progn
      (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
      (setq idx -1
    rot (getangle "\nText rotation angle: "))
      (if (not rot)(setq rot 0))
      (while (< (setq idx (1+ idx))(sslength ss))
(setq ent (ssname ss idx))
(setq totparam (fix (vlax-curve-getendparam ent))
      i -1)
(while (< (setq i (1+ i)) totparam)
  (setq pt (vlax-curve-getpointatparam ent i))
  (entmake (list '(0 . "TEXT")
(cons 10 pt)
(cons 7 (getvar "textstyle"))
(cons 40 (getvar "textsize"))
(cons 50 rot)
;(cons 1 (rtos (car pt) 2 2))
(cons 1 (strcat "\n(X="(rtos (car pt) 2 2)")"
"(Y="(rtos (cadr pt) 2 2)")"))
;;this labels the Z
;;(car pt) is the X, (cadr pt) is the Y
)
   )
  )
)
      (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
      )
    )
  (princ)
  )



CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How to find vertex number
« Reply #19 on: June 07, 2006, 11:52:52 AM »
Good job Mathew.
You are on your way to being a lisper. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

matrix2005in

  • Guest
Re: How to find vertex number
« Reply #20 on: June 07, 2006, 01:59:53 PM »
CAB
thanks man 8-)

one doubt how can i adjust text size in that code??...i mean it taking from textsize variable but if you create new text style with different height it wont change the text size variable...
eg:- before creating textsize-0.2000 (default)
after creating text style-style1 height-3 still textsize variable is same-0.200

what to do?? :oops:

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: How to find vertex number
« Reply #21 on: June 07, 2006, 03:01:12 PM »
mathew, here's some code you can input to the other (prior to where the text height is needed, such as right after the (progn )
Code: [Select]
(if (= 0.0
       (setq txthgt
      (cdr
(assoc 40
       (entget
(tblobjname "STYLE" (getvar "TEXTSTYLE"))
)
       )
)
     )
       )
  (setq txthgt (getvar "TEXTSIZE"))
  )
then replace (getvar "TEXTSIZE") with txthgt in this line:
Code: [Select]
(cons 40 (getvar "textsize"))

matrix2005in

  • Guest
Re: How to find vertex number
« Reply #22 on: June 07, 2006, 03:15:50 PM »
Hi jeff

Excellent...that's what i want...lovely :-)

Hey howmany years you peoples are working with lisp...i am surprised you people are writing code like essays...

what is the procedure to learn lisp step by step and what all basics  i need to understand...


Bob Wahr

  • Guest
Re: How to find vertex number
« Reply #23 on: June 07, 2006, 04:12:10 PM »
Jeff's one of the older hands around here, he's been doing it for almost three months now.  I think Kerry has been doing it the longest, he started last year some time.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: How to find vertex number
« Reply #24 on: June 07, 2006, 04:31:15 PM »
Jeff's one of the older hands around here, he's been doing it for almost three months now.  I think Kerry has been doing it the longest, he started last year some time.
:lmao:
Mathew, I started to toy with lisp a looooong time ago but didn't get serious about it until 3 years, or so, ago. And I use sreious quite loosely here. I still toy with it, but my 'toys' just get bigger, badder, leaner, meaner. :lol:

IMHO, the best way to learn is to figure out something(s) that you do repetitively and try to automate that process, reading the help files and these forums for guidance. Try your best to figure out something on your own before posting for help. It's not that you won't find plenty of us willing to help, but more like if you find the answer through trial & error of your own you will retain how it is done far longer than us just doing it for you.....