PDA

View Full Version : Call Expreess Tools command from Lisp



tomasz.wilk741723
2017-01-13, 04:16 PM
Hello,

I have a drawing with many objects of type TEXT. I have to change the texts to polylines. In the Express Tools there is a tool for that, that is called TXTEXP. If I try to use it out of the box, the text is very distorted, as there are many texts on a large area. If I run TXTEXP for a single text line it is perfect.
Now to the point. I have tried to use Lisp to select objects one by one and then run TXTEXP. So far I have learned why this doesn't work:

(command "TXTEXP" selset "")
TXTEXP is not a builtin command but the lisp code itself. So far I have this code:


(defun c:TXTEXP_Repeat ( / e i s ent l x selset)
(if (setq s (ssget))
(progn
(setq i 0)
(setq l (sslength s))
(repeat l
(setq e (ssname s i)
x (cdr (assoc 0 (entget e)))
ent (entget e)
i (1+ i)
)
(if (= x "TEXT")
(progn
(setq selset (ssadd e))
(command "_SELECT" selset "")
(c:TXTEXP)
(print (strcat "\nItem " (itoa i) " out of " (itoa l)))
)
(progn ;else
(print (print (strcat "\nItem " (itoa i) " not a TEXT. ")))
)
)

)
)
)
(princ)
)

It doesn't work - the selection made from the selset selection set does not go to TXTEXP, which still asks to select text for exploding. I have run out of ideas. Anyone can help?

Cheers
Tomasz

BIG-AL
2017-01-14, 04:21 AM
This may be like extrim you can call it but it actually uses a different defun that allows a selection pick. I am trying to find



(load "Extrim")
(etrim obj pt1)


Found this very interesting original code http://www.eng-tips.com/viewthread.cfm?qid=68580


; look at changing this to the selection set that you have ie no picking
(prompt "\nSelect text to be EXPLODED: ")

(Setq FLTR '((-4 . "<AND")
(-4 . "<OR") ; filter for mtext and text
(0 . "MTEXT")
(0 . "TEXT")
(-4 . "OR>")
(-4 . "<NOT")
(102 . "{ACAD_REACTORS") ; and not leader text
(-4 . "NOT>")
(-4 . "AND>")
)
GLST (acet-txtexp-grplst) ; Get all the groups in drawing
GDICT (if GLST
(dictsearch (namedobjdict) "ACAD_GROUP")
)
SS (ssget FLTR)
CNT 0
)

tomasz.wilk741723
2017-01-16, 10:09 AM
Thanks BIG-AL for the reply.

Unfortunately there is no alternative defun with an argument.

What I ended up doing, was what you suggested in the second code window. I have changed the txtexp.lsp in Express folder, in AutoCAD folder within Program Files. I have added one argument to the definition of c:TXTEXP and then substituted (ssget FLTR) with this argument. I had to manually load the changed lsp to AutoCAD, as the original one is read from compiled fas file though.

Other than that I had to add if statement to check for text with one space alone, as those caused an error.

The changes in txtexp.lsp:


(defun c:txtexp (selectionSet / ...

...

SS selectionSet ; was (ssget FLTR)



The final version of my function:


(defun c:TXTEXP_Repeat ( / e i s ent l x selset tv)
(if (setq s (ssget))
(progn
(setq i 0)
(setq l (sslength s))
(repeat l
(setq e (ssname s i)
x (cdr (assoc 0 (entget e)))
tv (cdr (assoc 1 (entget e))) ;text value
ent (entget e)
i (1+ i)
)
(if (and (= x "TEXT") (not (= tv " ")))
(progn
(setq selset (ssadd e))
;(command "WYBIERZ" selset "")
;(print (entget e))
(c:TXTEXP selset)
(print (strcat "\nItem " (itoa i) " out of " (itoa l)))
)
(progn ;else
(print (print (strcat "\nItem " (itoa i) " not a TEXT. ")))
)
)

)
)
)
(princ)
)