LISP to quickly number multiple polylines

LISP to quickly number multiple polylines

ramirez.m.1989
Enthusiast Enthusiast
6,240 Views
26 Replies
Message 1 of 27

LISP to quickly number multiple polylines

ramirez.m.1989
Enthusiast
Enthusiast

I need to quickly number polylines. In other posts I found a routine but you have to select each point where you want the number to appear . Ideally, multiple polylines should be selected and numbered depending on the order in which they were selected.  I attach an example drawing.

 

 

Thanks.

 

0 Likes
Accepted solutions (1)
6,241 Views
26 Replies
Replies (26)
Message 2 of 27

devitg
Advisor
Advisor

How do you "Discard " the small polys . 

 

Can you tell us where do it dwg come from , or whom or how did it .?

 

 

0 Likes
Message 3 of 27

ramirez.m.1989
Enthusiast
Enthusiast

The small polylines are a drawing error, I attach another simplified example drawing.

 

The polylines are made with the boundary command.

 

I just leave the layers of interest in the drawing. The original drawing are sidewalks of streets with their corresponding materialities. Each of the polylines is a sidewalk with a certain materiality.

0 Likes
Message 4 of 27

pbejse
Mentor
Mentor

@ramirez.m.1989 wrote:

I need to quickly number polylines....

 


As a starting point

 

(defun c:LMB ( / sel e sum verts ptList p_)
      
;;	Label Me Buddy			;;
;;	pBe Feb 2018			;;
;;--------------------------------------;;
;;	Kent Cooper sum|verts		;;
;;--------------------------------------;;
      
(setq inc (cond
                 ((getint (strcat "\nEnter number"
                                  (if inc
                                        (strcat " <" (itoa inc) ">: ")
                                        ": ")
                                  )))
                 (inc))
      )
      
(while (and  (princ (strcat "\nLabel Number " (itoa inc)))
             (setq sel (ssget "_+.:S:E" '((0 . "LWPOLYLINE"))))
             )
	(setq e     (ssname sel 0)
	      sum   '(0 0)
	      verts (cdr (assoc 90 (setq ent (entget e)))))
	(setq ptList
	       (mapcar 'cdr
	               (vl-remove-if-not
	                     '(lambda (x) (= (car x) 10)) ent)))
	(foreach x ptList (setq sum (mapcar '+ x sum)))
	(setq p_ (mapcar '/ sum (list verts verts)))
	(entmakex
	      (list
	        (cons 0 "TEXT")
	        (cons 10 p_)                      
	        (cons 11 p_)
	        (cons 8 (cdr (assoc 8 ent)))
	        '(40 . 0.18)                                
	        '(72 . 4)
	        '(73 . 3)
	        (cons 1 (itoa inc))
	        )
	      )
      	  (entmakex
                (list (cons 0 "CIRCLE")
                      (cons 10 p_)
                      (assoc 8 ent)
                      (cons 40 0.28)
                      )
                )
                      (setq inc (1+ inc)))
      	(princ)
                )
0 Likes
Message 5 of 27

ramirez.m.1989
Enthusiast
Enthusiast

Sure, it's that. It would only be necessary to include the multiple selection and it would be perfect. 

 

It could be in the order of selection or indicating the direction of the numbering.

 

Thanks.

0 Likes
Message 6 of 27

pbejse
Mentor
Mentor
Accepted solution

@ramirez.m.1989 wrote:

...would only be necessary to include the multiple selection and it would be perfect. 


Sure...

 

 

(defun c:LMBS(/ sel e sum verts ptList p_)

;;	Label Me Buddy			;;
;;	pBe Feb 2018			;;
;;--------------------------------------;;
;;	Kent Cooper sum|verts		;;
;;--------------------------------------;;

      (setq inc  (cond
                       ((getint (strcat "\nEnter number"
                                        (if inc
                                              (strcat " <"
                                                      (itoa inc)
                                                      ">: ")
                                              ": ")
                                        )))
                       (inc))
            )

      (if
            (setq ss (ssget '((0 . "LWPOLYLINE"))))

                 (repeat (sslength ss)
                       (setq e     (ssname ss 0)
                             sum   '(0 0)
                             verts (cdr (assoc 90 (setq ent (entget e)))))
                       (setq ptList
                                  (mapcar 'cdr
                                          (vl-remove-if-not
                                                '(lambda (x) (= (car x) 10))
                                                ent)))
                       (foreach x ptList (setq sum (mapcar '+ x sum)))
                       (setq p_ (mapcar '/ sum (list verts verts)))
                       (entmakex
                             (list
                                   (cons 0 "TEXT")
                                   (cons 10 p_)
                                   (cons 11 p_)
                                   (cons 8 (cdr (assoc 8 ent)))
                                   '(40 . 0.18)
                                   '(72 . 4)
                                   '(73 . 3)
                                   (cons 1 (itoa inc))
                                   )
                             )
                       (entmakex
                             (list (cons 0 "CIRCLE")
                                   (cons 10 p_)
                                   (assoc 8 ent)
                                   (cons 40 0.28)
                                   )
                             )
                       (setq inc (1+ inc))
                       (ssdel e ss)
                       )
                 )
      (princ)
      )

 

0 Likes
Message 7 of 27

ramirez.m.1989
Enthusiast
Enthusiast

I make the selection with an area and the numbers come out disordered.

 

Is there any way to make the selection with an area and that the numbers come out in order? 

 

I do not know how to quickly enumerate a lot of polylines. Selecting each polyline is a bit slow.

0 Likes
Message 8 of 27

devitg
Advisor
Advisor

Select by FENCE 

0 Likes
Message 9 of 27

ramirez.m.1989
Enthusiast
Enthusiast

The numbers keep coming out of order. 

0 Likes
Message 10 of 27

ramirez.m.1989
Enthusiast
Enthusiast

Doing several tests I realized that it numbers according to the order in which the polyline was drawn.

0 Likes
Message 11 of 27

pbejse
Mentor
Mentor

@ramirez.m.1989 wrote:

The numbers keep coming out of order. 


Selecting by Fence will and should give the correct order.

 


@ramirez.m.1989 wrote:

Doing several tests I realized that it numbers according to the order in which the polyline was drawn.


 

Yes, it will do that.

 

What we need is a mean sorting algorithm. depending on the direction. Left to right , Top to bottom .... but then again, you need to select bygroup, so its basically the same as using Fence selection

 

EDIT:  Now you got me curious, How exactly were the polylines generated?

 

 

0 Likes
Message 12 of 27

john.uhden
Mentor
Mentor

If you want them in a certain order, then just pick them in a certain order.

I think your bigger problem may be in determining where to put the text label, as the "centroid" of a polyline may well be outside its boundary.  Somewhere I have a function that always finds a location inside the boundary.  I think it's my SSURGO program that labels the soil type of numerous polyline boundaries.  If I recall, it has to keep testing East-West and North-South until it finds a suitable location wide enough to contain the text.

John F. Uhden

0 Likes
Message 13 of 27

ramirez.m.1989
Enthusiast
Enthusiast
In some cases they are more than 1000 polylines so it is not very fast to
select one by one.
0 Likes
Message 14 of 27

john.uhden
Mentor
Mentor

Might there be a graphical order that would work, as in from left to right and top to bottom?  If so, we can help you to sort the polylines in order by their coordinates.

John F. Uhden

0 Likes
Message 15 of 27

ramirez.m.1989
Enthusiast
Enthusiast
They are supposed to be streets so they would be numbered in streets. All
those on the same axis should have a continuous numbering.
0 Likes
Message 16 of 27

pbejse
Mentor
Mentor

@ramirez.m.1989 wrote:
In some cases they are more than 1000 polylines so it is not very fast to
select one by one.

Listen ramirez.m.1989, before we started, you were happy with typing in the description per object. I suggested layers so you dont even need to typed in anything. Now, we have a routine to number the polylines via selection. At first using a loop and then modified using Fence, I'm pretty sure  beats placing the TEXT on the objects center(ish), typing the string number then creating the circle one after the other.

 

I'm open for suggestions.

 

0 Likes
Message 17 of 27

ramirez.m.1989
Enthusiast
Enthusiast
I'm grateful for your help. With the routines that you have created, I will
save a lot of time. I just wanted to know if there was any way to perfect
them.
0 Likes
Message 18 of 27

pbejse
Mentor
Mentor

@ramirez.m.1989 wrote:
I'm grateful for your help. With the routines that you have created, I will
save a lot of time. 

We are happy to help. Smiley Happy


@ramirez.m.1989 wrote:
I just wanted to know if there was any way to perfect them.

 

Not sure about "perfect" but maybe a better way. So answer me this. 

 

 

..That is why i'm asking how were the polylines generated? maybe, just maybe we can deal with the numeric order on or before the objects are created...

 

...EDIT:  Now you got me curious, How exactly were the polylines generated? ..

 

 

0 Likes
Message 19 of 27

ramirez.m.1989
Enthusiast
Enthusiast
The topographers send us the drawing of the sidewalks, streets and
singularities. We take that drawing and draw the polylines to separate the
different materialities with the *boundary command*. Then, we number each
polyline and place dimensions. Finally, we created an excel sheet with the
numbering, width, length and materiality of each of the polylines.
0 Likes
Message 20 of 27

pbejse
Mentor
Mentor
Now we're getting somewhere... we'll start again tomorrow.

Hang in there buddy...
0 Likes