Mass move block to nearest polyline

Mass move block to nearest polyline

eoconnor95662
Enthusiast Enthusiast
7,895 Views
50 Replies
Message 1 of 51

Mass move block to nearest polyline

eoconnor95662
Enthusiast
Enthusiast

As noted in title I would like a LISP command to mass move blocks to nearest polyline. I've researched and found commands like lee mac's move block to polyline but it doesn't work in mass. Any feedback or existing AutoCAD functions would be much appreciated.

0 Likes
Accepted solutions (3)
7,896 Views
50 Replies
Replies (50)
Message 41 of 51

ВeekeeCZ
Consultant
Consultant

@7Archaeologist84BFCP wrote:

Could anyone possibly change @dlanorh 's script to change block's layer to that of a nearest polyline (nearest from blocks insertion point)? It would save me massive amounts of work.


 

Which of his code are you referring to? Then post some test drawing from with would be clear what you're after.

0 Likes
Message 42 of 51

7Archaeologist84BFCP
Contributor
Contributor

As I understood it, part of his code could get nearest polyline. I'm attaching an example file. I have large amount of blocks with insertion points on polylines and I need each of them to acquire the layer of the polyline they are placed at.

 

0 Likes
Message 43 of 51

ВeekeeCZ
Consultant
Consultant

Again, which code did you use? There are plenty in history, not going to read it all.

0 Likes
Message 44 of 51

_Tharwat
Advisor
Advisor

You may find this program what you are after and just replace the entity name TEXT with INSERT to make it work with blocks.

https://www.cadtutor.net/forum/topic/75959-lisp-to-align-mtext-to-nearest-polyline-end/#comment-6002... 

0 Likes
Message 45 of 51

7Archaeologist84BFCP
Contributor
Contributor

Tharwat,

thank you for your script which moves texts and inserts to the nearest polyline. It will save me lots of time when we start a new project, however what I'm looking for is a script that gives blocks a layer of a polyline below them (which I assume is a nearest polyline).
Thank you

0 Likes
Message 46 of 51

_Tharwat
Advisor
Advisor

Alright, please try the following program which should change the layer of selected blocks based on the closest / nearest polyline's layer found.

(defun c:test (/ int sel ent get pos pts ins loc srt)
  ;;----------------------------------------------------;;
  ;;	Author : Tharwat Al Choufi			;;
  ;; website: https://autolispprograms.wordpress.com	;;
  ;;----------------------------------------------------;;
  (and
    (princ "\nSelect Polylines & Texts : ")
    (setq int -1
          sel (ssget "_:L" '((0 . "INSERT,LWPOLYLINE")))
    )
    (while (setq int (1+ int)
                 ent (ssname sel int)
           )
      (setq get (entget ent)
            pos (cdr (assoc 10 get))
      )
      (or (and (= (cdr (assoc 0 get)) "LWPOLYLINE")
               (setq pts (cons (list (cdr (assoc 10 (reverse get)))
                                     ent
                                     (assoc 8 get)
                               )
                               pts
                         )
               )
          )
          (setq ins (cons (list pos get) ins))
      )
    )
    (while (and ins pts)
      (and (setq pos (car ins)
                 loc (car pos)
           )
           (setq srt
                  (car (vl-sort
                         pts
                         (function
                           (lambda (j k)
                             (< (distance
                                  loc
                                  (vlax-curve-getclosestpointto (cadr j) loc)
                                )
                                (distance
                                  loc
                                  (vlax-curve-getclosestpointto (cadr k) loc)
                                )
                             )
                           )
                         )
                       )
                  )
           )
           (entmod (subst (caddr srt) (assoc 8 (cadr pos)) (cadr pos)))
           (setq ins (cdr ins))
      )
    )
  )
  (princ)
) (vl-load-com)

 

Message 47 of 51

7Archaeologist84BFCP
Contributor
Contributor

Tharwat,

thank you so much! This is exactly what I was looking for. Previously I was using copy property per each polyline+block combo (for hundreds of blocks per drawing). I'm early in my studies of LISP and visual LISP and I'm inspired to learn it even more knowing I will have the ability to do things like this.
Thank you.

Message 48 of 51

_Tharwat
Advisor
Advisor

Great to hear that, and you are welcome anytime. 

Message 49 of 51

hythamthelove
Advocate
Advocate

Your lisp is so good, can this lisp be adjusted to move lines to the nearest vertex of other line like this

The green lines to be moved to the nearest vertex of the red line

hythamthelove_0-1688891745329.pnghythamthelove_1-1688891763269.png

 

0 Likes
Message 50 of 51

_Tharwat
Advisor
Advisor

Thanks,

Yes it is doable and I can write it for you if you can pay for it.

0 Likes
Message 51 of 51

hythamthelove
Advocate
Advocate

sure no problem

0 Likes