20
; MODULE_ID AI_UTILS_LSP_
;;;---------------------------------------------------------------------------;;;
;;;
ai_utils.lsp
;;;
;;;
Copyright 1992,1994,1996-2003 by Autodesk, Inc.
;;;
;;;
Permission to use, copy, modify, and distribute this software
;;;
for any purpose and without fee is hereby granted, provided
;;;
that the above copyright notice appears in all copies and
;;;
that both that copyright notice and the limited warranty and
;;;
restricted rights notice below appear in all supporting
;;;
documentation.
;;;
;;;
AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
;;;
AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
;;;
MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
;;;
DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
;;;
UNINTERRUPTED OR ERROR FREE.
;;;
;;;
Use, duplication, or disclosure by the U.S. Government is subject to
;;;
restrictions set forth in FAR 52.227-19 (Commercial Computer
;;;
Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
;;;
(Rights in Technical Data and Computer Software), as applicable.
;;;
;;;---------------------------------------------------------------------------;;; (ai_abort <appname> [<error message>] )
;;;
;;; Displays critical error message in alert box and terminates all
;;; running applications.
;;;
;;; If <errmsg> is nil, no alert box or error message is displayed.
(defun ai_abort (app msg)
(defun *error* (s)
(if old_error (setq *error* old_error))
(princ)
)
(if msg
(alert (strcat " Application error: "
app " \n\n " msg " \n" ) )
)
(exit)
)
(defun ai_return (value) value) ; Make act of returning value explicit
;;; Beep function conditional on user-preferred setting.
(defun ai_beep ( / f)
(write-line "\007" (setq f (open "CON" "w")))
(setq f (close f))
)
;;; (ai_alert <message> )
;;;
;;; Shell for (alert)
(defun ai_alert (msg)
; find it
(= just_name "CONTINUOUS")
)
)
))
((and (= 2 (logand bit 2))
(= table_name "BLOCK")
(= 1 (logand 1 (cdr (assoc 70 tbldata))))
))
((and (= 4 (logand bit 4))
;; Check for Xref dependents only.
(zerop (logand 4 (cdr (assoc 70 tbldata))))
(not (zerop (logand 48 (cdr (assoc 70 tbldata)))))
))
((and (= 8 (logand bit 8))
(not (zerop (logand 4 (cdr (assoc 70 tbldata)))))
))
;; Vports tables can have similar names, only display one.
((member just_name table_list)
)
(T (setq table_list (cons just_name table_list)))
)
)
(cond
((and (= 16 (logand bit 16))
(= table_name "LTYPE") ) (setq table_list (cons "BYBLOCK"
(cons "BYLAYER" table_list))) )
(t)
)
(ai_return table_list)
)
;;;
;;; (ai_strtrim <string> )
;;;
;;; Trims leading and trailing spaces from strings.
(defun ai_strtrim (s)
(cond
((/= (type s) 'str) nil)
(t (ai_strltrim (ai_strrtrim s)))
)
)
(defun ai_strltrim (s)
(cond
((eq s "") s)
((/= " " (substr s 1 1)) s)
(t (ai_strltrim (substr s 2)))
)
)
(defun ai_strrtrim (s)
(cond
((eq s "") s)
((/= " " (substr s (strlen s) 1)) s)
(t (ai_strrtrim (substr s 1 (1- (strlen s)))))
)
)
;;;
;;; Pass a number, an error message, and a range. If the value is good, it is
;;; returned, else an error is displayed.
)
;;;
;;; Routines that check CMDACTIVE and post an alert if the calling routine
;;; should not be called in the current CMDACTIVE state. The calling
;;; routine calls (ai_trans) if it can be called transparently or
;;; (ai_notrans) if it cannot.
;;;
;;;
1 - Ordinary command active.
;;;
2 - Ordinary and transparent command active.
;;;
4 - Script file active.
;;;
8 - Dialogue box active.
;;;
(defun ai_trans ()
(if (zerop (logand (getvar "cmdactive") (+ 2 8) ))
T
(progn
(alert "This command may not be invoked transparently.")
nil
)
)
)
(defun ai_transd ()
(if (zerop (logand (getvar "cmdactive") (+ 2) ))
T
(progn
(alert "This command may not be invoked transparently.")
nil
)
)
)
(defun ai_notrans ()
(if (zerop (logand (getvar "cmdactive") (+ 1 2 8) ))
T
(progn
(alert "This command may not be invoked transparently.")
nil
)
)
)
;;; (ai_aselect)
;;;
;;; Looks for a current selection set, and returns it if found,
;;; or throws user into interactive multiple object selection,
;;; and returns the resulting selection set if one was selected.
;;;
;;; Sets the value of ai_seltype to:
;;;
;;;
1 = resulting selection set was autoselected
;;;
2 = resulting selection set was prompted for.
(defun ai_aselect ( / ss)
(cond
((and (eq 1 (logand 1 (getvar "pickfirst")))
)
;;;
;;; UNDO handlers. When UNDO ALL is enabled, Auto must be turned off and
;;; GROUP and END added as needed.
;;;
(defun ai_undo_push()
(setq undo_init (getvar "undoctl"))
(cond
((and (= 1 (logand undo_init 1)) ; enabled
(/= 2 (logand undo_init 2)) ; not ONE (ie ALL is ON)
(/= 8 (logand undo_init 8)) ; no GROUP active
)
(command "_.undo" "_group")
)
(T)
)
;; If Auto is ON, turn it off.
(if (= 4 (logand 4 undo_init))
(command "_.undo" "_auto" "_off")
)
)
;;;
;;; Add an END to UNDO and return to initial state.
;;;
(defun ai_undo_pop()
(cond
((and (= 1 (logand undo_init 1)) ; enabled
(/= 2 (logand undo_init 2)) ; not ONE (ie ALL is ON)
(/= 8 (logand undo_init 8)) ; no GROUP active
)
(command "_.undo" "_end")
)
(T)
)
;; If it has been forced off, turn it back on.
(if (= 4 (logand undo_init 4))
(command "_.undo" "_auto" "_on")
)
)
;;;
;;; (get_dcl "FILTER")
;;;
;;; Checks for the existence of, and loads the specified .DCL file,
;;; or aborts with an appropriate error message, causing the initial
;;; load of the associated application's .LSP file to be aborted as
;;; well, disabling the application.
;;;
;;; If the load is successful, the handle of the .DCL file is then
;;; added to the ASSOCIATION LIST ai_support, which would have the
;;; following structure:
;;;
;;;
;;; (("DCLFILE1" . 1) ("DCLFILE2" . 2)...)
;;;
;;; If result of (ai_dcl) is NIL, then .DCL file is not avalable,
;;; or cannot be loaded (the latter can result from a DCL audit).
;;;
;;; Applications that call (ai_dcl) should test its result, and
)
( (member ss_ename '("VIEWPORT" "MTEXT"))
(setq bit_value (logior 1 2))
)
( (member ss_ename '("MLINE"))
(setq bit_value (logior 1 8))
)
(T (setq bit_value (logior 1 2 4 8 16)) ; Enable all fields if unknown.
)
)
bit_value
)
;;;
;;;
;;; (ai_helpfile) returns an empty string. Let the core code figure out
;;; the default platform helpfile.
;;;
(defun ai_helpfile ( / platform)
""
)
;;;
;;; Returns val with the any trailing zeros beyond the current
;;; setting of luprec removed.
;;;
(defun ai_rtos(val / a b units old_dimzin)
(setq units (getvar "lunits"))
;; No fiddling if units are Architectural or Fractional
(if (or (= units 4) (= units 5))
(rtos val)
;; Otherwise work off trailing zeros
(progn
(setq old_dimzin (getvar "dimzin"))
;; Turn off bit 8
(setvar "dimzin" (logand old_dimzin (~ 8)))
(setq a (rtos val))
;; Turn on bit 8
(setvar "dimzin" (logior old_dimzin 8))
(setq b (rtos val units 15))
;; Restore dimzin
(setvar "dimzin" old_dimzin)
;; Fuzz factor used in equality check.
(if (equal (distof a) (distof b) 0.000001) a b)
)
)
)
;;;
;;; Returns angle val with the any trailing zeros beyond the current
;;; setting of luprec removed.
;;;
(defun ai_angtos(val / a b old_dimzin)
(setq old_dimzin (getvar "dimzin"))
;; Turn off bit 8
(setvar "dimzin" (logand old_dimzin (~ 8)))
(setq a (angtos val))
;; Turn on bit 8
(setvar "dimzin" (logior old_dimzin 8))
(setq b (angtos val (getvar "aunits") 15))
;; Restore dimzin
(setvar "dimzin" old_dimzin)
;; Fuzz factor used in equality check. Reminder a & b are radians.
(if (equal (angtof a) (angtof b) 0.00000001) a b)
)
;;;