Macro to draw and mitre a board

  •  'mitre.d3m
    'a DesignCAD macro tested on version 15.3
    'draw and mitre a board (box)
    'type 1 is for picture frame style mitres
    'type two is for a 3D box style mitre
    'asks user for the layer on which to draw
    'the default is to search out the lowest numbered layer which is empty and not locked
    'asks user for 3 color values to set the RGB color with which to draw
    'defaults to 0 in all three cases
    'user must supply a length and square cross section for the board
    'escape backs out 1 input level at a time then terminates
    'original layer and color states are preserved and restored

    'todo:
    'code to mitre boards that are not square in cross section
    'code to create all 10 rotations of the mitred board

    'this code is in the public domain. Use it, abuse it, send me feedback!

    'Ed Musgrove 27 Feb 2005 edgarmusgrove@yahoo.com
'must get current drawing color then restore upon exit
originalDrawingColorRed = sys(300)
originalDrawingColorGreen = sys(301)
originalDrawingColorBlue = sys(302)

precision 0
GetDrawingLayer:
userSupplied = 1
input "Enter empty layer into which the board will be drawn (default = first empty after 0).", eL$
if Sys(999) = 1 then goto Terminate
if ( eL$ = "" ) then
'find first empty layer after 0
for i = 1 to 1000
isEmptyLayer = layer(i)
if ( NOT (ODD(isEmptyLayer) = 1 ) ) then 'layer not empty
'is it locked?
if ( isEmptyLayer > 5 ) then
emptyLayer = i
userSupplied = 0
message "Board will be drawn in layer ", i, "."
exit for
endif
endif
next i
else
emptyLayer = val(eL$)
endif

if ( userSupplied = 1) then 'check the user supplied layer for validity
'is it a valid layer number?
if ( emptyLayer < 0 ) then
message "Must be a valid layer number between 0 and 1000 inclusive!"
goto GetDrawingLayer
else
if ( emptyLayer > 1000 ) then
message "Must be a valid layer number between 0 and 1000 inclusive!"
goto GetDrawingLayer
endif
endif

'is it an empty layer?
isEmptyLayer = layer(emptyLayer)
if ( ODD(isEmptyLayer) = 1 ) then 'layer not empty
message "Layer is not empty, choose another!"
goto GetDrawingLayer
endif

'is it locked?
if ( isEmptyLayer < 5 ) then
message "Layer is locked, choose another!"
goto GetDrawingLayer
endif
endif

'if we slice while other stuff is visible, it will be sliced as well
dim layerStates(1001)
for i = 0 to 1000
layerStates(i) = layer(i)
next i
for i = 0 to 1000
if ( NOT ( i = emptyLayer ) ) then layer(i) = 0 'not current, not editable, not visible
next i
layer(emptyLayer) = 14 'make the drawing layer current, editable, and visible


GetRed:
input "Enter RED value for drawing color (default = 0).", rgbR$
if ( Sys(999) = 1 ) then goto GetDrawingLayer
if ( rgbR$ = "" ) then
rgbRed = 0
else
rgbRed = val(rgbR$)
if ( rgbRed < 0 ) then
message "Red color value must be between 0 and 255 inclusive!"
goto GetRed
endif
if ( rgbRed >255 ) then
message "Red color value must be between 0 and 255 inclusive!"
goto GetRed
endif
endif

GetGreen:
input "Enter GREEN value for drawing color (default = 0).", rgbG$
if ( Sys(999) = 1 ) then goto GetDrawingLayer
if ( rgbG$ = "" ) then
rgbGreen = 0
else
rgbGreen = val(rgbG$)
if ( rgbGreen < 0 ) then
message "Green color value must be between 0 and 255 inclusive!"
goto GetGreen
endif
if ( rgbGreen >255 ) then
message "Green color value must be between 0 and 255 inclusive!"
goto GetGreen
endif
endif

GetBlue:
input "Enter BLUE value for drawing color (default = 0).", rgbB$
if ( Sys(999) = 1 ) then goto GetDrawingLayer
if ( rgbB$ = "" ) then
rgbBlue = 0
else
rgbBlue = val(rgbB$)
if ( rgbBlue < 0 ) then
message "Blue color value must be between 0 and 255 inclusive!"
goto GetBlue
endif
if ( rgbBlue >255 ) then
message "Blue color value must be between 0 and 255 inclusive!"
goto GetBlue
endif
endif

ReenterType:
typeOK = 0
input "Enter mitre type (1 or 2, default = 2).", mT$
if Sys(999) = 1 then end
if (mT$ = "") then
mitreType = 2
else
mitreType = val(mT$)
endif
if (mitreType = 1) then
typeOK = 1
else
if (mitreType = 2) then typeOK = 1
endif
if (typeOK = 0) then
message "Only 1 and 2 are valid entries!"
goto ReenterType
endif

precision 15
ReenterBoard:
input "Enter length for board.", bL$
if Sys(999) = 1 then goto ReenterType
if ( bL$ = "" ) then
message "Sorry, no default for board length!"
goto ReenterBoard
endif
boardLength = val(bL$)
if ( boardLength <= 0 ) then
message "Board must have a positive value for length!"
goto ReenterBoard
endif

ReenterCrossSection:
input "Enter cross section of board.", bcS$
if Sys(999) = 1 then goto ReenterType
if ( bcS$ = "" ) then
message "Sorry, no default for board cross section!"
goto ReenterCrossSection
endif
crossSection = val(bcS$)
if ( crossSection <= 0 ) then
message "Board must have a positive value for cross section!"
goto ReenterCrossSection
endif

'I supose we should make sure that the board is big enough to mitre
if ( (crossSection * 2) >= boardLength ) then
message "Board length must be greater than twice the cross section!"
goto ReenterBoard
endif

>Box
{
<Color [rgbRed, rgbGreen, rgbBlue]
<Pointxyz 0, 0, 0
<Pointrel [boardLength, crossSection, crossSection]
}

'if (mitreType = 1) then two slices are all that is needed--one at each end
>Slice
{
<SelectOnly 0
<Type 0
<Pointxyz [0, 0, crossSection]
<Pointxyz 0, 0, 0
<Pointxyz [crossSection, crossSection, (crossSection/2)]
<Pointxyz [0, crossSection, (crossSection/2)] 'throw away cutoffs
}

>Slice
{
<SelectOnly 0
<Type 0
<Pointxyz [boardLength, 0, 0]
<Pointxyz [boardLength, 0, crossSection]
<Pointxyz [boardLength - crossSection, crossSection, (crossSection/2)]
<Pointxyz [boardLength, crossSection, (crossSection/2)]
}

if (mitreType = 2) then 'make another pair of slices
>Slice
{
<SelectOnly 0
<Type 0
<Pointxyz [crossSection, 0, 0]
<Pointxyz [0, 0, crossSection]
<Pointxyz [crossSection, crossSection, 0]
<Pointxyz 0, 0, 0
}

>Slice
{
<SelectOnly 0
<Type 0
<Pointxyz [boardLength, 0, crossSection]
<Pointxyz [boardLength - crossSection, crossSection, 0]
<Pointxyz [boardLength - crossSection, 0, 0]
<Pointxyz [boardLength, 0, 0]
}
endif

Terminate: 'restore what we hijacked
sys(300) = originalDrawingColorRed
sys(301) = originalDrawingColorGreen
sys(302) = originalDrawingColorBlue

for i = 0 to 1000
if ( ODD(layerStates(i)) = 1 ) then
layer(i) = layerStates(i) - 1 ' if state is ODD use the next lower evwen value
else
layer(i) = layerStates(i)
endif
next i

>FitToAllWindow
{
}

Regen

end
 

File to Download:

mitre.zip