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

Block rotation by layer

33 REPLIES 33
SOLVED
Reply
Message 1 of 34
Fleww
2506 Views, 33 Replies

Block rotation by layer

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.

33 REPLIES 33
Message 2 of 34
dlanorh
in reply to: Fleww

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

Message 3 of 34
SeeMSixty7
in reply to: Fleww

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,

 

Message 4 of 34
Fleww
in reply to: dlanorh

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

Message 5 of 34
Fleww
in reply to: SeeMSixty7

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.

Message 6 of 34
SeeMSixty7
in reply to: Fleww

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.

 

 

Message 7 of 34
dlanorh
in reply to: Fleww

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

Message 8 of 34
SeeMSixty7
in reply to: Fleww

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.

 

Message 9 of 34
Fleww
in reply to: dlanorh

I putted just 1 in 2010, now its both.

Message 10 of 34
Fleww
in reply to: SeeMSixty7

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 🙂

Message 11 of 34
ВeekeeCZ
in reply to: Fleww

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?

Message 12 of 34
dlanorh
in reply to: Fleww

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

Message 13 of 34
Fleww
in reply to: dlanorh

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:

Message 14 of 34
Fleww
in reply to: ВeekeeCZ

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.

Message 15 of 34
Fleww
in reply to: dlanorh

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

Message 16 of 34
dlanorh
in reply to: Fleww

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

Message 17 of 34
Fleww
in reply to: dlanorh

this is .dwg 🙂

Message 18 of 34
ВeekeeCZ
in reply to: Fleww

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

 

Message 19 of 34
Fleww
in reply to: dlanorh

perfect tnx so much <3.

Message 20 of 34
dlanorh
in reply to: Fleww

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

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