| Often it becomes
necessary to change a whole bunch of text on an IntelliCAD drawing so that it all has the
same height, width, obliquing angle, direction, orientation or string value. All these qualities can be set by editing the text, but if
you have many text entities to modify, doing them one at a time would be very tedious and
inefficient, especially when they all require the same property settings.
This LISP code enables you to create a selection
set of text you want to change by picking or using a window. It prompts for the text
properties to modify. Then it modifies them all without any further work from you.
Don't worry if your selection set includes non-text
entities. These are filtered out of the modification process, so you can make your
selection set the easiest and quickest way available.
The LISP code provided here is fully functional and
commented throughout to explain what each line does. It is intended to provide you with a
routine you can use in IntelliCAD immediately for fun and profit. The comments are to help
you understand how it works so you can learn LISP and make your own modifications and
enhancements for even greater productivity in your office.
Comments are preceded with a semicolon (;).
Comments are intended to be read with in conjunction with a LISP reference close by
; ****************************
; CHGTEXT.LSP
;Changes properties of all text entities in selection sets.
;(C)1989-98 AZCAD - Melbourne, Australia
;www.dbm.com.au/azcad
; Define the function that will perform the database changes
(defun DOIT (P DXF NEWVAL / M N T2 E)
; P DXF and NEWVAL are arguments DOIT requires
; when called.
; M N T2 and E are symbols (variables) declared as local
; to the DOIT function.
(setq M 0 S 0 N (sslength P))
; Initialize symbols setting M and S to zero, and N equal
to the
; number of entities in selection set P
(while (< M N)
; Begin a WHILE loop that will execute so long as
; M (iteration counter) is less than N (number of entities
; in the selection set).
; In other words, perform the functions in this loop once
; for each entity in the selection set
(if (= "TEXT" (cdr (assoc 0 (setq E (entget (ssname P M))))))
; Begin an IF function. The test is to identify only TEXT
; items in the selection set. Applying text property commands
; to non-text entities will result in errors.
; SSNAME returns the entity name of the Mth item in P
; ENTGET returns the entity data for the entity name
; E is an symbol to store the entity data
; ASSOC returns the association list for, in this case, key
; element 0
; CDR returns a list of all but the first element in list submitted to it
(progn
; PROGN allows a number of expressions to submitted
; where only one is expected (in this case, the THEN expression
; required by the IF function).
(setq T2 (assoc DXF E) E (subst (cons DXF NEWVAL) T2 E))
; T2 returns the association list for the key element DXF
; passed to this function
; CONS creates a new association list
; SUBST substitutes the new association list for the
; old association list (T2) in the entity data (E)
; the new entity data is set to E
(entmod E)
; updates the entity data in E in the database
(setq S (1+ S) M (1+ M))
; Increment S (modified entity counter) and M
; (iteration counter) by one
)
; Close PROGN
; The following expression is the ELSE component of the IF function
(setq M (1+ M))
; Update M (the iteration counter) even though the entity was not
text
)))
; Close IF, WHILE and DEFUN
; ****************************
; Define a function that converts degrees to radians
; If you use a lot of home-grown LISP, this function
; could go in your ICAD.LSP file making it available to
; all your LISP and eliminating the requirement to include
; it each routine that uses it (there will be many)
(defun DTR (DEG)
; DTR requires one argument and has no local symbols
(* pi (/ DEG 180.0))
; Degrees divided by 180 and multiplied by PI equals
radians
)
; Close DEFUN
; ****************************
; Define a function with a new command name CHGTEXT
(defun C:CHGTEX (/ P CHGTYP DXF NEWVAL)
; No arguments. All atoms are local
(setq P (ssget))
; SSGET requests a selection set which is assigned to P
; Begin an IF function if P is TRUE
; (i.e. there is a selection set)
(if P
(progn
(setq CHGTYP (strcase
(getstring "\n<H>eight/Width/Obliquing
angle/Normal/Backwards/Upsidedown/String: ")))
; GETSTRING gets string input from user prompted by
; the prompt provided. The prompt indicates input required
; (capitalized letter) and default (capitalized letter in angle
; brackets) to standard convention
; STRCASE converts character case, in this case
; (no second argument) to uppercase. This provides
; a consistent result where users have CapsLock
; on or off
(cond
; Test the response set to CHGTYP
((eq CHGTYP "W")
; If W user wants to change the Width
(setq DXF 41)
; Association list key for width is 41
(princ "\nNew width: ")
; Prompt for new width on a new line (\n)
(setq NEWVAL (getreal)))
; Get real number input from user and set to NEWVAL
((eq CHGTYP "O")
; If O user wants to change obliquing angle
(setq DXF 51)
; Association list key is 51
(princ "\nNew obliquing angle: ")
; Prompt
(setq NEWVAL (DTR (getreal))))
; GETREAL receives real number input from user
; DTR converts the real number to radians
; Result is set to NEWVAL
((eq CHGTYP "N") (setq DXF 71 NEWVAL 0))
; If N for normal, set association list key to 71
; and NEWVAL to 0
((eq CHGTYP "B") (setq DXF 71 NEWVAL 2))
; If B for backwards, set association list key to 71
; and NEWVAL to 2
((eq CHGTYP "U") (setq DXF 71 NEWVAL 4))
; If U for upsidedown, set association list key to 71
; and NEWVAL to 4
((or (eq CHGTYP "H") (eq CHGTYP ""))
(setq DXF 40)
; If H or nothing (pressed Return for the default)
; set association list key to 40
(princ "\nNew height: ")
; Prompt for new height
(setq NEWVAL (getdist)))
; GETDIST accepts new height by input or picking
((eq CHGTYP "S") (setq DXF 1 NEWVAL (getstring 't "\nNew
string: "))))
; If S for new string, set association list key to 1
; and get a user-supplied string for NEWVAL
(DOIT P DXF NEWVAL)))
; Call DOIT to update the database passing
; P - the selection set,
; DXF - the association list key,
; and NEWVAL - the new value to use.
(princ (strcat "\n" (rtos S 2 0) " text entities
changed."))
; RTOS converts a number to a string to enable it to
; be concatenated (STRCAT) to some words which
; are printed to a new line (\n) to advise the number
; of entities changed.
(setq P ())
; Null the selection set
(prin1))
; PRIN1 without arguments prints a blank line in the command window
; ***********************
The source code above can be cut and pasted into
NotePad and save as CHGTEX.LSP in IntelliCAD's program directory. Load it in IntelliCAD
using the load function. With a drawing loaded in IntelliCAD type in (load
"chgtex") and then enter CHGTEX to execute the
program.
As with all LISP code, there is plenty of scope to
modify, improve and tailor this routine to your own requirements or preferred method. For
example, it would be possible to include a selection set filter construct in the second
line of the CHGTEXT function, which would eliminate the text checking process in DOIT. It
would also be possible to modify more entity properties than those included in this
routine. Good luck with your own development of this basic routine.
More information on programming in LISP in
IntelliCAD can be found in the IntelliCAD 98 Developer's reference on the IntelliCAD
CD-ROM (Uncompressed/Help/DevRef.hlp).
The version of LISP used in IntelliCAD is highly
compatible with Autodesk's AutoLISP and many routines written in AutoLISP will work
perfectly well in IntelliCAD. Books on AutoLISP are becoming scarce. Check Amazon.com for books on
AutoLISP
Many LISP routines suitable for use with IntelliCAD
are available from DBM's AutoLISP
Library which has close to 2,000 routines available online. A subscription may be
required to access the routine you want.
There are a variety of LISP resources on the Web
that are a goldmine of free code for IntelliCAD users. Most of the routines offered on the
sites listed on our LISP on the Web page was originally created
for use with AutoCAD. In most cases it will work just fine with IntelliCAD.
Code is provided "as-is" for purposes
of instruction and utility and may be used by anyone for any purpose entirely at their own
risk. It is unsupported and without warranty of any kind. No responsibility will be taken
for any direct or indirect consequences resulting from or associated with the use of this
code.
|