DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Rotate Macro - How to?

Started by noely71, June 22, 2010, 06:50:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

noely71

Hi,

I hope this hasnt been asked, i couldn't find it anywhere.

I need to create a macro that rotates 90° left/Right. How can this be done? I've been using DC for years, but i'm new to macros. I've tried to record one just by using the record function, selecting an abject rotating it. stop etc...
Obviously something in my logic isn't correct here.

Any help appreciated.

Noely71

Rob S

#1
Select objects, and run the following macro.  It will rotate your selection counterclockwise 90 degrees about the selection handle.

I created it by recording the action, and then deleting the superfluous bits.  Just copy the text into notepad, and save it as "rotateleft90.d3m" in your macros folder.

It could be made fancier by having it ask the user to select objects, if there is no existing selection.

' rotateleft90
' for right90, change angle to minus 90

>Rotate
{
 <Axis 2
 <Angle 90.0000
 <DragMode 0
 <ThroughHandle 1
 <MakeCopy 0
 <Increment 0.0000
 }

User since forever

edgar

Here is a version I use:

'Program: rot.d3m
precision 15
if sys(80)=0 then
' sys(1027) = 0  'msg box style OK -- default
message "Nothing selected...ending!"
end
end if

' Get Boundary of Selected object
minx = sys(196)
miny = sys(197)
maxx = sys(198)
maxy = sys(199)
minz = sys(200)
maxz = sys(201)
avgx = (minx+maxx)/2.0
avgy = (miny+maxy)/2.0
avgz = (minz+maxz)/2.0

>sethandle
{
<pointxyz [avgx, avgy, avgz]
}

sys(36)=1
if Sys(344) = 1 then 'true if in 2d mode
axis$="z"
goto SpinIt
endif

GetAxis:
'if axis$="" then input "Enter axis of rotation - x, y ,z", axis$
print "Enter axis of rotation - x, y ,z"
Anykey axis$
if Sys(999) = 1 then end ' escape key
a = 3
if axis$="x" or axis$="X" THEN a=0
if axis$="y" or axis$="Y" THEN a=1
if axis$="z" or axis$="Z" THEN a=2
if a = 3 then
message "Axis must be either X, Y, or Z, try again!"
goto GetAxis
endif

SpinIt:
input "Enter angle of rotation (default = 90).", da$
if Sys(999) = 1 then goto GetAxis ' escape key
if (da$ = "") then
da = 90
else
da = val(da$)
endif

>Rotate
{
<Axis [a]
<Angle [da]
}
>RegenerateAll
{
}
end


it sets the handle at the "center" of the object and defaults to 90 degrees about the Z axis but allows the user some latitude.

I'm no great macro writer so there me well be ways of improving this. Everyone is welcome to provide suggestions for improvement!

One especially troubling item is the "Set Precision 15". This was one of the first macros I wrote and I use it a lot. In later macros I store the current precision, set to 15, do the work then restore the original precision. I wonder if it matters one way or the other!
-Ed

noely71

Great, I'll give these a try.

Thank you!

noely71

Hi, Ive just tried to use the macros you sent me, thank you again.

Edgar. Is this macro made to rotate singe objects, or groups, solids or blocks? I cannot get it to do the last 3, it turns all lines horizintal, and left my text the same orientation (block). and turns all objects 90° seperately/not as a group (group/solid).

Robs. An error with "ThroughHandle 1" appeared.

Any input appreciated,

Noely71

Rob S

#5
What version are you using?  Throughhandle was already in use in V17

You can comment out that line (put a quote mark in front of it) and try again see if that helps.

I tried running it in V17 and it produced an error on <MakeCopy 0 so that option did not exist for V17

The following version works in V17 as well as V19 and V20, I don't have a V18 to test with

' rotateleft90
' for right90, change angle to minus 90

>Rotate
{
 <Axis 2
 <Angle 90.0000
 <DragMode 0
 <ThroughHandle 1
 if sys$(105)>"17.9" then <MakeCopy 0
 if sys$(105)>"17.9" then <Increment 0.0000
 }




User since forever

edgar

Quote from: noely71 on June 27, 2010, 06:45:12 PM

Edgar. Is this macro made to rotate singe objects, or groups, solids or blocks? I cannot get it to do the last 3, it turns all lines horizintal, and left my text the same orientation (block). and turns all objects 90° seperately/not as a group (group/solid).

This macro was created in version 15 and worked for me there. It seems to have major problems on my v20 system--I'm not sure if it is the macro, the machine or the program (or a new keyboard shortcut conflict--nope)!

As for groups and blocks, I'm not sure I have ever tried to use it on those. Solids and 2-D objects were OK.

If I have some spare time (not too likely) I will try to see where my macro is going astray. BTW, the built-in Rotate seems to be working well for me (I use it now instead of my version which I created to eliminate the extra keypresses the built-in requires).
-Ed

noely71

Thanks,

Rob, I put the ' mark there and it works perfectly both left and right.

Edgar, I'm setting DC up for a client who doesn't know CAD, but wants to edit event floor plans easily, I'm trying to eliminate excess 'CAD' work for her!

Anyway, thanks for you help!

Noely71