PDA

View Full Version : Change existing text to new Textstyle



Mater
2011-04-27, 06:08 PM
I'm looking for some help. I came across this lisp routine and tried to modify it to select every object on the "Labels" layer. I keep getting this error:


ActiveX Server returned the error: unknown name: STYLENAME

The original code I found had the code below at line 2 but the user has to select the objects


(setq ss1 (ssget (list (cons 0 "*text")))

I would like the lisp to select all the text on the labels layer without user input other than the style that they want to change the text too. Here is the modified lisp in it's entirety:



(defun c:ft ( / ss1 index newstyle styledata defwidth ename txtobj)
(setq ss1 (ssget "x" '((8 . "Labels") ))
index 0
newstyle (getstring "\nEnter new style for text: ")
)
(if (setq styledata (tblsearch "style" newstyle))
(progn
(setq defwidth (cdr (assoc 41 styledata)))
(while (setq ename (ssname ss1 index))
(setq txtobj (vlax-ename->vla-object ename))
(vlax-put-property txtobj 'StyleName newstyle)
(if (vlax-property-available-p txtobj 'ScaleFactor)
(vlax-put-property txtobj 'ScaleFactor defwidth)
)
(setq index (1+ index))
)
)
(princ "\nRequested text style does not exist!")
)
(princ)
)


Thanks

alanjt
2011-04-27, 06:41 PM
Try:
(ssget "_X" '((0 . "MTEXT,TEXT") (8 . "Labels")))

My guess would be that you're selecting a piece of RText or ArcText with *TEXT.

Mater
2011-04-27, 07:09 PM
Awsome that did it.

Thanks for the help.

alanjt
2011-04-27, 07:12 PM
Awsome that did it.

Thanks for the help.You're welcome.

BeKirra
2011-04-28, 01:56 AM
Try:
(ssget "_X" '((0 . "MTEXT,TEXT") (8 . "Labels")))

My guess would be that you're selecting a piece of RText or ArcText with *TEXT.
Alan,
What if the selected entity was a circle, line or pline etc.
Do I have to specify the the entity name and replace the "MTEXT,TEXT" at the line above?
Thanks.

alanjt
2011-04-28, 02:00 AM
Alan,
What if the selected entity was a circle, line or pline etc.
Do I have to specify the the entity name and replace the "MTEXT,TEXT" at the line above?
Thanks.
That's what the (0 . "TYPE") portion does, it filters your selection based on entity type.

(0 . "CIRCLE") to only select circles
(0 . "ARC,LINE") to only select arcs and lines

Or am I not understanding your question?

BeKirra
2011-04-28, 02:18 AM
That's what the (0 . "TYPE") portion does, it filters your selection based on entity type.

(0 . "CIRCLE") to only select circles
(0 . "ARC,LINE") to only select arcs and lines

Or am I not understanding your question?
Thanks, Alan. Your answer is what I was after.
Just one more.
If I am writing a piece of code for any type of entity selections, I then have to add all entity names based on the DXF classification (ie. line, lwpolyline, arc, circle...).
Am I right?
If this is the case, it would be painful.

alanjt
2011-04-28, 03:42 AM
Thanks, Alan. Your answer is what I was after.
Just one more.
If I am writing a piece of code for any type of entity selections, I then have to add all entity names based on the DXF classification (ie. line, lwpolyline, arc, circle...).
Am I right?
If this is the case, it would be painful.
If the selection applies to anything, the you don't need to worry about filtering. The point of filtering is to ONLY select or not select particular properties/object types.

(ssget) will select anything
(ssget '((0 . "~VIEWPORT"))) will select anything EXCEPT viewports
(ssget "_:L") will select anything except objects on locked layers
(ssget '((8 . "0"))) will only select objects on the "0" layer