Autocad block rotate lisp

Autocad block rotate lisp

Fleww
Advocate Advocate
3,942 Views
14 Replies
Message 1 of 15

Autocad block rotate lisp

Fleww
Advocate
Advocate

Hey guys, can you please help me to make lisp for this. This need to be rotated in whole drawing like in pictures and .dwg files.

Can you help me please to automate this process?right.pngwrong.png

0 Likes
Accepted solutions (4)
3,943 Views
14 Replies
Replies (14)
Message 2 of 15

Kent1Cooper
Consultant
Consultant

That is probably achievable, but it would be a little easier if you're willing to redefine the Block so that at a rotation angle of 0°, it "aims" in the 0° direction [to the right] from its insertion point, like this:

Kent1Cooper_0-1616676871421.png

[Generally, it's a good idea to define all Blocks that way.]

 

EDIT:  Also, would the end of the Polyline that one of these Blocks is attached to ever be an arc segment rather than a line segment?  It would make a difference to the method of determining the rotation angle to impose on the Block.  And/or, would they ever be attached to other kinds of objects, such as Lines or Arcs or Splines or partial Ellipses?

Kent Cooper, AIA
0 Likes
Message 3 of 15

Fleww
Advocate
Advocate

Okay I can do it than what?:) Still need some lisp right?:/

0 Likes
Message 4 of 15

Kent1Cooper
Consultant
Consultant

@Fleww wrote:

Okay I can do it then what?:) Still need some lisp right?:/


Yes.  What do you picture for the procedure?  Would the User pick the Blocks?  Or window an area and find all Blocks within it?  Would the routine find all Blocks only of a certain name?  Only on a certain Layer?

 

[And see, and answer the questions in, the EDIT of my first Reply.]

Kent Cooper, AIA
0 Likes
Message 5 of 15

Fleww
Advocate
Advocate

Only blocks on certain layer, in this case "USER" layer. Just to rotate by this "STREET" layer polyline like on picture.

I hope you understand me now? 🙂

0 Likes
Message 6 of 15

john.uhden
Mentor
Mentor

You may not need any Lisp.  I haven't opened your dwgs, but along with what @Kent1Cooper  said about the rotation angle within the definition, where is the block insertion point relative to the block objects?  You may need a more sensible block definition.

John F. Uhden

0 Likes
Message 7 of 15

Fleww
Advocate
Advocate

Can you help me with that pleaseee? I tryed my best and couldn't reach it.

0 Likes
Message 8 of 15

ВeekeeCZ
Consultant
Consultant
Accepted solution

Here's a quick on. It works with the original dwg. It works for 1 block per polyline, so remove or fix duplicates.

 

(vl-load-com)

(defun c:AlignEndBlocks ( / s i e d li lp a)

  (if (setq s (ssget '((0 . "LWPOLYLINE,INSERT"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    d (entget e))
      (if (= "INSERT" (cdr (assoc 0 d)))
	(setq li (cons (cons (reverse (cdr (reverse (mapcar '(lambda (x) (fix (* 10 x))) (cdr (assoc 10 d)))))) e) li))
	(setq lp (cons (cons (mapcar '(lambda (x) (fix (* 10 x))) (cdr (assoc 10 (reverse d)))) e) lp)))))
  (foreach x lp
    (if (setq a (assoc (car x) li))
      (entmod (append (entget (cdr a))
		      (list (cons 50 (+ (* pi 1.5) ; adjust this
					(angle '(0 0 0) (vlax-curve-getfirstderiv (cdr x) (vlax-curve-getEndParam (cdr x)))))))))))
  (princ)
  )

 

 
0 Likes
Message 9 of 15

Fleww
Advocate
Advocate

Thank you so much. Isn't it possible to make lisp for whole drawing and it's not duplicate its like it should be somewhere multiple users:/

This helped me alot. I hope it's not big problem for you to help me for whole drawing I would be very greatfull. It will save me alot.

0 Likes
Message 10 of 15

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok, it's just a quick fix.

 

(vl-load-com)

(defun c:AlignEndBlocks ( / s i e d li lp a x)

  (if (setq s (ssget '((0 . "LWPOLYLINE,INSERT"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    d (entget e))
      (if (= "INSERT" (cdr (assoc 0 d)))
	(setq li (cons (cons (reverse (cdr (reverse (mapcar '(lambda (x) (fix (* 10 x))) (cdr (assoc 10 d)))))) e) li))
	(setq lp (cons (cons (mapcar '(lambda (x) (fix (* 10 x))) (cdr (assoc 10 (reverse d)))) e) lp)))))
  (foreach a li
    (if (setq x (assoc (car a) lp))
      (entmod (append (entget (cdr a))
		      (list (cons 50 (+ (* pi 1.5) ; adjust this
					(angle '(0 0 0) (vlax-curve-getfirstderiv (cdr x) (vlax-curve-getEndParam (cdr x)))))))))))
  (princ)
  )

 

0 Likes
Message 11 of 15

Fleww
Advocate
Advocate

I have like 1k blocks, can I rotate it all on every first polyline of them with the same angle like on your lisp? Like whole drawing in one click?

0 Likes
Message 12 of 15

ВeekeeCZ
Consultant
Consultant
Accepted solution

OK

 

(vl-load-com)

(defun c:AlignEndBlocks ( / s i e d li lp a x)
  
  (if (setq s (ssget "_X" '((-4 . "<OR")
			    (-4 . "<AND") (0 . "LWPOLYLINE") (8 . "STREET") (-4 . "AND>")
			    (-4 . "<AND") (0 . "INSERT") (8 . "USER") (-4 . "AND>")
			    (-4 . "OR>"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    d (entget e))
      (if (= "INSERT" (cdr (assoc 0 d)))
	(setq li (cons (cons (reverse (cdr (reverse (mapcar '(lambda (x) (fix (* 10 x))) (cdr (assoc 10 d)))))) e) li))
	(setq lp (cons (cons (mapcar '(lambda (x) (fix (* 10 x))) (cdr (assoc 10 (reverse d)))) e) lp)))))
  (foreach a li
    (if (setq x (assoc (car a) lp))
      (entmod (append (entget (cdr a))
		      (list (cons 50 (+ (* pi 1.5) ; adjust this
					(angle '(0 0 0) (vlax-curve-getfirstderiv (cdr x) (vlax-curve-getEndParam (cdr x)))))))))))
  (princ)
  )
0 Likes
Message 13 of 15

Fleww
Advocate
Advocate

This is almost perfect !! Can you please make it work for this file too? It's total same, but doesn't rotate this well.

Can you just check this please for perfect lisp I upload dwg. drawing ❤️

0 Likes
Message 14 of 15

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok, here you go

 

(vl-load-com)

(defun c:AlignEndBlocks ( / s i e d li lpe lps a x)
  
  (if (setq s (ssget "_X" '((-4 . "<OR")
			    (-4 . "<AND") (0 . "LWPOLYLINE") (8 . "STREET") (-4 . "AND>")
			    (-4 . "<AND") (0 . "INSERT") (8 . "USER") (-4 . "AND>")
			    (-4 . "OR>"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    d (entget e))
      (if (= "INSERT" (cdr (assoc 0 d)))
	(setq li (cons (cons (reverse (cdr (reverse (mapcar '(lambda (x) (fix (* 10 x))) (cdr (assoc 10 d)))))) e) li))
	(setq lpe (cons (cons (mapcar '(lambda (x) (fix (* 10 x))) (cdr (assoc 10 (reverse d)))) e) lpe)
	      lps (cons (cons (mapcar '(lambda (x) (fix (* 10 x))) (cdr (assoc 10 d))) e) lps)))))
  (foreach a li
    (if (setq x (assoc (car a) lpe))
      (entmod (append (entget (cdr a))
		      (list (cons 50 (+ (* pi 1.5) ; adjust this
					(angle '(0 0 0) (vlax-curve-getfirstderiv (cdr x) (vlax-curve-getEndParam (cdr x))))))))))
    (if (setq x (assoc (car a) lps))
      (entmod (append (entget (cdr a))
		      (list (cons 50 (+ (* pi 0.5) ; adjust this
					(angle '(0 0 0) (vlax-curve-getfirstderiv (cdr x) (vlax-curve-getStartParam (cdr x)))))))))))
  (princ)
  )
Message 15 of 15

Fleww
Advocate
Advocate
PERFECT! Thanks so much man. God bless <3333
0 Likes