TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: POCKETS on May 10, 2011, 03:53:36 PM
-
We get a number of drawings from vendors with text that doesn't match our company standard. In order to put these drawings into our system the vendors text has to be changed to our standards. As an example: Vendor's text is Ariel and Ariel bold and we have to change them to Romans. Is there a lisp that will make these changes without having to call up the text style dialog box for each drawing?
Using AutoCAD R2008
Pockets
-
Flip da SCRipt, yo!!
Batch script should do the job.
-STYLE
ARIAL
ROMANS
<ENTER>
<ENTER>
<ENTER>
<ENTER>
<ENTER>
<ENTER>
<ENTER>
<ENTER>
<ENTER>
<ENTER>
<ENTER>
<ENTER>
<ENTER>
Well, maybe not THAT many, but you get the idea. Just do it on the command line and count along.
-
Or put a little LISP in your script:
(command "_.-style" "ARIAL" "ROMANS")
(while (eq 1 (logand 1 (getvar 'CMDACTIVE))) (command ""))
-
How about using ObjectDBX?
You could call my ObjectDBX Wrapper (http://lee-mac.com/odbxbase.html) using this:
(defun c:test1 ( / lst )
;; List of Old and New TextStyles:
(setq lst '(("ARIAL" . "ROMANS") ("ARIAL BOLD" . "ROMANS")))
;; ^^ Be sure to use capitals here (also no check that new style exists)
(foreach x (LM:ODBX '(lambda ( x ) (ChangeTextStyle x lst)) nil t)
(princ
(strcat "\n--> Drawing: " (car x)
(if (vl-catch-all-error-p (cdr x))
(strcat "\n Error: " (vl-catch-all-error-message (cdr x)))
"\nSuccessful."
)
)
)
)
(princ)
)
(defun ChangeTextStyle ( doc StyleList / new )
(vlax-for layout (vla-get-layouts doc)
(vlax-for object (vla-get-block layout)
(if
(and
(wcmatch (vla-get-objectname object) "AcDb*Text")
(setq new (cdr (assoc (strcase (vla-get-stylename object)) StyleList)))
)
(vla-put-stylename object new)
)
)
)
)
-
Lee Mac, Matt,
I have the foggist idea as to how to get your programs to work.
Below is a program I got from Andrea at the swamp but it doesn't change true text to .shx text such as the Ariel to Romans. Any help will be appreciated.
; Replaces ALL text with Romans.shx TSR
;;theswamp.org Andrea 2:47 PM 9/16/2010
;;;TextStyleReplace
(defun c:TSR (/ Att ActDoc att Obj Blk n tot f)
(vl-load-com)
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)) tot 0 n 0)
;_Unlock les couches
(vlax-for lay (vla-get-layers ActDoc)
(vla-put-Lock lay :vlax-false)
(vl-catch-all-apply 'vla-put-Freeze (list lay :vlax-false))
)
;; (vla-put-ActiveLayer ActDoc (vla-item (vla-get-layers ActDoc) "0"))
;;capture tous les block
(vlax-for Blk (vla-get-Blocks ActDoc)
(setq tot (+ tot (vla-get-count blk)))
)
;;CREATION DU STYLE ROMANS
(mapcar (function (lambda ( _font / text_style)
(setq text_style (vla-add (vla-get-textstyles ActDoc) _font))
(vla-put-fontfile text_style "ROMANS.SHX")
(vla-put-height text_style 0.0)
(vla-put-width text_style 1.0)
(vla-put-activetextstyle ActDoc text_style)))
'("ROMANS"))
(acet-ui-progress-init "Traitement" tot)
;;traitement des blocks
(vlax-for Blk (vla-get-Blocks ActDoc)
(vlax-for Obj Blk
(setq n (1+ n))
(acet-ui-progress-safe n)
(setq f (vla-get-layer Obj))
(vla-put-layer Obj "0")
(cond
((vlax-property-available-p Obj 'TextStyle) ;_DIMENSION
(vl-catch-all-apply 'vla-put-TextStyle (list Obj "ROMANS"))
)
((vlax-property-available-p Obj 'StyleName) ;_TEXT,MTEXT, ATTRIBUTE
(vl-catch-all-apply 'vla-put-stylename (list Obj "ROMANS"))
)
((and
(eq (vla-get-objectname Obj) "AcDbBlockReference")
(not (vlax-property-available-p Obj 'Path)) ;_Not Xref ???
(eq (vla-get-hasattributes Obj) :vlax-true)
)
(progn
(vla-put-layer Obj f)
(foreach Att (vlax-invoke Obj 'getattributes)
(vl-catch-all-apply 'vla-put-stylename (list Att "ROMANS"))
)
)
)
(t nil)
)
)
)
(setq ss1 (ssget "X" '((0 . "MTEXT,TEXT"))))
(if ss1
(progn
(setq sscount (sslength ss1))
(setq val1 (- sscount 1))
(repeat sscount
(setq ent (vlax-ename->vla-object (ssname ss1 val1)))
(vla-put-layer ent "TextLayer")
(setq val1 (- val1 1))
)
)
)
(vla-Regen ActDoc acActiveViewport)
(acet-ui-progress-done)
(princ)
)
-
Hi Pockets,
I haven't currently got access to CAD but to run my program, do the following:
Download the ObjectDBX Wrapper program from the link I posted.
Open a new (blank) drawing and load the ObjectDBX Wrapper program.
Save the snippet of code I posted above and change the list at the top to suit your styles - it takes the form: ((oldstyle . newstyle)(oldstyle . newstyle) ... )
Load and run the code snippet.
-
i have been using this from T. Willey for some time and works good.
only thing i found that it does not take on is R-text
-http://www.theswamp.org/index.php?topic=17659.0;all
Greetz john
sorry for bad english