Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp(?) to draw Polyline across multiple center points

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
3264 Views, 7 Replies

Lisp(?) to draw Polyline across multiple center points

Anonymous
Not applicable

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.

 

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

Lisp(?) to draw Polyline across multiple center points

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.

 

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.

7 REPLIES 7
Message 2 of 8
j.palmeL29YX
in reply to: Anonymous

j.palmeL29YX
Mentor
Mentor

If you draw the polyline(s) manually, how do you decide, in which order you connect the circles? If there are any "rules" or you can formulate such rules (e.g. ascending x-values or similar) then it should be possible to write some lines LISP - and I'd suggest to ask in the LISP-Forum to get a solution in a short time.

If there are not such rules - I'm afraid you will have to do it manually  😞

 

cadder

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

If you draw the polyline(s) manually, how do you decide, in which order you connect the circles? If there are any "rules" or you can formulate such rules (e.g. ascending x-values or similar) then it should be possible to write some lines LISP - and I'd suggest to ask in the LISP-Forum to get a solution in a short time.

If there are not such rules - I'm afraid you will have to do it manually  😞

 

cadder

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 3 of 8
Anonymous
in reply to: j.palmeL29YX

Anonymous
Not applicable

Oh, hi.

Okay. I will try to post there too.

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.

Do you think it is possible this way?

0 Likes

Oh, hi.

Okay. I will try to post there too.

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.

Do you think it is possible this way?

Message 4 of 8
j.palmeL29YX
in reply to: Anonymous

j.palmeL29YX
Mentor
Mentor

@Anonymous  schrieb:


Do you think it is possible this way?


Yep. I'm sure if you ask in the LISP forum you will get an answer in a short time.

Good luck.

 

cadder

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes


@Anonymous  schrieb:


Do you think it is possible this way?


Yep. I'm sure if you ask in the LISP forum you will get an answer in a short time.

Good luck.

 

cadder

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 5 of 8
tboehler
in reply to: Anonymous

tboehler
Collaborator
Collaborator

I tried a few things with Civil 3D points that didn't work well.  Here is the drawing you attached with the remining points connected on a layer called ADD.  You will just need to insert lines on that layer into your drawing.  I had some time and thought how long could it take.  Not long but - I wouldn't want to do that again.

 

I used the center of the circle as you did.  The block insertion point was outside of the circle?  Maybe that is the intended location for the lines?

 

Hopefully that helped a bit.  I hope someone can help find a better solution.

 

 

 

0 Likes

I tried a few things with Civil 3D points that didn't work well.  Here is the drawing you attached with the remining points connected on a layer called ADD.  You will just need to insert lines on that layer into your drawing.  I had some time and thought how long could it take.  Not long but - I wouldn't want to do that again.

 

I used the center of the circle as you did.  The block insertion point was outside of the circle?  Maybe that is the intended location for the lines?

 

Hopefully that helped a bit.  I hope someone can help find a better solution.

 

 

 

Message 6 of 8
3wood
in reply to: Anonymous

3wood
Advisor
Advisor

You can try LINKPOINTS.vlx .

It links all 9000+ points with one polyline in less than 2 minutes. Then you can EXPLODE the polyline, delete a few redundant lines and use LINKPOINTS a couple of time to link some gaps, and then use JOIN to join cleared lines into a few polylines. 

Polyline links the block insert point. Since the insert point of your pole is not at the center point of the circle, you can either select and move all polylines in one go from the block insert point to the center of the circle, or replace the block with a new block which has the  insert point at the circle center before using LINKPOINTS.

Inserts, circles and points are all valid objects to link. 

I also attached a result drawing here. The total operation time was less than 5 minutes.

The trial version allows you link 20 poles but you can get a free registration for a year.

0 Likes

You can try LINKPOINTS.vlx .

It links all 9000+ points with one polyline in less than 2 minutes. Then you can EXPLODE the polyline, delete a few redundant lines and use LINKPOINTS a couple of time to link some gaps, and then use JOIN to join cleared lines into a few polylines. 

Polyline links the block insert point. Since the insert point of your pole is not at the center point of the circle, you can either select and move all polylines in one go from the block insert point to the center of the circle, or replace the block with a new block which has the  insert point at the circle center before using LINKPOINTS.

Inserts, circles and points are all valid objects to link. 

I also attached a result drawing here. The total operation time was less than 5 minutes.

The trial version allows you link 20 poles but you can get a free registration for a year.

Message 7 of 8
CADaSchtroumpf
in reply to: Anonymous

CADaSchtroumpf
Advisor
Advisor

Hi,

You can try this!

When you enter your Distance Max, before valid it; be carrefull with the degree off zoom

I have try with your drawing, seem to work's (I have put 75 for max dist) and isolate layer of blocks inserted.

You can find good lisp for add or remove a vertex of polyline if you must have to correct the drawing.

(defun c:join_block ( / lst_flt js e_sel js_wsel ename dxf_cod pt_ins lst_pt_ins d_max corner_dl corner_ul js_bl lremov n e_remov lst_pt ent_sel lst_d index)
  (setq lst_flt
    (list
      '(0 . "INSERT,POINT")
      (cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
      (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model"))
    )
  )
  (or
    (setq js (ssget "_I" lst_flt))
    (setq js (ssget "_P" lst_flt))
  )
  (cond
    (js
      (sssetfirst nil js)
      (initget "Current New")
      (if (eq (getkword "\nUse selected objects? [Current/New] <Current>: ") "New")
        (progn
          (sssetfirst nil nil)
          (setq
            js (ssadd)
            js (ssget lst_flt)
          )
          (sssetfirst nil js)
        )
      )
    )
    (T (setq js (ssget lst_flt)) (sssetfirst nil js))
  )
  (while
    (or
      (null (setq e_sel (entsel "\nSelect bloc model or point where to start polyline")))
      (not (member (cdr (assoc 0 (entget (car e_sel)))) '("INSERT" "POINT")))
    )
  ) 
  (setq
    js_wsel (ssadd)
    ename (car e_sel)
    dxf_cod (entget ename)
    pt_ins (cdr (assoc 10 dxf_cod))
    lst_pt_ins (list pt_ins)
  )
  (ssadd ename js_wsel)
  (initget 6)
  (setq d_max (getdist pt_ins (strcat "\nDistance max for find next blocks <" (rtos (abs (getvar "OFFSETDIST"))) ">: ")))
  (if (not d_max) (setq d_max (abs (getvar "OFFSETDIST"))) (setvar "OFFSETDIST" d_max))
  (sssetfirst nil nil)
  (while pt_ins
    (setq
      corner_dl (mapcar '(lambda (x) (- x d_max)) pt_ins)
      corner_ur (mapcar '(lambda (x) (+ x d_max)) pt_ins)
      corner_dl (list (car corner_dl) (cadr corner_dl))
      corner_ur (list (car corner_ur) (cadr corner_ur))
      js_bl
      (ssget "_C"
        corner_dl
        corner_ur
        (foreach m
          (foreach n dxf_cod
            (if (not (member (car n) '(0 67 410 8 6 62 2 41 42 43 70 71 44 45 210)))
              (setq lremov (cons (car n) lremov))
            )
          )
          (setq dxf_cod (vl-remove (assoc m dxf_cod) dxf_cod))
        )
      )
    )
    (repeat (setq n (sslength js_wsel))
      (if (setq e_remov (ssmemb (ssname js_wsel (setq n (1- n))) js_bl))
        (ssdel e_remov js_bl)
      )
    )
    (repeat (setq n (sslength js_bl))
      (if (not (ssmemb (setq e_remov (ssname js_bl (setq n (1- n)))) js))
        (ssdel e_remov js_bl)
      )
    )
    (cond
      ((not (zerop (sslength js_bl)))
        (setq lst_pt nil)
        (repeat (setq n (sslength js_bl))
          (setq
            ent_sel (ssname js_bl (setq n (1- n)))
            lst_pt (cons (cdr (assoc 10 (entget ent_sel))) lst_pt)
          )
        )
        (setq
          lst_d (mapcar '(lambda (x) (distance x (list (car pt_ins) (cadr pt_ins)))) lst_pt)
          index (- (length lst_d) (length (member (apply 'min (mapcar '(lambda (x) (min x d_max)) lst_d)) lst_d)))
          pt_ins (nth index lst_pt)
        )
        (if pt_ins (progn (setq lst_pt_ins (cons pt_ins lst_pt_ins)) (ssadd (ssname js_bl index) js_wsel)))
      )
      (T (setq pt_ins nil))
    )
  )
  (cond
    (lst_pt_ins
      (entmakex
        (vl-list*
          (cons 0 "LWPOLYLINE")
          (cons 100 "AcDbEntity")
          (cons 100 "AcDbPolyline")
          (cons 90 (length lst_pt_ins))
          (mapcar '(lambda (p) (cons 10 p)) lst_pt_ins)
        )
      )
    )
  )
  (prin1)
)
0 Likes

Hi,

You can try this!

When you enter your Distance Max, before valid it; be carrefull with the degree off zoom

I have try with your drawing, seem to work's (I have put 75 for max dist) and isolate layer of blocks inserted.

You can find good lisp for add or remove a vertex of polyline if you must have to correct the drawing.

(defun c:join_block ( / lst_flt js e_sel js_wsel ename dxf_cod pt_ins lst_pt_ins d_max corner_dl corner_ul js_bl lremov n e_remov lst_pt ent_sel lst_d index)
  (setq lst_flt
    (list
      '(0 . "INSERT,POINT")
      (cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
      (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model"))
    )
  )
  (or
    (setq js (ssget "_I" lst_flt))
    (setq js (ssget "_P" lst_flt))
  )
  (cond
    (js
      (sssetfirst nil js)
      (initget "Current New")
      (if (eq (getkword "\nUse selected objects? [Current/New] <Current>: ") "New")
        (progn
          (sssetfirst nil nil)
          (setq
            js (ssadd)
            js (ssget lst_flt)
          )
          (sssetfirst nil js)
        )
      )
    )
    (T (setq js (ssget lst_flt)) (sssetfirst nil js))
  )
  (while
    (or
      (null (setq e_sel (entsel "\nSelect bloc model or point where to start polyline")))
      (not (member (cdr (assoc 0 (entget (car e_sel)))) '("INSERT" "POINT")))
    )
  ) 
  (setq
    js_wsel (ssadd)
    ename (car e_sel)
    dxf_cod (entget ename)
    pt_ins (cdr (assoc 10 dxf_cod))
    lst_pt_ins (list pt_ins)
  )
  (ssadd ename js_wsel)
  (initget 6)
  (setq d_max (getdist pt_ins (strcat "\nDistance max for find next blocks <" (rtos (abs (getvar "OFFSETDIST"))) ">: ")))
  (if (not d_max) (setq d_max (abs (getvar "OFFSETDIST"))) (setvar "OFFSETDIST" d_max))
  (sssetfirst nil nil)
  (while pt_ins
    (setq
      corner_dl (mapcar '(lambda (x) (- x d_max)) pt_ins)
      corner_ur (mapcar '(lambda (x) (+ x d_max)) pt_ins)
      corner_dl (list (car corner_dl) (cadr corner_dl))
      corner_ur (list (car corner_ur) (cadr corner_ur))
      js_bl
      (ssget "_C"
        corner_dl
        corner_ur
        (foreach m
          (foreach n dxf_cod
            (if (not (member (car n) '(0 67 410 8 6 62 2 41 42 43 70 71 44 45 210)))
              (setq lremov (cons (car n) lremov))
            )
          )
          (setq dxf_cod (vl-remove (assoc m dxf_cod) dxf_cod))
        )
      )
    )
    (repeat (setq n (sslength js_wsel))
      (if (setq e_remov (ssmemb (ssname js_wsel (setq n (1- n))) js_bl))
        (ssdel e_remov js_bl)
      )
    )
    (repeat (setq n (sslength js_bl))
      (if (not (ssmemb (setq e_remov (ssname js_bl (setq n (1- n)))) js))
        (ssdel e_remov js_bl)
      )
    )
    (cond
      ((not (zerop (sslength js_bl)))
        (setq lst_pt nil)
        (repeat (setq n (sslength js_bl))
          (setq
            ent_sel (ssname js_bl (setq n (1- n)))
            lst_pt (cons (cdr (assoc 10 (entget ent_sel))) lst_pt)
          )
        )
        (setq
          lst_d (mapcar '(lambda (x) (distance x (list (car pt_ins) (cadr pt_ins)))) lst_pt)
          index (- (length lst_d) (length (member (apply 'min (mapcar '(lambda (x) (min x d_max)) lst_d)) lst_d)))
          pt_ins (nth index lst_pt)
        )
        (if pt_ins (progn (setq lst_pt_ins (cons pt_ins lst_pt_ins)) (ssadd (ssname js_bl index) js_wsel)))
      )
      (T (setq pt_ins nil))
    )
  )
  (cond
    (lst_pt_ins
      (entmakex
        (vl-list*
          (cons 0 "LWPOLYLINE")
          (cons 100 "AcDbEntity")
          (cons 100 "AcDbPolyline")
          (cons 90 (length lst_pt_ins))
          (mapcar '(lambda (p) (cons 10 p)) lst_pt_ins)
        )
      )
    )
  )
  (prin1)
)
Message 8 of 8
DannyNL
in reply to: CADaSchtroumpf

DannyNL
Advisor
Advisor

There is already a separate LISP thread about this specific question.

See link below:

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-draw-polyline-across-multipl...

0 Likes

There is already a separate LISP thread about this specific question.

See link below:

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-draw-polyline-across-multipl...

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report