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.

Units of Measurement sensitive distance command

Started by edgar, July 07, 2007, 08:32:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

edgar

More as an exercise in coding than anything else, I did some work on an old macro I wrote a while back. Originally, all I wanted was to hit a hotkey (I use the <*> on the keypad), gravity snap two points and get a message saying how far apart they were. I use it mainly when presenting a drawing to a client who often askes "How far is it between...?" then pointing out two features of the drawing (often floorplans or remodels of boats). Now, I wanted to make the macro supply reasonable results regardless of the base drawing Units of Measurment. My thanks to 'Impulse (James Whiting) for the streamlining of my original code!


'dist.d3m

'based on an original macro from
'Impulse (James Whiting) on the DesignCAD forum
'measuring tool using built-in Angle-Distance command

'modified 11 March 2005 by Ed Musgrove
'modified 5 July 2007 by Ed Musgrove
'to make it drawing Units Of Measurement sensitive
'edgar  on the DesignCAD forum
'[email protected]
'what I wanted was output in feet  inches  fractions  (to nearest 1/16 ")
'along with the other information

'use the status bar for prompting the user
'which seems to be the DesignCAD style philosophy
originalStatusBarVisibility = sys(223)  'do this before Top so we can re-enter
if ( originalStatusBarVisibility = 0 ) then  'off
sys(223) = 1  'turn it on
endif

' get  user default precision
userPrecision = Sys(7)
precision userPrecision
'precision 15 ' this is a hold-over from when I want to force max precision

sys(41) = 1  'rubberband type = line

baseUnits = sys(1100) 'Units Of Measurement for current drawing
'if sys(1100)=0 then base unit is unitless which is really decimal feet
'if sys(1100)=1 then base unit is inches
'if sys(1100)=2 then base unit is feet
'if sys(1100)=3 then base unit is miles
'if sys(1100)=4 then base unit is mm
'if sys(1100)=5 then base unit is cm
'if sys(1100)=6 then base unit is m
'if sys(1100)=7 then base unit is km

if baseUnits = 0 then UnitsOfMeasuremen$ = "drawing Units Of Measurement is unitless"
if baseUnits = 1 then UnitsOfMeasuremen$ = "drawing Units Of Measurement is inches"
if baseUnits = 2 then UnitsOfMeasuremen$ = "drawing Units Of Measurement is feet"
if baseUnits = 3 then UnitsOfMeasuremen$ = "drawing Units Of Measurement is miles"
if baseUnits = 4 then UnitsOfMeasuremen$ = "drawing Units Of Measurement is millimeters"
if baseUnits = 5 thenUnitsOfMeasuremen$ = "drawing Units Of Measurement is centimeters"
if baseUnits = 6 then UnitsOfMeasuremen$ = "drawing Units Of Measurement is meters"
if baseUnits = 7 then UnitsOfMeasuremen$ = "drawing Units Of Measurement is kilometers"

'SANITY CHECK in case more units are added:
if baseUnits > 7 then
message "An unknown drawing Units Of Measurement is being used--update the macro!"
goto Terminate
endif

Top:
doubleQuote$ = """
setpoint "Set 2 points to get the distance between them." 2
if sys(1) < 2 then
sys(1027) = 4  'msg box style Yes/No
message "This macro requires 2 points.", chr$(13), "Do you wish to set new points and continue?"
sys(1027) = 0   'default "OK" style
if ( sys(1028) = 7 ) then
goto Terminate  'user said NO
else
goto Top
endif
endif
pointval x1, y1, z1, 1
pointval x2, y2, z2, 2

Sys(36) = 1 'Enable silent mode to disable the text box for the AngleDistance command
>AngleDistance
{
<PointXYZ [x1, y1, z1]
<PointXYZ [x2, y2, z2]
}
Sys(36) = 0 ' Disable the silent mode
Xs = (x2 - x1)
if NOT(Xs = 0) then
Dx$ = Xs
else
Dx$ = "0"
endif
Ys = (y2 - y1)
if NOT(Ys = 0) then
Dy$ = Ys
else
Dy$ = "0"
endif
Zs = (z2 - z1)
Dz$ = Zs

firstLine$ =  UnitsOfMeasuremen$ + chr$(13)  + chr$(13) + "Dx = "
firstLine$ =  firstLine$ + Dx$
firstLine$ =  firstLine$ + "  Dy = "
firstLine$ =  firstLine$ + Dy$

If Sys(344) = 0 then '   3D delta added
if NOT(Zs = 0) then   ' only display it if there was a difference
firstLine$ = firstLine$ + "  Dz = "
firstLine$ = firstLine$ + Dz$
endif
endif

dxyz$ = Sys(650)  'distance value returned from  AngleDistance
Dxyz = val(dxyz$)

firstLine$ =  firstLine$ + "  Distance = "
firstLine$ =  firstLine$ + dxyz$  + chr$(13)  + chr$(13)

if baseUnits = 0 then 'unitless
answer$ = Dxyz
goto GiveAnswer
endif
if baseUnits = 1 then 'inches
Dxyz = Dxyz/12
baseUnits = 2
endif
miles = 0
if baseUnits = 3 then 'miles
miles = int(Dxyz)
remander = Dxyz - miles
Dxyz = remander * 5280
baseUnits = 2
endif
if baseUnits = 2 then 'feet
feet = int(Dxyz)
remander = Dxyz - feet
remanderInches = remander*12
inches = int(remanderInches)
fractions = remanderInches - inches
sixteenths = fractions/.0625
sixteenths = round(sixteenths)

no16 = 0
if sixteenths = 0 then
frac$ = doubleQuote$
no16 = 1
goto SayIt
endif
if sixteenths = 1 then
frac$ = " 1/16" + doubleQuote$
goto SayIt
endif
if sixteenths = 2 then
frac$ = " 1/8" + doubleQuote$
goto SayIt
endif
if sixteenths = 3 then
frac$ = " 3/16" + doubleQuote$
goto SayIt
endif
if sixteenths = 4 then
frac$ = " 1/4" + doubleQuote$
goto SayIt
endif
if sixteenths = 5 then
frac$ = " 5/16" + doubleQuote$
goto SayIt
endif
if sixteenths = 6 then
frac$ = " 3/8" + doubleQuote$
goto SayIt
endif
if sixteenths = 7 then
frac$ = " 7/16" + doubleQuote$
goto SayIt
endif
if sixteenths = 8 then
frac$ = " 1/2" + doubleQuote$
goto SayIt
endif
if sixteenths = 9 then
frac$ = " 9/16" + doubleQuote$
goto SayIt
endif
if sixteenths = 10 then
frac$ = " 5/8" + doubleQuote$
goto SayIt
endif
if sixteenths = 11 then
frac$ = " 11/16" + doubleQuote$
goto SayIt
endif
if sixteenths = 12 then
frac$ = " 3/4" + doubleQuote$
goto SayIt
endif
if sixteenths = 13 then
frac$ = " 13/16" + doubleQuote$
goto SayIt
endif
if sixteenths = 14 then
frac$ = " 7/8" + doubleQuote$
goto SayIt
endif
if sixteenths = 15 then
frac$ = " 15/16" + doubleQuote$
goto SayIt
endif
if sixteenths = 16 then
inches = inches + 1
frac$ = c
endif

SayIt:
if inches = 12 then
inches = 0
feet = feet + 1
endif
precision 0
if feet = 0 then
foot$ = ""
else
foot$ = feet
foot$ = foot$ + "'  "
endif
if inches = 0 then
inch$ = ""
if no16 = 1 then frac$ = ""
else
inch$ = inches
endif
if NOT(miles = 0) then
miles$ = miles
miles$ = miles$ + " miles "
answer$ = miles$ + foot$ + inch$ + frac$
else
answer$ = foot$ + inch$ + frac$
endif
goto GiveAnswer
endif
if baseUnits = 4 then
answer$ = dxyz$ + " millimeters"
goto GiveAnswer
endif
if baseUnits = 5 then
answer$ = dxyz$ + " centimeters"
goto GiveAnswer
endif
if baseUnits = 6 then
answer$ = dxyz$ + " meters"
goto GiveAnswer
endif
if baseUnits = 7 then
answer$ = dxyz$ + " kilometers"
goto GiveAnswer
endif

GiveAnswer:
firstLine$ = firstLine$ + answer$
message firstLine$

Terminate:
'set stuff back the way the user had it:
sys(223) = originalStatusBarVisibility
'sys(7) = userPrecision 'un-comment if you force a non-user precision
end

-Ed