DC6 style Mirror Macro, Works in 2D or 3D, 2-Pt or 3-Pt

Started by bdeck, July 06, 2008, 08:00:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bdeck

Updated and Moved from Tips and Tricks.

This macro is a total replacement for the DC Mirror command. I assign it to the "/" key, so I  never have to look at the mirror dialog.

It performs the equivalent of the DC custom mirror in 2D or 3D.

Improvements over DC version:

1) In 2D or 3D, orthogonal mirrors may be created by holding the shift key while setting mirror points. (The shift key does not work in the DC Mirror command) So if you want a mirror parallel to the x, y, or z axis, hold the shift key while setting the second point.

2) In 3d you can set either 2 or 3 points to define the mirror plane. If only 2 points are set (by pressing the Enter key after the second point), the mirror plane will be set normal to the view plane, just as in 2D drawing mode.  Note that 2-point mirrors in 3d will be normal to the view plane of whichever window is active when the Enter key is pressed. (It must be a front, side, or top, but may be a user defined workplane.)

3) Since there is no dialog on screen, there are no issues with keyboard focus, so key commands such as "K" and " ' "  work without hassle.

BD


' cm3d.d3m   Custom Mirror 3D   BDeck  7/08
' Mirror replacement macro (this version works in 2d or 3d) 
' Allows shift key for orthogonal custom mirror.
' Eliminates need for dialog box.
' All instructions appear in status bar and messages.
'
' 2-point mirror plane in 3D is normal to view plane of the window active when return key is pressed.
' If window other than front, side, or top is active, then macro will prompt user to select a proper view window.
' 2-point mirror plane will be inaccurate if view window has been corrupted with setview command.
' Corrupted views can be restored to normal with Window/DesignCadTile command before using 2-point mirror.
'

sys(470)=1     'block other commands
sys41=sys(41)  'rubber band mode

if sys(80)=0 then
   message "No entities selected"
   end
endif

if sys(344) then  'check for 2d drawing mode
   gosub clickline
else
   gosub clickplane
endif

gosub cleanup
end

cleanup:
  sys(41)=sys41   'cleanup
  sys(1)=0
  end
return

clickline:
  Sys(41) = 1    'rubberband line for user points
  Setpoint "Set two points to define custom mirror line", 2
  If Sys(1) < 2 Then return

  sys(36)=1      ' silent mode for duration of macro

  Pointval x1 y1 z1 1 ' get the first point the user set
  Pointval x2 y2 z2 2 ' get the second point the user set

  >Mirror
  {
  <Axis 4     ' 4 = custom mirror  (Thanks to prl for documenting this parameter)
  <Type 1     ' 0 = don't make copy , 1 = copy   
  <Pointxyz [x1,y1,z1]
  <Pointxyz [x2,y2,z2]
  }
return

clickplane:
   Sys(41) = 1    'rubberband line for user points
   Setpoint "Set 2 or 3 points to define a custom mirror plane", 3

   If Sys(1) < 2 Then return

   pointval x1, y1, z1, 1
   pointval x2, y2, z2, 2
   if sys(1)=3 then
      pointval x3, y3, z3, 3
   else
      x3 = x2
      y3 = y2
      z3 = z2
      if  sys$(90)<>"front" and sys$(90) <> "side" and sys$(90) <> "top"  then
         print "Select Front, Top, or Side view window to be normal to mirror plane, or Escape to exit"
         message "2-point custom mirror must be completed in front, top, or side view. Please select a view plane"
         do while  sys$(90)<>"front" and sys$(90) <> "side" and sys$(90) <> "top"
            anykey a
            if a=27 then return
         loop
      endif
      if sys$(90) = "front" then 
          z3 = z2 + 1
          if sys(205)<>0 or sys(206)<>0 or sys(207)<>0 then gosub corrupt
      endif
      if sys$(90) = "top" then
          y3 = y2 + 1
          if sys(205)<>90 or sys(206)<>0 or sys(207)<>0 then gosub corrupt
      endif
      if sys$(90) = "side" then
            x3 = x2 + 1
            if sys(205)<>0 or sys(206)<>90 or sys(207)<>0 then gosub corrupt
      endif
     
   endif
   sys(36)=1    ' silent mode for duration of macro
   >Mirror
   {
       <Axis 4  ' 4 = custom mirror  (Thanks to prl for documenting this parameter)
       <Type 1  ' 0 = don't make copy , 1 = copy   
       <pointxyz [x1, y1, z1]
       <pointxyz [x2, y2, z2]
       <pointxyz [x3, y3, z3]
   }
return

corrupt:
     message "View plane is rotated from workplane. Restore DesignCadTiles before 2-pt mirror.
     gosub cleanup
return