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

Rotating multiple blocks parallel to polyline

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
luk_konto
917 Views, 10 Replies

Rotating multiple blocks parallel to polyline

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.

10 REPLIES 10
Message 2 of 11
Kent1Cooper
in reply to: luk_konto

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
Message 3 of 11
Sea-Haven
in reply to: Kent1Cooper

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.

Message 4 of 11
luk_konto
in reply to: luk_konto

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.

 

Message 5 of 11
komondormrex
in reply to: luk_konto

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

Message 6 of 11
CADaSchtroumpf
in reply to: luk_konto

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)
)
Message 7 of 11
Sea-Haven
in reply to: luk_konto

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

 

Message 8 of 11
luk_konto
in reply to: luk_konto

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.

Message 9 of 11
CADaSchtroumpf
in reply to: luk_konto

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

 

Message 10 of 11
luk_konto
in reply to: luk_konto

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

Message 11 of 11

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta