Lisp(?) to draw Polyline across multiple center points

Lisp(?) to draw Polyline across multiple center points

Anonymous
Not applicable
15,055 Views
42 Replies
Message 1 of 43

Lisp(?) to draw Polyline across multiple center points

Anonymous
Not applicable

(Posting here, since when I posted on general foruns I was recommended to do so:)

Hi, people.
I need some help.

I'm stucked with a job that I must deliver done by next monday.
This job consist in redrawing routes based on older files to a new map and filling this routes with relevant information (I will expand on this later).
These routes are represented by polylines that must have its vertexes matching center points of a block.

 Capturar_1_sample.PNG

 

 

These blocks represent electrical poles (is that how we call it in english? I'm brazilian). I have been doing this clicking in center-point by center-point, one by one. And I'm fast.
But now I have a little health issue that's making me slower and slower. I have something that may translate to carpal tunnel syndrome in english and it's making my hand hurt really bad.

 

These routes, polylines, may demand thousands and thousands of clicks in the center points of these blocks, and if add the clicking for pan and navigation... I know it is quite normal in autocad, but when we are talking about this AND speed AND health issues... Things get dark.

 

The general view of the position of the poles it this:Capturar_1_generalview.PNG

 

 

 I believe it is possible to understand the size of this demon (and it hasn't even finished - pole-wise) with this image.

It is also possible to see here that I already have much of it done. But I do not.

These lines represent other things. In order to add and analyze the data I have to, I must redraw. I do not have enough time nor my english is flexible enough to explain it, but I have to see file by file and redraw it with my own two eyes and my own two hands. It is a insane-importantness-level thing, that may strenghen our argument in legal subjects in the next monday meeting.

 

So let's get to what I need help with.
I can write something in autoLISP, but I'm not good (nor I have the time to experiment) enough.

 

I want something that allow me to select these blocks - or circles - that I need and automatically draw a polyline based on it's center points. As the sample above showed.

I'm attaching this file so anyone who can help me may play with it.

The rules would be: one direction.
From the "first" center point" to the nearest next and so on until it "links" all the selected blocks/circles with this polyline.

 

Is it possible? Is there already a command or lisp out there that makes this for me? (didn't have luck so far with my search)

 

Capturar_1_sample_to_do.PNG 

Please, guys. Help me.

0 Likes
Accepted solutions (2)
15,056 Views
42 Replies
Replies (42)
Message 21 of 43

sjcteam
Explorer
Explorer

thank you so much this is a very useful lisp , but can you please upgrade it so it considers selecting order 

0 Likes
Message 22 of 43

Kent1Cooper
Consultant
Consultant

@sjcteam wrote:

.... can you please upgrade it so it considers selecting order 


If selection order is what matters, not relative position, then you don't need a routine.  Just set INSertion-point [if you're working with Blocks] or CENter [with Circles] or NODe [with Point objects] as the only running object snap mode, and start a PLINE command.  You'll just draw the result as you go along picking objects, rather than pick them first and have it drawn afterwards.

Kent Cooper, AIA
0 Likes
Message 23 of 43

sjcteam
Explorer
Explorer

Thank you so much for your fast reply , I was looking for a routine to draw polyline between selected node and  selecting the node by rectangle selection obversely  will  be much faster than choosing point by point and take the risk of not snapping to one point  , so I mean something like what we have in autonumbering order in express tool (by X, By Y ,By selecting order)

0 Likes
Message 24 of 43

Sea-Haven
Mentor
Mentor

Ok what you need is select a few at a time and compare the distance from start/last point to the block point, sort based on distance then join in that order. Looking at dwg in some cases may be only 1 or 2 points in other areas 20+.

 

This is 1st go need to add the while loop so can keep going and join plines  Anybody can jump in.

 

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-draw-polyline-across-multiple-center-points/td-p/8038549/page/2

(defun LWPoly (lst cls)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst))
                         (cons 70 cls))
                   (mapcar (function (lambda (p) (cons 10 p))) lst))))
				   
				   
(defun c:test ( / ss inspt stpt lst lst2)		   
(setq stpt (getpoint "\nPick start point "))
(setq ss (ssget '((0 . "INSERT"))))
(setq lst '())
(repeat (setq x (sslength ss))
(setq ent (ssname ss (setq x (1- x))))
(setq inspt (cdr (assoc 10 (entget ent))))
(setq dist (distance stpt inspt))
(setq lst (cons (list dist inspt) lst))
)
(setq lst2 '())
(foreach pt lst
(setq lst2 (cons (cadr pt) lst2))
)
(setq lst2 (reverse lst2))
(lwpoly lst2 0)
(setq stpt (last lst2))
(setq lastpl (entlast))
(princ)
)

 

 

Oh yeah I need to add that blocks insertion point is not at centre of pole adding more difficulty. It looks like point is lower left so should be able to do a add X Y

 

0 Likes
Message 25 of 43

Kent1Cooper
Consultant
Consultant

@sjcteam wrote:

... I was looking for a routine to draw polyline between selected node and  selecting the node by rectangle selection....


That seems to directly contradict your previous request [Message 21] to have it consider selection order.  In selecting by rectangle selection, it will use the reverse drawing order of the things selected within a given rectangular area, over which you will have no control.

Kent Cooper, AIA
0 Likes
Message 26 of 43

sjcteam
Explorer
Explorer

thank you so much , but it doesn't work for me unfortunately

0 Likes
Message 27 of 43

sjcteam
Explorer
Explorer

maybe I didn't make myself clear at the first post, but what I really want is pretty much similar to auto numbering in express tool as in option (by x ,by Y , by selecting order )in selecting term , I mean the same power in selecting but to do the connecting polyline 

0 Likes
Message 28 of 43

bhelget
Participant
Participant

I'm looking for the same solution as you are but need polylines on both ends of the lines. Did you figure out how to get the polyline go across all the line endpoints on one end?

Snap1.png

0 Likes
Message 29 of 43

Kent1Cooper
Consultant
Consultant

@bhelget wrote:

I'm looking for the same solution as you [ @SROBERTS-2017 ] are but need polylines on both ends of the lines. Did you figure out how to get the polyline go across all the line endpoints on one end?


Since @SROBERTS-2017 said something about "I have got that to work" in connection with endpoints, I think we need to see what they came up with.  The issue in their Message was probably about differences in drawn direction from one Line [or perhaps Polyline?] to the next.

Kent Cooper, AIA
0 Likes
Message 30 of 43

devitg
Advisor
Advisor

@bhelget Please upload your sample dwg . so we can get the order the lines where made.

 

0 Likes
Message 31 of 43

bhelget
Participant
Participant

Here's the sample file. Thanks.

0 Likes
Message 32 of 43

SROBERTS-2017
Explorer
Explorer

Sorry i did not

0 Likes
Message 33 of 43

ВeekeeCZ
Consultant
Consultant

You should not have posted it in here. Yours is totally different story, much simpler.

I asked the moderators to split this into a new thread.

 

(vl-load-com)

(defun c:ConnectLineEndPoints ( / LWPoly s l v)
  
  (defun LWPoly (lst)
    (entmake (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (length lst)) '(70 . 0))
		     (mapcar '(lambda (p) (cons 10 p)) lst))))
  
  (if (and (setq s (ssget '((0 . "LINE"))))
	   (setq l (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
	   )
    (foreach p '(10 11)
      (setq v (mapcar '(lambda (e) (cdr (assoc p (entget e)))) l)
	    v (vl-sort v '(lambda (x1 x2) (< (car x1) (car x2)))))
      (LWPoly v)))
  (princ)
  )

 

0 Likes
Message 34 of 43

bhelget
Participant
Participant

Thank you BeeKeeCZ for your quick reply with solution and noted about forum rules.

 

One more question though, can the routine also include a step to pick the starting points for the polylines (example: pick line for start of polylines)?

 

Thanks again!

0 Likes
Message 35 of 43

ВeekeeCZ
Consultant
Consultant

Illustrate what you mean.

 

The routine takes all the selected lines, sort them by their X coord and connects them using pline from the lowest X to the highest. 

0 Likes
Message 36 of 43

bhelget
Participant
Participant

bhelget_0-1670945417243.png

 

0 Likes
Message 37 of 43

ВeekeeCZ
Consultant
Consultant

What if I add a prompt to specify a direction... 

Specify a direction, from [Right] <left>: 

 

0 Likes
Message 38 of 43

bhelget
Participant
Participant

I would need it to work with the selection lines running in the X direction (horizontal) also. So, not sure if the right or left prompt would work for that...?

0 Likes
Message 39 of 43

ВeekeeCZ
Consultant
Consultant

So it's either a vertical or horizontal layout. Never somehow in between.

0 Likes
Message 40 of 43

bhelget
Participant
Participant

Yes, just vertical and horizontal.

0 Likes