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.

Automatic scaling macro using right-clics

Started by JJG, September 17, 2010, 09:53:17 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JJG

Because I had recently an enormous number of sections to be adjusted using the scaling commands, I created the following macros, for not having manualy a lot of calculations to do : DesignCAD can do it automatically, and with the highest degree of precision that it is capable.
This macro therefore, in some ways, is the following as the one proposed by "Impulse" in the topic "Scale by target distance macro"
( http://forum.designcad.com/index.php?topic=190.0 )
but is only a graphical-method (requires no data to enter), and very intuitive.

This macro automatically adjusts the size of the selection in the ratio of two lengths, which are:
1) length between the reference-point of the selection and the first set-point (="initial-size") ;
2) length between the reference-point of the selection and the second set-point (="final-size").
As for controlling orthoscale native DesignCAD's command, this macro assumes that something is selected, and therefore, the reference-point of selection is known.
Also, there is no need to re-set it again : it is automatically starting point for the calculation.

Finally, we may note that :
1) to undo the action of this macro, only one ctrl z is require ... exactly like the native  scale-commands of Designcad.
2) works both in 2D and 3D mode as well.

'Automatic Orthoscale macro using rigth-clics    JJG  sep. 2010
'This macro automatically adjusts the size of the selection in the ratio of two lengths, which are:
'1) length between the reference point of the selection and the first set-point (="initial-size") ;
'2) length between the reference point of the selection and the second set-point (="final-size").
'As for controlling orthoscale native DesignCAD's command, this macro assumes that something is selected,
'and therefore, the point of selection is known. Also, there is no need to re-set it again : it is automatically
'starting point for the calculation.

a=sys(242) 'Store Select object when created statment [0=no, 1=yes]

If sys(80)<1 then goto ESC

sys(996) = 1 'Enhanced Esc Key Behavior

Sx=sys(190)  'Selection Handle 1 X value
Sy=sys(191)  'Selection Handle 1 Y value
Tx=sys(192)  'Selection Handle 2 X value
Ty=sys(193)  'Selection Handle 2 Y value
Ux=sys(194)  'Selection Handle 3 X value
Uy=sys(195)  'Selection Handle 3 Y value
Sz=sys(202)  'Selection Handle 1 Z value
Tz=sys(203)  'Selection Handle 2 Z value
Uz=sys(204)  'Selection Handle 3 Z value

CAPTURE: 'capture of needed points for scaling
sys(242)=1    'Select object when created [0=no, 1=yes]

a$="Set the corresponding points (preferably using right-click) : 1-initial Size ; 2-final Size."

>line
{
  <MaxPoints 3
  <CmdPrompt [a$]
  <PointXYZ [Sx, Sy, Sz]
  <incomplete
  }
'note =   <MaxPoints 3 = this command accepts up to 3 points

If sys(80)<>1 then goto fin
getselect 1,j
entity j
If sys(90)<>1 then goto fin '1 is line-type
If sys(99)<3 then goto CAPAGAIN
'Note: if you capture 2x the same pt (ie if R = I), DesignCAD do counts as only 1 pt, so no risk of division by 0 with the ratio Li
Dim x(sys(99))
Dim y(sys(99))
Dim z(sys(99))

' # Reading of construction-points #
for t=1 to sys(99)
pointval x(t), y(t), z(t), t
next t

>SelectDelete
{
  }

>SelectPrevious
{
   }

>SetHandle
{
  <PointXYZ [Sx,Sy,Sz]
  <PointXYZ [Tx,Ty,Tz]
  <PointXYZ [Ux,Uy,Uz]
  }

Rx = x(1)
Ry = y(1)
Rz = z(1)

Ix = x(2)
Iy = y(2)
Iz = z(2)

Fx = x(3)
Fy = y(3)
Fz = z(3)

'# Calculation of scaling-ratio #
Li = sqrt(sqr(Rx-Ix)+sqr(Ry-Iy)+sqr(Rz-Iz))
Lf = sqrt(sqr(Rx-Fx)+sqr(Ry-Fy)+sqr(Rz-Fz))

ZoomF = Lf/Li

>SelectScaleOrtho
{
  <ZoomFactor [ZoomF]
  }


FIN:
sys(242)=a 'restore initial setting of Select object when created statment
End.


CAPAGAIN:
inf$="Please run the macro again and : set correctly the points for calculations, wich are at 2 = Click (preferably using right-click) on : 1-initial length ;  2-final Length "
message inf$
>SelectDelete
{
  }
>SelectPrevious
{
   }
end.


ESC:
inf$="Please select at least one entity, then run the macro"
message inf$
end.


JJG

#1
I naturally write the associated macros to this previous one ::

1) X-scaling capablity :
'Automatic X-scaling macro using right-clics   JJG sep. 2010
'This macro automatically adjusts the size of the selection in the ratio of two lengths, which are:
'1) length between the reference point for the selection and the first set-point (="initial-size") ;
'2) length between the reference point for the selection and the second set-point (="final-size").
'As for controlling orthoscale native DesignCAD's command, this macro assumes that something is selected,
'and therefore, the point of selection is known. Also, there is no need to re-set it again : it is automatically
'starting point for the calculation.

a=sys(242) 'Store Select object when created statment [0=no, 1=yes]

If sys(80)<1 then goto ESC

sys(996) = 1 'Enhanced Esc Key Behavior

Sx=sys(190)   'Selection Handle 1 X value
Sy=sys(191)   'Selection Handle 1 Y value
Tx=sys(192)   'Selection Handle 2 X value
Ty=sys(193)   'Selection Handle 2 Y value
Ux=sys(194)   'Selection Handle 3 X value
Uy=sys(195)   'Selection Handle 3 Y value
Sz=sys(202)   'Selection Handle 1 Z value
Tz=sys(203)   'Selection Handle 2 Z value
Uz=sys(204)   'Selection Handle 3 Z value

CAPTURE: 'capture of needed points for scaling
sys(242)=1   'Select object when created [0=no, 1=yes]

a$="Set the corresponding points (preferably using right-click) : 1-initial Size ; 2-final Size."

>line
{
 <MaxPoints 3
 <CmdPrompt [a$]
 <PointXYZ [Sx, Sy, Sz]
 <incomplete
 }
'note =   <MaxPoints 3 = this command accepts up to 3 points

If sys(80)<>1 then goto fin
getselect 1,j
entity j
If sys(90)<>1 then goto fin '1 is line-type
If sys(99)<3 then goto CAPAGAIN
'Note: if you capture 2x the same pt (ie if R = I), DesignCAD do counts as only 1 pt, so no risk of division by 0 with the ratio Li
Dim x(sys(99))
Dim y(sys(99))
Dim z(sys(99))

' # Reading of construction-points #
for t=1 to sys(99)
pointval x(t), y(t), z(t), t
'a$=x(t)
'b$=y(t)
'mes$=a$+" ; "+b$
'message mes$
next t

>SelectDelete
{
 }

>SelectPrevious
{
  }

>SetHandle
{
 <PointXYZ [Sx,Sy,Sz]
 <PointXYZ [Tx,Ty,Tz]
 <PointXYZ [Ux,Uy,Uz]
 }

Rx = x(1)
'Ry = y(1)
'Rz = z(1)

Ix = x(2)
'Iy = y(2)
'Iz = z(2)

Fx = x(3)
'Fy = y(3)
'Fz = z(3)

'# Calculation of scaling-ratio #
Lix = sqrt(sqr(Rx-Ix))
Lfx = sqrt(sqr(Rx-Fx))
if Lix = 0 then
inf$="the choose of the point corresponding to the Initial Size is not good : its X coordinate is the same as the main point of reference for the selection. Please choose a more appropriate point, then start the macro again."
message inf$
end
endif

ZoomX = Lfx/Lix

>SelectScale
{
 <Scale [ZoomX], 1, 1
 }


FIN:
sys(242)=a 'restore initial setting of Select object when created statment
End.


CAPAGAIN:
inf$="Please run the macro again and : set correctly the points for calculations, wich are at 2 = Click (preferably using right-click) on : 1-initial length ;  2-final Length "
message inf$
>SelectDelete
{
 }
>SelectPrevious
{
  }
end.


ESC:
inf$="Please select at least one entity, then run the macro"
message inf$
end.


(for Y-scaling and Z-scaling, I will let you replace the variables and the correct formula for calculating the ratio !)

JJG

and 2)
a XYZ-scaling (together, independently and simultaneously) macro ; in this latter one, there are some adjustments that can detect if it is a X-Scale only, a Y-scale only, a XY-scale only , etc ..., which simplifies its use in a intuitive way.
May require a little adjustment period to understand how to provide for the construction points to get the desired result, but because it only requires one ctrl Z to undo any wrong operation ... it's no problem !
'Automatic XYZ-scaling (together, independently and simultaneously) macro using right-clics   JJG sep. 2010
'This macro automatically adjusts the size of the selection in the ratio of two lengths, which are:
'1) length between the reference point for the selection and the first set-point (="initial-size") ;
'2) length between the reference point for the selection and the second set-point (="final-size").
'As for controlling orthoscale native DesignCAD's command, this macro assumes that something is selected,
'and therefore, the point of selection is known. Also, there is no need to re-set it again : it is automatically
'starting point for the calculation.

a=sys(242) 'Store Select object when created statment [0=no, 1=yes]

If sys(80)<1 then goto ESC

sys(996) = 1 'Enhanced Esc Key Behavior

Sx=sys(190)  'Selection Handle 1 X value
Sy=sys(191)  'Selection Handle 1 Y value
Tx=sys(192)  'Selection Handle 2 X value
Ty=sys(193)  'Selection Handle 2 Y value
Ux=sys(194)  'Selection Handle 3 X value
Uy=sys(195)  'Selection Handle 3 Y value
Sz=sys(202)  'Selection Handle 1 Z value
Tz=sys(203)  'Selection Handle 2 Z value
Uz=sys(204)  'Selection Handle 3 Z value

CAPTURE: 'capture of needed points for scaling
sys(242)=1    'Select object when created [0=no, 1=yes]

a$="Set the corresponding points (preferably using right-click) : 1-initial Size ; 2-final Size."

>line
{
  <MaxPoints 3 'this command accepts up to 3 points
  <CmdPrompt [a$]
  <PointXYZ [Sx, Sy, Sz]
  <incomplete
  }

'note =   <MaxPoints 3 = this command accepts up to 3 points

If sys(80)<>1 then goto fin
getselect 1,j
entity j
If sys(90)<>1 then goto fin '1 is line-type
If sys(99)<3 then goto CAPAGAIN
Dim x(sys(99))
Dim y(sys(99))
Dim z(sys(99))

' # Reading of construction-points #
for t=1 to sys(99)
pointval x(t), y(t), z(t), t
next t

>SelectDelete
{
  }

>SelectPrevious
{
   }

>SetHandle
{
  <PointXYZ [Sx,Sy,Sz]
  <PointXYZ [Tx,Ty,Tz]
  <PointXYZ [Ux,Uy,Uz]
  }

Rx = x(1)
Ry = y(1)
Rz = z(1)

Ix = x(2)
Iy = y(2)
Iz = z(2)

Fx = x(3)
Fy = y(3)
Fz = z(3)

'# Calculation of scaling-ratio #
Lix = sqrt(sqr(Rx-Ix))
Lfx = sqrt(sqr(Rx-Fx))
if Lfx = 0 then Lfx = 1
if Lix = 0 then Lix = Lfx

Liy = sqrt(sqr(Ry-Iy))
Lfy = sqrt(sqr(Ry-Fy))
if Lfy = 0 then Lfy = 1
if Liy = 0 then Liy = Lfy

ZoomX = Lfx/Lix
ZoomY = Lfy/Liy

If sys(344)= 1 then
goto ZOOM2D 'sys(344)= 1 = 2D-drawing mode
else
goto ZOOM3D
end if

ZOOM2D:
>SelectScale
{
  <Scale [ZoomX], [ZoomY], 1
  }

GOTO FIN


ZOOM3D:
Liz = sqrt(sqr(Rz-Iz))
Lfz = sqrt(sqr(Rz-Fz))
if Lfz = 0 then Lfz = 1
if Liz = 0 then Liz = Lfz

ZoomZ = Lfz/Liz
>SelectScale
{
  <Scale [ZoomX], [ZoomY], [ZoomZ]
  }


FIN:
sys(242)=a 'restore initial setting of Select object when created statment
End.


CAPAGAIN:
inf$="Please run the macro again and : set correctly the points for calculations, wich are at 2 = Click (preferably using right-click) on : 1-initial length ;  2-final Length "
message inf$
>SelectDelete
{
  }
>SelectPrevious
{
   }
end.


ESC:
inf$="Please select at least one entity, then run the macro"
message inf$
end.

Lar

Nice work, JJG. You can set a point anywhere in the selection and scale that point to another point anywhere in the drawing.

Lar

JJG