;;-------------------PLSMINUS.LSP---------------------------- ;; Purpose: aids in creation of PLUS, MINUS & REFERENCE dimensions ;; for structural & misc. steel detailing ;; Version: 1.2 ;; Date: 15 Jan 02 ;; Copyright 2002 by Herman Mayfarth All rights reserved. ;; Permission granted to freely use without fee. ;; NO redistribution without author's WRITTEN permission. ;; ;;----------------------------------------------------------- ;;--------------rtodtstl.lsp----------------------------- ;;; Author: Herman Mayfarth ;;; Date: 15 Jan 2002 ;;; Purpose: convert real to MTEXT representation as ft & inches ;;; w/ unbarred fraction & no inch marks ;;; Params: num: real number to convert to MTEXT string ;;; fracht: real specifying the relative ht. of fractions ;;; Returns: string as above if successful, nil otherwise ;;;------------------------------------------------------ (defun rtodtstl (num fracht / add count curent instrg outstrg start_format suffix ) (setq instrg (rtos num 4 4) ;strip the last character, which is alwayss the inch mark instrg (substr instrg 1 (1- (strlen instrg))) ) ;;three cases exist: ;;Case 1: ;;if we have > 1" and have a fraction, the string will contain a space before ;;the fraction, and we need to substitute the start of the MTEXT format for ;;the space character ;;Case 2: ;;we have >1" but no fraction => no / will be found, and no MTEXT formatting ;;Case 3: ;;we have a fraction <1" => MTEXT formatting prefixes the input string ;setup the format string for the start of the MTEXT fraction (setq start_format (strcat "{\\H" (rtos fracht 2 2) "x;\\S") ;initialize a counter for the position to test in the input string count 1 suffix 0 ;and bind a null string to a symbol for the output string outstrg "") ;now walk down the input string one character at a time (repeat (strlen instrg) ;set a flag to indicate the current character should be kept (setq add 1 ;and get the current character from the input string curent (substr instrg count 1)) ;;first, test for a space character (cond ((= curent " ");found a space (Case 1), ;; so substitute the fraction format, clear the add flag, and set a flag ;; to let us know we need to close the format at the end (setq outstrg (strcat outstrg start_format) add nil suffix 1)) ;;else test for fraction bar ((= curent "/") ;found a fraction bar (progn ;;test for suffix (if (= suffix 0) (setq suffix 2));need a prefix ;;substitute the ^ symbol, clear the add flag (setq outstrg (strcat outstrg "^") add nil ) );progn );pred );cond ;if add is bound, there was no substitution, so just add the ;current character to the front of the output string (if add (setq outstrg (strcat outstrg curent))) (setq count (1+ count)) );repeat ;;if we found a fraction, we need to close the MTEXT format (cond ((= suffix 1) (setq outstrg (strcat outstrg ";}"))) ((= suffix 2) (setq outstrg (strcat start_format outstrg ";}"))) (T nil);otherwise, do nothing ) outstrg );rtodtstl ;;;--------------refdim.lsp----------------------------- ;;; Author: Herman Mayfarth ;;; Purpose: convert distance to parenthesized rep ;;; w/ unbarred fraction & no inch marks ;;; Param: real number representing distance ;;; Needs: rtodtstl ;;; Returns: string as above if successful, nil otherwise ;;;------------------------------------------------------ (defun refdim (arg / ) (strcat "\\A1(" (rtodtstl arg 0.75) ")") ) (defun plusdim (arg / ) (strcat "\\A1(+" (rtodtstl arg 0.75) ")") ) (defun minusdim (arg / ) (strcat "\\A1(-" (rtodtstl arg 0.75) ")") ) ;;;function to entmake scaled MTEXT (defun tktn_make_scaled_mtext (textval textlyr inspt width attach / elist sf ) (entmake (list '(0 . "MTEXT") '(100 . "AcDbEntity") (cons 8 textlyr) '(100 . "AcDbMText") (cons 10 inspt) (cons 40 (* (tktn_getscl) (getvar "DIMTXT"))) (cons 41 width) (cons 71 attach) '(72 . 5) (cons 1 textval) (cons 7 (getvar "TEXTSTYLE")) '(210 0.0 0.0 1.0) '(11 1.0 0.0 0.0) '(50 . 0.0) ) ) inspt;return insertion point );tktn_make_scaled_mtext ;;--------------------- tktn_getscl-------------------------------------- ;; Purpose: calculate scale factor ;; Uses: nothing ;; Returns: sf ;;----------------------------------------------------------------- (defun tktn_getscl( ) (cond ((= 1 (getvar "TILEMODE")) (getvar "DIMSCALE"));tiled space ((= 1 (getvar "CVPORT")) 1.0);in paper space ;; in a viewport (T (last (trans '(0 0 1.0) 3 2));calc scale factor ) );cond );end tktn_getscl ;;--------------------- tktn_setlyr-------------------------------------- ;; Purpose: set layer for entmake ;; Arg: lset ;; Uses: notelayer ;; Returns: txtlyr ;;----------------------------------------------------------------------- (defun tktn_setlyr (lset) (if notelayer (setq txtlyr lset) (setq txtlyr (getvar "CLAYER")) ) );tktn_setlyr (defun C:PLUS( / ; local symbols olderr ;saved error function oldos ;saved OSMODE txtval ;text string txtlyr ;text layer txtpt ;WCS coords of text insertion point ; local functions: *lerror* ) ;; ;--------------------- lerror ----------------------------------- ;; local error handler (defun *lerror* (msg) (if (or (= msg "Function cancelled") (= msg "quit / exit abort") ) (princ) (princ (strcat "\nError: " msg)) ) );*lerror* ;----------------------------------------------------------------- ;; handle nonsense case of zero dimscale in tiled space (if(and(= 0 (getvar "DIMSCALE"))(= 1 (getvar "TILEMODE"))) (progn((alert " Zero Dimension Scale\n Set Tilemode = 0 or Use a Non-Zero Dimension Scale")(exit)))) (setq olderr *error* *error* *lerror* oldos (getvar "OSMODE")) (setq sf (tktn_getscl)) (tktn_setlyr "DIM") ;;prompt for text values (setq txtval (getdist "\nPlus Dimension: ")) (princ (strcat "\nPlus Dimension: " (rtos txtval 4 4))) (setq txtval (plusdim txtval)) ;;prompt for insertion point (initget 1) (setvar "OSMODE" 512) (setq txtpt (polar (trans (getpoint "\nInsertion Point:") 1 0 ) (/ PI 2) (* 2 (getvar "DIMGAP")) ) ) (setvar "OSMODE" oldos) ;;make entity (tktn_make_scaled_mtext txtval txtlyr txtpt 0 8) (setq *error* olderr *lerror* nil) (princ) );end PLUS (defun C:MINUS( / ; local symbols olderr ;saved error function oldos ;saved OSMODE txtval ;text string txtlyr ;text layer txtpt ;WCS coords of text insertion point ; local functions: *lerror* ) ;; ;--------------------- lerror ----------------------------------- ;; local error handler (defun *lerror* (msg) (if (or (= msg "Function cancelled") (= msg "quit / exit abort") ) (princ) (princ (strcat "\nError: " msg)) ) );*lerror* ;----------------------------------------------------------------- ;; handle nonsense case of zero dimscale in tiled space (if(and(= 0 (getvar "DIMSCALE"))(= 1 (getvar "TILEMODE"))) (progn((alert " Zero Dimension Scale\n Set Tilemode = 0 or Use a Non-Zero Dimension Scale")(exit)))) (setq olderr *error* *error* *lerror* oldos (getvar "OSMODE")) (tktn_setscl) (tktn_setlyr "DIM") ;;prompt for text values (setq txtval (getdist "\nMinus Dimension: ")) (princ (strcat "\nMinus Dimension: " (rtos txtval 4 4))) (setq txtval (minusdim txtval)) ;;prompt for insertion point (initget 1) (setvar "OSMODE" 512) (setq txtpt (polar (trans (getpoint "\nInsertion Point:") 1 0 ) (/ PI 2) (* 2 (getvar "DIMGAP")) ) ) (setvar "OSMODE" oldos) ;;make entity (tktn_make_scaled_mtext txtval txtlyr txtpt 0 8) (setq *error* olderr *lerror* nil) (princ) );end MINUS (defun C:REFDIM( / ; local symbols olderr ;saved error function oldos ;saved OSMODE txtval ;text string txtlyr ;text layer txtpt ;WCS coords of text insertion point ; local functions: *lerror* ) ;; ;--------------------- lerror ----------------------------------- ;; local error handler (defun *lerror* (msg) (if (or (= msg "Function cancelled") (= msg "quit / exit abort") ) (princ) (princ (strcat "\nError: " msg)) ) );*lerror* ;----------------------------------------------------------------- ;; handle nonsense case of zero dimscale in tiled space (if(and(= 0 (getvar "DIMSCALE"))(= 1 (getvar "TILEMODE"))) (progn((alert " Zero Dimension Scale\n Set Tilemode = 0 or Use a Non-Zero Dimension Scale")(exit)))) (setq olderr *error* *error* *lerror* oldos (getvar "OSMODE")) (tktn_setscl) (tktn_setlyr "DIM") ;;prompt for text values (setq txtval (getdist "\nReference Dimension: ")) (princ (strcat "\nReference Dimension: " (rtos txtval 4 4))) (setq txtval (refdim txtval)) ;;prompt for insertion point (initget 1) (setvar "OSMODE" 512);near (setq txtpt (polar (trans (getpoint "\nInsertion Point:") 1 0 ) (/ (* 3 PI) 2) (+ (getvar "DIMGAP") (* 2.5 (tktn_getscl) (getvar "DIMTXT"))) ) ) (setvar "OSMODE" oldos);restore OSMODE ;;make entity (tktn_make_scaled_mtext txtval txtlyr txtpt 0 8) (setq *error* olderr *lerror* nil) (princ) );end REFDIM ;;load prompt (princ "\nPLSMINUS copyright Herman Mayfarth 1999.") (princ "\nType PLUS or MINUS for plus/minus dimensions, REFDIM for reference dimension.") (princ)