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.
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Solved by dlanorh. Go to Solution.
Solved by dlanorh. Go to Solution.
Solved by dlanorh. Go to Solution.
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
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,
Attachment 1 is what I got, 2 is what I need how it needs to be rotated automaticly for whole drawing.
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.
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.
I am not one of the robots you're looking for
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.
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 🙂
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?
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
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:
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
There are some flaws with the polylines. Use the OVERKILL to fix them first. Then the routine should work.
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.