Rotate blocks to match viewport axis

Rotate blocks to match viewport axis

Code_x
Advocate Advocate
1,853 Views
8 Replies
Message 1 of 9

Rotate blocks to match viewport axis

Code_x
Advocate
Advocate

Hi, is there a macro that can be used to align objects to either match X axis or Y axis. I need objects to be parallel to either of those axes. Sometimes I receive blocks that are set on certain angles, and I find it very slow to align each object to a stright line. Please see the video below of what I am looking for.  If anyone knows a macro for that that would be very helpful.  Thank you!

 

Video : 

https://we.tl/t-oF1R5MASGo

0 Likes
1,854 Views
8 Replies
Replies (8)
Message 2 of 9

pendean
Community Legend
Community Legend
Using or converting those to Dynamic Blocks not an option?
0 Likes
Message 3 of 9

Code_x
Advocate
Advocate
I am just trying to rotate those blocks to be perfectly straight either horizontally or vertically. Converting these misc. blocks to be dynamic will take me longer time.
0 Likes
Message 4 of 9

pendean
Community Legend
Community Legend
You are an LT user (according to your video), so there is not going to be a LISP option for you, and there is not going to be a MACRO option to do that either since all a MACRO does is repeat what you can type exactly/precisely with no errors or variations for more than one single specific block.

Also... what would determine the correct orientation for each block in each viewport then? your video simply shows you using ALIGN command to relocated a rectangular block to a square in modelspace.
Do you just wish to automate ALIGN command with two-picks for example?

let us know your intent.
0 Likes
Message 5 of 9

Code_x
Advocate
Advocate
Some blocks are on a very minor angle which is hard to see or the lines in the block appear to be somewhat straight, in fact, those lines are on a slight angle. What I am trying to achieve is to make the block perfectly align to either X or Y so that i can work with those lines. I guess if I can somehow automate alignment command then that would be helpful too. I was looking for an automated rotate option that can make the block to be perfectly 90 degree or 180 but not 92.3.. or etc
0 Likes
Message 6 of 9

Sea-Haven
Mentor
Mentor

This will rotate a block outside of a viewport to match.

 

; Rotate a block in pspace to match world in model
; By Alan H Aug 2020

(defun c:roblklay ( / obj1 obj rot ent)
(command "._PSPACE")
(setvar 'nomutt 1)
(princ "\nSelect a viewport")
(setq sss (ssget "_+.:E:S" (list (cons 0 "Viewport"))))
(setq obj1 (vlax-ename->vla-object (ssname sss 0)))
(setq ang (vlax-get obj1 'TwistAngle))

(while (setq ent (entsel "Pick block Enter to exit"))
(setq obj (vlax-ename->vla-object (car ent)))
(vla-put-rotation obj ang)
)

(princ)
)
(c:roblklay)
0 Likes
Message 7 of 9

Code_x
Advocate
Advocate
Not sure, something doesn't work with this macro. It only triggers rotate function but then I have to specified base point and rotation angle for the block. Is that how it should work?
0 Likes
Message 8 of 9

Sea-Haven
Mentor
Mentor

What you want is different, I misread what you wanted, but a simple answer is to look at block angle and change to 0 or 90 etc. The issue I see is rotation would occur around insertion point.

 

Here is say 1 of 4 defuns 0 90 180 270 for you, note the Pi is for angle, depending on how your units are set will affect the angle. eg (/ pi 2.0) = 90 (* 1.5 pi) = 270

(defun c:B90  ( / ss ent)
(setq ss (ssget '((0 . "INSERT"))))
(repeat (setq x (sslength ss))
(setq ent (entget (ssname ss (setq x (1- x)))))
(entmod (subst (cons 50 pi) (assoc 50 ent) ent))
)
(princ)
)

 

0 Likes
Message 9 of 9

ВeekeeCZ
Consultant
Consultant

Here are two fairly simple routines. So simple that I am almost ashamed to offer them. 

 

(defun c:RotHor ( / s)
  (if (setq s (entsel "\nSelect object close to refpoint: "))
    (command "_.rotate" (car s) "" "_end,_int,_ins,_mid" (cadr s) "_ref" "_non" "@" pause 0))
  (princ)
  )


(defun c:RotVer ( / s)
  (if (setq s (entsel "\nSelect object close to refpoint: "))
    (command "_.rotate" (car s) "" "_end,_int,_ins,_mid" (cadr s) "_ref" "_non" "@" pause (angtos (/ pi 2))))
  (princ)
  )

 

0 Likes