View Full Version : Rotating a block
b_v_mc
2006-03-02, 03:20 PM
Hey all, I was wondering if I could make a button or lisp that will rotate a block. Heres my situation; I am putting together a lighting plan and we use a set length of track and number of cans on this track. So we have blocks in the autocad design center say of a 5 foot long, 2 inch thick poly line with 8 circles or cans representing the lights and some text over it saying the length and number of cans. now when i insert them there are a lot of cases where i must rotate it and it ends up upside down. Now all i have to so is rotate it 180 degrees. How would i accomplish this making a button or lisp. Ive tried before but whenever it comes to the point that i have to select an object or a basepoint it just doesnt workout.
thanks for any help.
so if Im following the guidlines for begining LISP writing, I want to write down the steps it takes to execute a command, so i have;
1:type rotate
2:select object
3:specify base point (in this case it would be the midpoint of the polyline)
4:rotation angle, which would be 180
now all i want to do is type in a command then selct what i want to rotate and have it rotate 180 degrees, without having to go through all those steps. for each one i have to rotate.
AND im using Autocad2005 Sorry
T.Willey
2006-03-02, 04:25 PM
(command "_.rotate" (ssget) "" pause 180)
All you have to do now is define a function with what you want to type to do the command.
kennet.sjoberg
2006-03-02, 05:35 PM
Here is one way to do it
(defun c:BlockRot ( / SelSet Counter EntName Obj )
(princ "Command: Rotate selected Blocks 180 degrees " )
(if (setq SelSet (ssget '((0 . "INSERT" ))) )
(progn
(setq Counter 0 )
(vl-load-com)
(while (setq EntName (ssname SelSet Counter ))
(setq Obj (vlax-ename->vla-Object EntName ) )
(vlax-put-property Obj "Rotation" (+ (vlax-get Obj "Rotation" ) pi ) )
(vlax-release-Object Obj )
(setq Counter (1+ Counter ) )
)
)
(princ ". . no Block selected ! " )
)
(princ)
)
It rotate selected blocks around its own origin.
: ) Happy Computing !
kennet
b_v_mc
2006-03-02, 06:02 PM
hey thanks guys. Kennet that lisp routine almost worked. it seemed to have grabbed the existing base point which it different for each block. when you insert a piece of trak its base point is like 5 feet away from the actual track, this is because we are lighting furniture and thats how far back we have it set away from the back of say a couch. now when i used your lisp it went from 5 feet in front of the couch to 5 feet behind. Is there a way that it will grab the middle of the track and rotate?
thanks again
hey thanks guys. Kennet that lisp routine almost worked. it seemed to have grabbed the existing base point which it different for each block. when you insert a piece of trak its base point is like 5 feet away from the actual track, this is because we are lighting furniture and thats how far back we have it set away from the back of say a couch. now when i used your lisp it went from 5 feet in front of the couch to 5 feet behind. Is there a way that it will grab the middle of the track and rotate?
thanks again
You would need to either move the insertion point of the block or pick the rotation base point yourself, most likely.
T.Willey
2006-03-02, 06:09 PM
If you know the relation of the mid point from the block insertion, you could use polar from the insertion point. You would have to look at the scale factor, and the rotation though, but it could be done.
b_v_mc
2006-03-02, 06:26 PM
You would need to either move the insertion point of the block or pick the rotation base point yourself, most likely.
yea this would probably be the best way if there's no way to get it to automatically choose the midpoint of the polyline. reason being is the base point varies depending on ceiling height and there are various ceiling heights. the base point is the back of the couch so we need to keep them so people can just drag them in and drop them at the middle of the back of a couch. So i just simply (yea right) want to flip it heh.
kennet.sjoberg
2006-03-02, 06:29 PM
. . . Kennet that lisp routine almost worked. it seemed to have grabbed the existing base point . . .Yes, it was designed that way.
Here is an other one
(defun c:BlockRot2 ( / Pkt SelSet )
(princ "\nCommand: Rotate selected Blocks 180 degrees at point. " )
(setq Pkt (getpoint " Select Rotation point : " ) )
(setq SelSet (ssget '((0 . "INSERT" ))) )
(if (and Pkt SelSet )
(command "._rotate" SelSet "" Pkt "180" )
(princ ". . no Block or Rotation Point selected ! " )
)
(princ)
)
: ) Happy Computing !
kennet
b_v_mc
2006-03-02, 06:45 PM
Yes, it was designed that way.
Here is an other one
(defun c:BlockRot2 ( / Pkt SelSet )
(princ "\nCommand: Rotate selected Blocks 180 degrees at point. " )
(setq Pkt (getpoint " Select Rotation point : " ) )
(setq SelSet (ssget '((0 . "INSERT" ))) )
(if (and Pkt SelSet )
(command "._rotate" SelSet "" Pkt "180" )
(princ ". . no Block or Rotation Point selected ! " )
)
(princ)
)
: ) Happy Computing !
kennet
Bravo! Thanks this works great thanks.
b_v_mc
2006-03-02, 06:58 PM
I could of sworn ive seen commands that just flip something anytype of object a certain degree be it 90 180 360. Or am i just crazy.
kennet.sjoberg
2006-03-02, 07:06 PM
I could of sworn ive seen commands that just flip something anytype of object a certain degree be it 90 180 360. Or am i just crazy.
. . . .mmm Ortho mode On and Command: _rotate option Reference
: ) Happy Computing !
kennet
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.