Thanks for the suggestion, Cab. This is what I ended up with:
;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Routine: InchesToLineWeight
Purpose: Converts a distance, in inches, to a lineweight as used by
active-x.
Arguments: Inches signature #1 - real - the lineweight in inches
signature #2 - string - the name of the lineweight, this
is limited to "DEFAULT" "BYBLOCK" or "BYLAYER".
Returns: The lineweight enumeration as stored in acad.
-----------------------------------------------------------------------------
If an invalid lineweight is specified an error message is returned as a
string, beginning with "ERROR|"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;
(defun InchesToLineWeight (inches / RT temp)
(setq
temp (assoc (fix (round (* inches 1000) 0))
'((0 . 0)(2 . 5)(4 . 9)(5 . 13)(6 . 15)(7 . 18)
(8 . 20)(10 . 25)(12 . 30)(14 . 35)(16 . 40)
(20 . 50)(21 . 53)(24 . 60)(28 . 70)(31 . 80)
(35 . 90)(39 . 100)(42 . 106)(47 . 120)(55 . 140)
(62 . 158)(79 . 200)(83 . 211)("DEFAULT" . -3)
("BYBLOCK" . -2)("BYLAYER" . -1)
)
)
)
(if temp
(cdr temp)
(strcat
"ERROR|InchesToLineWeight - Invalid lineweight argument ("
(vl-prin1-to-string inches)
")"
)
)
)
;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Routine: Round
Purpose: Round numbers to a specified number of significant digits
Arguments: num - the number to be rounded, may be an integer or a real
decs - the number of decimal places desired.
if decs is supplied as a real, it is rounded to the
nearest integer and applied
--------------------------------------------------------------------------------
Examples:
num dec returns
143.125 2 143.12
143.125 1 143.1
143.125 0 143.0
143.125 -1 140
143.125 -2 100
143.125 -3 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;
(defun round (num ;the number to round
decs ;the number of decimal places
/ temp1 temp2)
(if (= 'REAL (type decs))
(setq decs (round decs 0))
) ;_ end of if
(setq
temp1 (/ (fix (* num (expt 10.0 decs))) (expt 10.0 decs) 1.0)
temp2 (/ (fix (* num (expt 10.0 (1+ decs))))
(expt 10.0 (1+ decs))
1.0
) ;_ end of /
;;round up or down?
temp2 (if (> (/ 1 2.0) (* (- temp2 temp1) (expt 10.0 decs)))
;;round down
temp1
;;round up
(+ temp1 (/ 1.0 (expt 10.0 decs)))
) ;_ end of if
;;make it an integer?
temp2 (if (> 0 decs)
;;yes
(fix temp2)
;;no
temp2
) ;_ end of if
) ;end setq
) ;_ end of defun