;; ···········································································
;; >-=((((°>`·.¸¸.·´¯`·.¸.·´¯`·... >-=((((°> `·.¸¸.·´¯`·.¸.·´¯`·... >-=((((°>
;;
;; PlaceText.lsp Version 1.0 Beta
;; Allow user to place text with enhanced features
;;
;; Copyright© 2009 Charles Alan Butler aka CAB from TheSwamp.org
;;
;; USAGE -> (PlaceText <vlaObject> '(Option Flags))
;; Move point is based on the Alignment point of the text
;;
;; Options Flags -> List of pair list
;; Option pairs may be in any order & may be omitted for default values
;; (list '(<String> <Data>) '(<String> <Data>))
;; <String> = string for option identification
;; Identifier DataType Default Action
;; "erase" Logic true erase text if user exits using ENTER
;; "curve" Logic true Allow Curve Align Option
;; "textgap" Real 0.1 step amount for text gap
;; "rotationstep" Real 0.0174533 step amount for rotation
;;
;; (PlaceText <vlaObject> '(("erase" nil))) = use default options
;;
;; RETURN -> an error message or nil if successful
;;
;; -=< User Options >=-
;; >> Enter = Exit
;; >> Space = Rotate CCW
;; >> Shift + Space = Rotate CW
;; >> Tab = Rotate 90 deg
;; >> Shift + Tab = Mirror Rotation
;; >> C = Curve Aligned, place text next to curve object
;; >>> [A] = toggle auto angle correction
;; >>> [P] = Text Perpendicular to object, also [Tab]
;; >>> [+] = Adjust Offset from object
;; >>> [-] = Adjust Offset from object
;;
;; Thanks to Lee Mac for ideas & code from his NumInc.lsp
;;
;; Need to add Trap for ESCape key <---------------<<<<
;; May include a Layer Override feature in future
;;
;; YOU MAY USE THIS CODE ONLY FOR *NON-COMMERCIAL*
;; PURPOSES AND ONLY IF YOU RETAIN
;; THIS HEADER COMPLETE AND UNALTERED
;; you must contact me if you want to use it commercially
;;
;; >-=((((°>`·.¸¸.·´¯`·.¸.·´¯`·... >-=((((°> `·.¸¸.·´¯`·.¸.·´¯`·... >-=((((°>
;; ···········································································
(defun PlaceText
(tObj
; expects a vla object, text or mtext Options ; list of option flags, may be nil
/ CurMod ; t/nil On/Off flag for Align Mode
RetMsg ; hold message to return
txtpoint ; text point method needed to modify point
OrgPoint ; original text point
OrgRot ; original text rotation
GapStep ; step amount for text gap
AngStep ; step amount for rotation
RemoveIfUserQuit ; erase the text object id the use quits
doc cang cpt data ent grdat lang msg pt rot shiftOK TxtHgt
)
;; CAB test to see if vlax-curve can be used on an object or ent
(defun curveOK
(ent
) ; returns nil if not allowed )
)
)
(strcat "\n<< Type [+] or [-] for offset, and [P]erpendicular >>" "\n<< [A] to toggle auto angle correction "
(if flag
"OFF" "On") " >>" ) )
;; function is wrapped in a COND statement for error detection
:vlax-true
)
(princ "\n*** ERROR - Layer is Locked. Can not continue.") )
:vlax-true
)
(princ "\n*** ERROR - Layer is Frozen. Can not continue.") )
;;------------------------------------------------------------
(t ; OK to proceed <---------------<<<
;; set up point to get from text
;; needed to get the proper method for insertion point
)
(setq txtpoint
"TextAlignmentPoint") (setq txtpoint
"InsertionPoint") )
;;(setq point ((eval (read(strcat "vla-get-" txtpoint))) tobj)) ; example usage
;; ============ Set Defaults =====================
(setq DefOptions
; (<Identifier> <VarName> <DefaultValue>) '(("erase" "RemoveIfUserQuit" t) ; erase the text object if the use quits
("curve" "AllowCurveAlign" t) ; Curve Method Flag
("textstep" "GapStep" 0.1) ; step amount for text gap
("textgap" "*TextGap*" 1.0) ; gap multiplier between text an aligned object (* TxtHgt *TextGap*)
("alignangle" "*AngInc*" 0.0) ; angle to align to object 0= parallel
("rotationstep" "AngStep" (/ pi 180.0)) ; step amount for rotation
))
;; Decode Options
)
)
;; ============ End of Set Defaults =====================
;; Refer notes regarding (acet-load-expresstools) in Post Reply #14
;; Set Express Tools Flag
(alert "\n** ExpressTools not loaded. Some Functions May not be Available. **") )
rot OrgRot
)
"\n[ENTER]= Quit, "
(if AllowCurveAlign
"[C]urve Aligned, " "") "[Space] = Rotate CCW, [Tab] = Rotate 90"
"\n[Shift] + [Space] = Rotate CW, [Shift] + [Tab] = Mirror Rotation"
)
)
)
;; -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=-
;; M a i n L o o p f o r u s e r i n p u t
;; -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=-
(while ; if last return value from progn is not nil, continue to loop )
)
)
;; --------------------------------------------------
;; ------- mouse movement updated here -----------
;; --------------------------------------------------
;; Got Pointing device Drag Mode input and a point
(cond ; two conditions: Curve Aligned On or OFF (CurMod ; Curve Aligned is set ON
lAng (+ cAng *AngInc*)
)
(cond ((and *AngCor
* (> lang
(* 0.51 pi
)) (< lang
(* 1.51 pi
))) (setq lang
(+ lang pi
)) ;flop text at >90 and <270 )
)
tobj
)
)
(t ; Standard Mode, Curve Aligned is set Off
tobj
)
(and (>= rot
(* 2 pi
))(setq rot
(- rot
(* 2 pi
)))) )
)
t ; stay in Loop
) ; end Pointing device Drag Mode input
;; -----------------------------------------------------------------
;; ((member (car grdat) '(11 25))) ; [Right Click], must be handled seperatly
;; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
;; Key Press by user evaluated here
;; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
;; React to the key press
((eq data
13) ; [Enter] User wants to Quit without moving text ((and tObj RemoveIfUserQuit
) )
(t ; restore the original text object
)
)
nil ; Exit Loop
)
;; Begin Curve Aligned Mode if allowed
;; Failure to select sutiable object will turn the mode off
((and AllowCurveAlign
(vl-position data '
(99 67))) ; C/c Curve Aligned (CurMod
(setq CurMod
nil) (princ msg
)) ; toggle OFF ((setq CurMod T
) ; set mode ON (prompt "\n>> Can not use that object to align. <<") )
)
(princ (CurMsg
*AngCor
*)) (setq CurMod
nil) ; set mode Off, failed to select object ) ; progn
) ; endif
)
)
t ; stay in Loop
)
;; process key press for Curve Aligned Mode Only
(setq *TextGap
* (+ GapStep
*TextGap
*)) )
(setq *TextGap
* (- *TextGap
* GapStep
)) )
((and CurMod
(vl-position data '
(9 80 112))) ; Tab Pp rotate relative angle 90 deg (setq *AngInc
* (- (/ pi
2) *AngInc
*)) )
((and CurMod
(vl-position data '
(65 97))) ; Aa toggle Auto ang correction (princ (CurMsg
*AngCor
*)) t ; stay in Loop
)
;; ----------------- end of Curve Mode --------------------
((= 32 data) ;[SHIFT] / [SPACE] rotate text object
(if (and shiftOK
(acet
-sys
-shift
-down
)) (setq rot
(- rot AngStep
)) (setq rot
(+ AngStep rot
)) )
t ; stay in Loop
) ; (= 32 data)
((= 9 data) ; [SHIFT] / [TAB] rotate text object
(if (and shiftOK
(acet
-sys
-shift
-down
)) ;; if not cardinal point reset to 0.0
(setq rot
(+ (/ pi
2) rot
)) )
)
t ; stay in Loop
) ; (= 9 data)
((= 15 data) ; F8 = toggles orthomode <OrthoMode Not Functioning Yet>
t ; stay in Loop
)
((princ "\n** Invalid KeyPress **") ; Fall through condition (princ msg
) ; stay in loop )
) ; cond
) ; end (= 2 (car grdat)) Key Press by user
;; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
;; ································································
;; Point picked by user, Normal Exit
nil ; Exit Loop
)
;; ································································
) ; Main COND for user input - return will control the WHILE exit
) ; end progn - return will control the WHILE exit
) ; Main while LOOP
;; -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=- -=*=-
RetMsg
)
) ; end error trap COND
;; return value will be error msg string or nil if tObj is moved successfully
)