Author Topic: How to find vertex number  (Read 9289 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.