LISP to - Connect line to base point of a block

LISP to - Connect line to base point of a block

nkamphui
Enthusiast Enthusiast
5,880 Views
30 Replies
Message 1 of 31

LISP to - Connect line to base point of a block

nkamphui
Enthusiast
Enthusiast

Hi all,

 

Is there a LISP that connects lines to the base point of a block? See attached pictures.

 

 

0 Likes
Accepted solutions (2)
5,881 Views
30 Replies
Replies (30)
Message 21 of 31

hak_vz
Advisor
Advisor

 

(defun bbp ()(trans (cdr(assoc 10 (entget(car(entsel)))))0 1))

 

 

Copy this line above and past into a console and hit <enter>

This creates function (bbp). You can copy (bbp) in clipboard and paste it when needed.

And then select  connecting line end point i.e point you have to connect to block base point and move its handle.

When asked for new point paste or type (bbp) and hit enter

It asks you to select a block, and when selected it return its base point. So line and will move to that position.

Before you receive some better code you may use it and finish your work. Remember, Acad is drafting program  so changing 100 block shouldn't be a problem at all.

Miljenko Hatlak

EESignature

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.
0 Likes
Message 22 of 31

ВeekeeCZ
Consultant
Consultant
Accepted solution

This works quite well for 3dpolylines.

BUT not with lwpolylines - if there is one, you need to unselect its block! See HERE  what I mean.

 

 

 

(vl-load-com)

(defun c:FixPlineToBlock ( / s i e o c lst-b lst-p)

  (if (setq s (ssget '((0 . "POLYLINE,INSERT"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    o (vlax-ename->vla-object e))
      (if (= "INSERT" (cdr (assoc 0 (entget e))))
	(setq lst-b (cons (cdr (assoc 10 (entget e))) lst-b))
	(setq lst-p (cons (cons o (progn
				    (setq c (reverse (vlax-get o 'Coordinates)))
				    (list (nth 2 c) (nth 1 c) 0)))
			  lst-p)))))
  (if (and lst-b lst-p)
    (foreach b lst-b
      (setq lst-p (vl-sort lst-p (function (lambda (p1 p2) (< (distance b (cdr p1)) (distance b (cdr p2)))))))
      (vlax-put (caar lst-p) 'Coordinates (append (reverse (cdddr (reverse (vlax-get (caar lst-p) 'Coordinates)))) b))
      (setq lst-p (cdr lst-p))))
  (princ)
  )

 

 

 

Message 23 of 31

pbejse
Mentor
Mentor

@nkamphui wrote:

?


If its not don't worry about it. 😊

 

0 Likes
Message 24 of 31

nkamphui
Enthusiast
Enthusiast

Thanks for the reply. @ВeekeeCZ solution worked best for me.

 

 

0 Likes
Message 25 of 31

stevor
Collaborator
Collaborator

And Autolisp probably could save time, maybe 99%+,

by doing them all at once.

One way could be to define a search distance, like 3

Drawing Units, if the DUs are by cm, from an insert

 point of an INSERT, ie, 'block,  to find the closest 'pipe,' 

using the ssget "c" function.

Then modify that pipe object to match the insert pt,

with the entmod function.

 

S
0 Likes
Message 26 of 31

nkamphui
Enthusiast
Enthusiast

Thankyou very much, works perfect! Transformed all lines to 3D polylines without issues. Only lines that are perfectly straight dissappear when executing this LISP. But i can do those by hand. Thanks again!

0 Likes
Message 27 of 31

ВeekeeCZ
Consultant
Consultant

@ВeekeeCZ wrote:

This works quite well for 3dpolylines.

BUT not with lwpolylines - if there is one, you need to unselect its block! See HERE  what I mean.

 


 

... or pair it the other way around. For each pline end point search for the closest block insertion point. But I guess the way it is now is good enough.

0 Likes
Message 28 of 31

pbejse
Mentor
Mentor

@nkamphui wrote:

Thankyou very much, works perfect!


Now you see the rainbow  @nkamphui 🙂

0 Likes
Message 29 of 31

hak_vz
Advisor
Advisor

@nkamphui wrote:

Thanks for the reply. @ВeekeeCZ solution worked best for me.

 

 


Where @ВeekeeCZ solution don't work you can apply this (Lwpoly) . I'm at work and don't have a time to code something like he did. My solution is single line function written "out of sleave". I'm glad that you received a solution to your problem.

Miljenko Hatlak

EESignature

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.
0 Likes
Message 30 of 31

ВeekeeCZ
Consultant
Consultant
Accepted solution

@ВeekeeCZ wrote:

@ВeekeeCZ wrote:

This works quite well for 3dpolylines.

BUT not with lwpolylines - if there is one, you need to unselect its block! See HERE  what I mean.

 


 

... or pair it the other way around. For each pline end point search for the closest block insertion point. 


 

The other way around without the need to unselect no-match blocks. Also added distance limitation.

 

(vl-load-com)

(defun c:FixPlineToBlock ( / s i e o c lst-b lst-p)

  (if (setq s (ssget '((0 . "POLYLINE,INSERT"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
      (if (= "INSERT" (cdr (assoc 0 (entget e))))
	(setq lst-b (cons (cdr (assoc 10 (entget e)))
			  lst-b))
	(setq lst-p (cons (cons (setq o (vlax-ename->vla-object e))
				(setq c (reverse (vlax-get o 'Coordinates))
				      c (list (nth 2 c) (nth 1 c) 0)))
			  lst-p)))))
  (if (and lst-b lst-p)
    (foreach p lst-p
      (setq lst-b (vl-sort lst-b '(lambda (b1 b2) (< (distance b1 (cdr p)) (distance b2 (cdr p))))))
      (if (< (distance (car lst-b) (cdr p)) 2.)
	(progn
	  (vlax-put (car p) 'Coordinates (append (reverse (cdddr (reverse (vlax-get (car p) 'Coordinates)))) (car lst-b)))
	  (setq lst-b (cdr lst-b))))))
  (princ)
  )

 

Message 31 of 31

nkamphui
Enthusiast
Enthusiast

This works even better thanks!

0 Likes