Please help me with a small issue.
I have the following .lsp and it needs to be slightly updated, but i can't seem to find a solution yet. I want it to zoom extents and then select all texts with colour 7 and run TTT
command (this is a custom function that exports selected text in an Excel sheet).
In my testing, it stops before selecting the text and ask me to select the desired text. I assume it's a problem with the ssget
function.
(defun C:123 (/ SS)
(command "_.Zoom" "E")
(if (setq ss (ssget "X" '((0 . "*TEXT")(62 . 7))))
(C:TTT)
)
)
Any help will be highly appreciated.
The successful operation of your program will be dependent on the definition of the c:ttt
function, specifically whether or not this function has been written to accept an implied selection.
Ideally, the c:ttt
function would be restructured as a function accepting a single selection set parameter, such that you could evaluate the function and pass your ss
selection set variable.
However, without knowledge of the definition of the c:ttt
function, the best that I could suggest would be to provide an implied selection in the following manner:
(defun c:123 ( / ss )
(command "_.zoom" "_e")
(if
(setq ss
(ssget "_X"
(list
'(0 . "TEXT")
'(62 . 7)
(if (= 1 (getvar 'cvport))
(cons 410 (getvar 'ctab))
'(410 . "Model")
)
)
)
)
(progn
(sssetfirst nil ss)
(C:TTT)
)
(princ "\nNo single-line text with object colour set to white found in the current layout/viewport.")
)
(princ)
)
You will note that I have also revised the selection criteria for your ssget
expression to only consider white single-line text residing in the current viewport/layout to ensure that the implied selection operates as expected.
EDIT: I would suggest the following revision to your code:
(defun c:123 ( / s )
(command "_.zoom" "_e")
(if (setq s (ssget "_X" '((0 . "TEXT") (62 . 7))))
(ttt s)
(princ "\nNo single-line text found with object colour set to white.")
)
(princ)
)
(defun c:ttt ( / s )
(if (setq s (ssget '((0 . "TEXT")))) (ttt s))
(princ)
)
(defun ttt ( sel / des fnm idx )
(if
(and sel
(setq fnm (vl-filename-mktemp nil nil ".csv"))
(setq des (open fnm "w"))
)
(progn
(repeat (setq idx (sslength sel))
(setq idx (1- idx))
(write-line (LM:csv-addquotes (cdr (assoc 1 (entget (ssname sel idx)))) ",") des)
)
(close des)
(startapp "explorer" fnm)
)
)
)
(defun LM:csv-addquotes ( str sep / pos )
(cond
( (wcmatch str (strcat "*[`" sep "\"]*"))
(setq pos 0)
(while (setq pos (vl-string-position 34 str pos))
(setq str (vl-string-subst "\"\"" "\"" str pos)
pos (+ pos 2)
)
)
(strcat "\"" str "\"")
)
( str )
)
)
(princ)
Here, I have defined a new function ttt
accepting a selection set argument comprised of single-line text objects, and successively writing the content of each text object in the set to a temporary CSV file (though, this could ultimately be any text format file, since only one column is used).
The new function is then evaluated by your c:ttt
function and c:123
function - the former prompting for a selection per your existing command, and the latter automatically processing all white text found in the drawing.