Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Block rotation by layer

Fleww
Advocate

Block rotation by layer

Fleww
Advocate
Advocate

Is there lisp to rotate all multiple blocks from one layer(many same blocks on just one layer) to first polyline(in specific layer) to just match up with them. I saw alot lisps for this but none for multiple blocks its all just click by click i need something more automatic. it dont need to be perfect.

0 Likes
Reply
Accepted solutions (4)
2,625 Views
33 Replies
Replies (33)

dlanorh
Advisor
Advisor

A sample drawing will help (saved as AutoCAD 2010 for me). The rotation bit is easy, but depends on how the block is constructed.

I am not one of the robots you're looking for

SeeMSixty7
Advisor
Advisor

Depending on what you want, but if you just want a bunch of blocks to have the same orientations based on their layer name, then you really shouldn't need AutoLISP for that functionality.

 

You can use QSELECT from Properties Dialog box. Set the paramenters to block references on a particular layer. Then it will highlight all those blocks. Then you simply scroll down to the rotation angle and input the desired angle. Done.

 

Good luck,

 

0 Likes

Fleww
Advocate
Advocate

Attachment 1 is what I got, 2 is what I need how it needs to be rotated automaticly for whole drawing.

0 Likes

Fleww
Advocate
Advocate

I know, but thats not what i need. I need all diffirent rotation for every block(all are in same layer), rotation needs to be "perfect" with specific layer which is like first polyline next to that block.

0 Likes

SeeMSixty7
Advisor
Advisor

But you want them all to be the same rotation as each other, based on the one polyline's alignment correct?

 

The accuracy you input is as accurate as it will be. You can easily obtain the correct angle of the polyline and input that for all the blocks rotation.

 

Or do you want them all to rotate toward a certain point on the polyline, from each individual insertion point?

If you want something like this then you will want an AutoLISP routine.

 

 

0 Likes

dlanorh
Advisor
Advisor
Apologies, I can't open these drawing. I should have told you that I need them saved in AutoCAD 2010 format. Is that possible?

I am not one of the robots you're looking for

0 Likes

SeeMSixty7
Advisor
Advisor

After Looking at your sample files, I realize I misunderstood what you were looking for. 

 

You want all the blocks on a particular layer to snap their rotation to the opposite end of the pline that attaches to the insertion point of your block.

 

You could resolve the issue by snapping them to those points when they are inserted instead of after the fact.

 

0 Likes

Fleww
Advocate
Advocate

I putted just 1 in 2010, now its both.

0 Likes

Fleww
Advocate
Advocate

Or do you want them all to rotate toward a certain point on the polyline, from each individual insertion point?

If you want something like this then you will want an AutoLISP routine.

 

Yes thats what I ask for 🙂

0 Likes

ВeekeeCZ
Consultant
Consultant

It would be easy to rotate them.

But what kind of process preceded this to happen that their are inserted and rotated as they are now? Is that export from some GIS system or did you insert them manually? Or using some routine? The question is whether that preceded process should rather be fixed?

0 Likes

dlanorh
Advisor
Advisor
Accepted solution

Try this. It will only work on blocks that are on the end of lines/polylines

You are asked to select a typical block, this is to get the block layer and name to define the selection set. The lisp will the select all similar blocks provided the block layer is not locked. It then selects all lines and compares the insertion point of the block with the start and end points of each line in the drawing. If a match or near match is found using a fuzz of 0.001, the block is rotated to align with the line and moved to the end of the line. If it is on the end of a line it is rotated 180 degrees to the alignment.

 

Type RB2L to run the lisp once loaded

 

(defun rh:ss2lst( ss opt / cnt lst)
  (cond ( (and ss (= (type ss) 'PICKSET))
          (repeat (setq cnt (sslength ss)) (setq lst (cons (ssname ss (setq cnt (1- cnt))) lst)))
          (if opt (setq lst (mapcar 'vlax-ename->vla-object lst)))
        )
        ( (or (not ss) (/= (type ss) 'PICKSET)) (setq lst -1))
  );end_cond
);end_defun

(defun rh:align_ang (itm pt) (angle '(0. 0. 0.) (vlax-curve-getfirstderiv itm (vlax-curve-getparamatpoint itm pt))))

(defun rh:assoc_val (dxf_code ent) (if (= (type dxf_code) 'INT) (cdr (assoc dxf_code (entget ent)))))

(vl-load-com)

(defun C:RB2L (/ *error* c_doc ent lyr bname fuzz b_lst i_pt e_pt ang)

  (defun *error* ( msg )
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
    (princ)
  );end_*error*_defun

  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        ent (car (entsel "\nSelect Typical Block to be Rotated : "))
        lyr (rh:assoc_val 8 ent)
        bname (rh:assoc_val 2 ent)
        fuzz 0.001
        b_lst (rh:ss2lst (ssget "_A" (list '(0 . "INSERT") (cons 2 bname) (cons 8 lyr))) T)
  );end_setq

  (cond (b_lst
          (setq l_lst (rh:ss2lst (ssget "_X" '((0 . "*LINE"))) T))
          (foreach blk b_lst
            (setq i_pt (vlax-get blk 'insertionpoint))
            (foreach l_obj l_lst
              (cond ( (equal i_pt (setq e_pt (vlax-curve-getstartpoint l_obj)) fuzz)
                      (setq ang (rh:align_ang l_obj e_pt))
                      (mapcar '(lambda (x y) (vlax-put blk x y)) (list 'insertionpoint 'rotation) (list e_pt ang))
                    )
                    ( (equal i_pt (setq e_pt (vlax-curve-getendpoint l_obj)) fuzz)
                      (setq ang (+ (rh:align_ang l_obj e_pt) pi))
                      (mapcar '(lambda (x y) (vlax-put blk x y)) (list 'insertionpoint 'rotation) (list e_pt ang))
                    )
              );end_cond
            );end_foreach
          );end_foreach
        )
  );end_cond
  (princ)
);end_defun

I am not one of the robots you're looking for

Fleww
Advocate
Advocate

I think this is it but some problems:

 

Select Typical Block to be Rotated :
Oops an Error : bad argument type: 2D/3D point: nil occurred.
Command:

0 Likes

Fleww
Advocate
Advocate

i just got it exported by some software to autocad and I don't have to move them I can just rotate like @dlanorh said.

There is alot of blocks in simple drawing and i need something so I can be 100% sure I did it to them all. Manual work is not so sure and so anoyying.

0 Likes

Fleww
Advocate
Advocate

I need it for whole drawing if its possible thats what i really need.

0 Likes

dlanorh
Advisor
Advisor

It should do the whole drawing, unless the selected block is on a locked layer, or some of the blocks are not on the ends of line/polylines. I know why the error is being generated, but i don't know where as once you select the block to rotate, it is automated. I would need a better sample drawing, perhaps the one causing the error, containing all line/polylines and the blocks in place.

I am not one of the robots you're looking for

0 Likes

Fleww
Advocate
Advocate

this is .dwg 🙂

0 Likes

ВeekeeCZ
Consultant
Consultant

There are some flaws with the polylines. Use the OVERKILL to fix them first. Then the routine should work.

 

0 Likes

Fleww
Advocate
Advocate

perfect tnx so much <3.

0 Likes

dlanorh
Advisor
Advisor

Your LWPolylines have an elevation, I didn't account for this. Will try to sort something.

I am not one of the robots you're looking for

0 Likes