News:

Please note new Forum URL: forum.designcad.com

Main Menu
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.

ortho flip copy

Started by bdeck, May 16, 2007, 08:37:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bdeck

These two macros perform a combination of  mirror and duplicate in a single operation.

They also include an ortho constraint, which can be removed to yield a universal mirror/duplicate command.

OrthoFlipCopy2.d3m relies on preset handles, and once started, requires only 2 mouse clicks and no dialog box.

OrthoFlipCopy.d3m needs no handles, and requires 3 mouse clicks and no dialog box.

By removing portions of the code, these may be converted to ortho flip, or just plain flip.

If duplicate function is changed to move, the second mirror function should be removed.

Although written in 3d format, they work only in 2d.

Thanks to Lar and Prl.

BD



' OrthoFlipCopy2.d3m     Bdeck 5/15/07
'
' Select object; run macro.
'
' Set 2 points:
'     1  target point for duplicate
'     2  approximate direction of mirror axis from point 1
'
' Also works in preset point mode
'
' Note that sys(36) prevents dialog box cleanup errors.
' Sys(1)=0 does not clean up set points in preset point mode.

if sys(80) <1 then end (if no items selected)
sflag=sys(36)
sys41=sys(41)    'archive rubberband style

dim x(6),y(6), z(6)
n=sys(1)   

if (n=2) then goto gottem                  'use correctly set points
sys(1)=0

Sys(41) = 1  'set rubber band style

setpoint "Set 2 points Target,  Axis" 2
   
n=sys(1)                   
if n<>2 then goto cleanup

gottem:


sys(36)=1

for i=1 to n
   pointval x(i) y(i) z(i) i
next i

if n=2 then   


  ' ortho correction              vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

    dx= abs(x(2)-x(1))
    dy= abs(y(2)-y(1))
    dz= abs(z(2)-z(1))

   if (dy>dx and dy>dz) then             
          x(2)=x(1)
          z(2)=z(1)         
   else
      if dz>dx and dz>dy then
          x(2)=x(1)
         y(2)=y(1)
      else
         y(2)=y(1)
         z(2)=z(1)
      endif
   endif
' ortho correction         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   >Mirror
   {
         <Axis 4   'custom mirror, the only one worth using.
         <Type 0   ' dont make copy
         <Pointxyz [x(1), y(1), z(1)]
         <Pointxyz [x(2), y(2), z(2)]
   }
   >Duplicate ' MAKE A COPY OF THE FLIPPED

   {
      <Reference 0   ' 0 = use handle 1=from reference point
      <Type 1   ' 1 = fixed scale]
      <Pointxyz [x(1), y(1), z(1)]
      '<Pointxyz [x(2), y(2), z(2)]              ' remove the ortho constraint and activate this line to improve functionality
   }

   >Mirror  ' PUT THE ORIGINAL BACK WHERE IT WAS
   {
         <Axis 4   'custom mirror, the only one worth using.
         <Type 0   ' dont make copy
         <Pointxyz [x(1), y(1), z(1)]
         <Pointxyz [x(2), y(2), z(2)]
   }

endif

cleanup:       
Sys(41) = sys41
sys(36)=sflag
sys(1)=0     'clean up unused points

REGEN  ' Necessary to cleanup mouse tracks from setpoint command


' OrthoFlipCopy.d3m     Bdeck 5/15/07
'
' Select object; run macro.
'
' Set 3 points:
'   1  source reference point
'   2  approximate direction of mirror axis from point 1
'   3  target reference point
'
' Also works in preset point mode
'
' Note that sys(36) prevents dialog box cleanup errors.
' Sys(1)=0 does not clean up set points in preset point mode.

if sys(80) <1 then end (if no items selected)

sflag=sys(36)
sys41=sys(41)    'archive rubberband style

dim x(6),y(6), z(6)
n=sys(1)   

if (n=3) then goto gottem                  'use correctly set points
sys(1)=0

Sys(41) = 1  'set rubber band style

setpoint "Set points for Source, Axis, and Target" 3
   
n=sys(1)                   
if n<>3 then goto cleanup

gottem:

sys(36)=1

for i=1 to n
   pointval x(i) y(i) z(i) i
next i

if n=3 then   
  '    ortho correction              vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
       dx= abs(x(2)-x(1))
       dy= abs(y(2)-y(1))
   dz= abs(z(2)-z(1))

   if (dy>dx and dy>dz) then   ' ortho correction
          x(2)=x(1)
          z(2)=z(1)         
   else
      if dz>dx and dz>dy then
          x(2)=x(1)
         y(2)=y(1)
      else
         y(2)=y(1)
         z(2)=z(1)
      endif
   endif
'  ortho correction         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   >Mirror
   {
         <Axis 4   'custom mirror, the only one worth using.
         <Type 0   ' dont make copy
         <Pointxyz [x(1), y(1), z(1)]
         <Pointxyz [x(2), y(2), z(2)]
   }
   >Duplicate ' MAKE A COPY OF THE FLIPPED

   {
      <Reference 1    ' 1=from reference point
      <Type 1   ' 1 = fixed scale]
      <Pointxyz [x(1), y(1), z(1)]
      <Pointxyz [x(3), y(3), z(3)]
   }

   >Mirror  ' PUT THE ORIGINAL BACK WHERE IT WAS
   {
         <Axis 4   'custom mirror, the only one worth using.
         <Type 0   ' dont make copy
         <Pointxyz [x(1), y(1), z(1)]
         <Pointxyz [x(2), y(2), z(2)]
   }

endif

cleanup:       
Sys(41) = sys41
sys(36)=sflag
sys(1)=0     'clean up unused points

REGEN  ' Necessary to cleanup mouse tracks from setpoint command

prl

#1
Thanks BD,

Here are my versions for 2d work that uses a single point. These are meant for fast mirroring either horizontally or vertically.

'Program: hm.d3m (horizontal mirror - about y axis)

if sys(80)=0 then
  Message "Nothing selected. . . press any key to continue"
  END
end if

' Make sure we're in 2d
if Sys(344) = 0 then END '1 is 2d, 0 is 3d

if sys(1) = 0 then
  setpoint "set mirror point location", 1
end if

if sys(1) = 0 then END
pointval x1, y1, z1, 1

sys(38)= 0 'do not mirror text
>Mirror
{
<axis 4
<pointxyz [x1,y1, z1]
<pointxyz [x1,y1+1, z1]
}

sys(1)=0
sys(80)=0
end


'Program: vm.d3m (vertical mirror - about x axis)

if sys(80)=0 then
  Message "Nothing selected. . . press any key to continue"
  END
end if

' Make sure we're in 2d
if Sys(344) = 0 then END '1 is 2d, 0 is 3d

if sys(1) = 0 then
  setpoint "set mirror point location", 1
end if

if sys(1) = 0 then END
pointval x1, y1, z1, 1

sys(38)= 0 'do not mirror text
>Mirror
{
<axis 4
<pointxyz [x1,y1, z1]
<pointxyz [x1+1,y1, z1]
}

sys(1)=0
sys(80)=0
end

bdeck



Yes, Kimosabe,

Speed good.

Dialog box bad.