Rotating multiple blocks parallel to polyline

Rotating multiple blocks parallel to polyline

luk_konto
Explorer Explorer
2,703 Views
10 Replies
Message 1 of 11

Rotating multiple blocks parallel to polyline

luk_konto
Explorer
Explorer

Hi, this is my first post here. Can you help me with lisp that can rotate blocks parallel to selected polyline?

I have hundreds or sometimes tousands of blocks that represent measured points. Blocks consist of insertion point and text with point number next to it. I have rail or road axis as polyline object and I want to rotate all my blocks so that text is parallel to polyline. I don't want to explode my blocks, I don't want to change them. My friend wrote lisp that rotates text objects to polyline and it helps a lot but he said that working with blocks is to hard for him right now.

It would be perfect if i would first select my blocks and then polyline but if i must select all objects at the same time it is still fine.

0 Likes
Accepted solutions (2)
2,704 Views
10 Replies
Replies (10)
Message 2 of 11

Kent1Cooper
Consultant
Consultant

Are any of the Blocks at vertices?  I think if they are, the approach I imagine would align them with the down-stream segment, which may not always be what you want, depending on the drawn direction of the Polyline.  And what about up-side-down results?  Some possibilities:

Kent1Cooper_0-1684939022920.png

Should there be a different Block for certain configurations, with the Attribute on the other side of the point?

Kent1Cooper_1-1684939176404.png

Kent Cooper, AIA
0 Likes
Message 3 of 11

Sea-Haven
Mentor
Mentor

The blocks are possibly created from other software like CIV3D so would always be shown to right of X and at a fixed angle, I can see the problem of plines are they CW or CCW. So need to reverse some to force a go right. 

 

A dwg provided would be helpful not an image.

0 Likes
Message 4 of 11

luk_konto
Explorer
Explorer

My blocks are all outside of polyline geometry. I want to rotate them acording to polyline geometry direction. I can always reverse polyline direction. I will show everything in layouts. Model space in viewports will be rotated parallel to my polyline so text in blocks should be readable and horizontal. I want to do it for polyline that can be as long as 20km and with many turns like a snake. Thoes polyline represent rail or road axies. Each of tousands of blocks should have different roration angle.

 

0 Likes
Message 5 of 11

komondormrex
Mentor
Mentor

rather than posting jpeg-s, you would better attach a sample of your drawing with a target pline and blocks to rotate.

0 Likes
Message 6 of 11

CADaSchtroumpf
Advisor
Advisor
Accepted solution

A start with this?

 

(defun c:Multalign_blk ( / js dxf_cod pojs vla_po n vla_obj pt deriv alpha)
  (vl-load-com)
  (princ "\nSelect a model block: ")
  (while (not (setq js (ssget "_+.:E:S" '((0 . "INSERT"))))))
  (setq dxf_cod (entget (ssname js 0)))
  (foreach m
    (foreach n dxf_cod
      (if (not (member (car n) '(0 67 410 8 6 62 66 2))) (setq lremov (cons (car n) lremov)))
    )
    (setq dxf_cod (vl-remove (assoc m dxf_cod) dxf_cod))
  )
  (setq js (ssget "_X" dxf_cod))
  (cond
    (js
      (princ "\nSelect the polyline. ")
      (while (null (setq pojs (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))))
      (setq vla_po (vlax-ename->vla-object (ssname pojs 0)))
      (repeat (setq n(sslength js))
        (setq
          vla_obj (vlax-ename->vla-object (ssname js (setq n (1- n))))
          pt (vlax-curve-getClosestPointTo vla_po (vlax-get vla_obj 'InsertionPoint))
          deriv (vlax-curve-getfirstderiv vla_po (vlax-curve-getparamatpoint vla_po pt))
          alpha (- (atan (cadr deriv) (car deriv)) (angle '(0 0 0) (getvar "UCSXDIR")))
        )
        (vlax-put
          vla_obj
          'Rotation
          (if (or (> alpha (* pi 0.5)) (< alpha (- (* pi 0.5)))) (+ alpha pi) alpha)
        )
      )
    ) 
  )
  (prin1)
)
0 Likes
Message 7 of 11

Sea-Haven
Mentor
Mentor

Maybe this also, a seperate step if you have to multiple layouts of a long pline. 

 

Back to post if created by CIV3D I think there is a rotate to layout view for labels, which is what you want. Maybe check text style.

 

For normal text

SeaHaven_0-1685158316462.png

 

0 Likes
Message 8 of 11

luk_konto
Explorer
Explorer

Thanks CADaSchtroumpf for your reply. Your routine is great and will be helpful in many occasions but can you change one thing? Right now I need that my blocks are rotated always according to polyline direction in a way that sometimes they are upside down. All the maps that I receive have text parallel to rail axis and where stationing is increasing from left to right so if station A is at 0,0km located in the east and station B is at 100,0km in the west, then the whole map has the text upside down in model space. I attached my example file with polyline and some not rotated points.


Thanks Sea-Haven for tips, I usually create one layout frame in model space and use "Path Array" to create the rest of layouts.

0 Likes
Message 9 of 11

CADaSchtroumpf
Advisor
Advisor
Accepted solution

If I understood correctly; you want to keep the orientation following the path of the polyline and not have a reading direction in relation to the Y axis of the screen (even if it means having writings turned upside down).
Just change line 28.

          (if (or (> alpha (* pi 0.5)) (< alpha (- (* pi 0.5)))) (+ alpha pi) alpha)

to simply

          alpha

 

0 Likes
Message 10 of 11

luk_konto
Explorer
Explorer

This is exacly what I wanted. Thank you very much. In fact both lisp routines will be very helpful for me. Thanks again 🙂

0 Likes
Message 11 of 11

Leo_Gambini
Contributor
Contributor

Can you make a adjust;  just want fixed this rotation perpendicular by polygon;

its the same less 90 degrees. (to avoid some block stay one overlay anothers)

 

Thanks a lot

0 Likes