SET START POINT

SET START POINT

sigmmadesigner
Advocate Advocate
382 Views
5 Replies
Message 1 of 6

SET START POINT

sigmmadesigner
Advocate
Advocate

Hello everyone, I would like to know how to start numbering the point at any point on a polyline, since my version only starts and ends where the object was created.
sequence, select the object, and specify a point where the numbering should start.

I appreciate everyone's contribution.

 

(defun c:Vertices (/ pl ent data pts pnt-pontos i pnt norte sorted-pts az txt txt-height text-style ent-text)
(setq pl (car (entsel "\nSelecione a polilinha: ")))
(if (and pl (= (cdr (assoc 0 (entget pl))) "LWPOLYLINE"))
(progn
;; Obtém os dados da entidade
(setq data (entget pl))

;; Filtra os pontos dos vértices (grupo 10)
(setq pts (vl-remove-if-not '(lambda (x) (= (car x) 10)) data))

(setq pnt-pontos (mapcar 'cdr pts))

(setq norte (car (vl-remove-if-not
(function
(lambda (pt)
(equal (cadr pt) (apply 'max (mapcar 'cadr pnt-pontos)))
)
)
pnt-pontos
))
)

(setq sorted-pts
(vl-sort
pnt-pontos
(function
(lambda (p1 p2))
)
)
)
)

;; Define estilo e tamanho do texto
(setq text-style "Standard") ;; 
(setq txt-height 2.5)

;; Insere numeração perto de cada ponto
(setq i 1)
(foreach p sorted-pts
(setq txt (strcat (if (< i 10) "0" "") (itoa i)))
(setq ent-text (entmakex
(list
(cons 0 "TEXT")
(cons 10 (list (+ (car p) 0.3) (+ (cadr p) 0.3)))
(cons 40 txt-height)
(cons 1 txt)
(cons 7 text-style)
)
)
)
(setq i (1+ i))
)
)
)
(princ)
)

0 Likes
Accepted solutions (2)
383 Views
5 Replies
Replies (5)
Message 2 of 6

Sea-Haven
Mentor
Mentor

This is something similar used for lower left point on a rectang as 1st point.

 

; thanks to dexus @ theswamp

(defun rotate-rectang (lst / corner)
  (setq corner ; find left most corner with a sort
    (car
      (vl-sort lst
        (function
          (lambda (a b)
            (if (equal (car a) (car b) 1e-4)
              (< (cadr a) (cadr b))
              (< (car a) (car b))
            )
          )
        )
      )
    )
  )
  (while (/= (car lst) corner) ; rotate until corner is the first item
    (setq lst (append (cdr lst) (list (car lst))))
  )
  lst ; return lst
)
 
(rotate-rectang '((3240.0 1074.0) (3440.0 1074.0) (3440.0 1174.0) (3240.0 1174.0)))

 

If you pick a pline near a pline vertice, using entsel, you should be able to find the matching closest vertice look at its position number then make a new list starting with that position then add the remainder of points. Don't sort them. 

0 Likes
Message 3 of 6

komondormrex
Mentor
Mentor
Accepted solution

@sigmmadesigner 

hey you there,

check the following code

(defun c:Vertices (/ pl ent data pts params s_param n_param i txt txt-height text-style ent-text)
	(setq pl (car (entsel "\nSelecione a polilinha: ")))
	(if (and pl (= (cdr (assoc 0 (entget pl))) "LWPOLYLINE"))
		(progn
			;; Obtém os dados da entidade
			(setq data (entget pl))
			;; Filtra os pontos dos vértices (grupo 10)
			(setq params (mapcar '(lambda (pt) (vlax-curve-getparamatpoint pl pt)) (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) data))))
		  	(setq s_param (vlax-curve-getparamatpoint pl (vlax-curve-getclosestpointto pl (trans (getpoint "Selecione um ponto de partida: ") 1 0))))
		  	(if (vl-some '(lambda (param) (> (setq n_param param) s_param)) params)
			  (progn
		 	 	;; Define estilo e tamanho do texto
				(setq text-style "Standard") ;; 
				(setq txt-height 2.5)
			    	(setq i 1)
			    	(foreach p (mapcar '(lambda (param) (vlax-curve-getpointatparam pl param)) (cons s_param (member n_param params)))
			  		(setq txt (strcat (if (< i 10) "0" "") (itoa i)))
					(setq ent-text (entmakex
							(list
								(cons 0 "TEXT")
								(cons 10 (list (+ (car p) 0.3) (+ (cadr p) 0.3)))
								(cons 40 txt-height)
								(cons 1 txt)
								(cons 7 text-style)
							)
						       )
					)
				      	(setq i (1+ i))
				)
			)
		       )
		)
	)
	(princ)
)

 

 

Message 4 of 6

sigmmadesigner
Advocate
Advocate

FANTASTIC, BINGO!!!!!!!! ON TOP

0 Likes
Message 5 of 6

Sea-Haven
Mentor
Mentor
Accepted solution

@komondormrex   just  a suggestion why not use the entsel pick point rather than select the point after picking pline.

(setq ent (entsel "\nSelecione a polilinha: "))
	(setq ptent (list (car (cadr ent)) (cadr (cadr ent))))
	(setq pl (car ent))

 

(trans ptent 1 0)

 

I drew a random pline and only got the 1st 2 points ? The 3rd point was where I started and I used close when making the pline.

SeaHaven_0-1748823437975.png

 

Will try to find some time to do a reorder of vertices. method maybe later today. Bit busy at moment.

 

Found a bit of time

; number a pline vertices starting at pick point.
; By AlanH June 2025

(defun c:numfrom ( / co-ord dist ent-text i k lst num oldsnap pl pt text-heightm text-style x)

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 1)

(setq ent (entsel "\nPick a pline near the vertice as start point "))

(setq pl (car ent))
(setq pt (cadr ent))
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget pl))))
(setq dists '())
(setq x 0)
(setq dist 10000.0)
(setq lst '())

(foreach plpt co-ord
  (setq d1 (distance pt plpt))
  (princ (strcat "\n" (rtos d1 2 2)))
  (setq lst (cons (list d1 x) lst))
  (setq x (1+ x))
)
(setq lst (vl-sort lst '(lambda (x y) (< (car x)(car y)))))

(setq num (cadr (car lst)))
(setq lst '() k num)

(repeat (- (length co-ord) num)
  (setq lst (cons (nth k co-ord) lst))
  (setq k (1+ k))
)

(setq k 0)
(repeat num
  (setq lst (cons (nth k co-ord) lst))
  (setq k (1+ k))
)
(setq lst (reverse lst))

(setq text-style "Standard")
(setq txt-height 2.5)
(setq i 1 k 0)
(repeat (length lst)
  (setq p (nth k lst))
  (setq txt (rtos i 2 0))
  (setq ent-text (entmakex
  (list
    (cons 0 "TEXT")
    (cons 10 p)
    (cons 40 txt-height)
   (cons 1 txt)
   (cons 7 text-style)
  )
  )
  )
  (setq i (1+ i) k (1+ k))
)

(setvar 'osmode oldsnap)

(princ)
)
(c:numfrom)

 

SeaHaven_0-1748837026735.png

 

 

Message 6 of 6

sigmmadesigner
Advocate
Advocate

THANK YOU, IT WAS JUST AS I NEEDED IT...

0 Likes