Jump to content

Recommended Posts

Posted

Dear friends,

I would like to learn how can I count the number of texts (strings) in a drawing using autolisp?

Best regards.

Posted (edited)

Do you want to also filter them by a criteria? I mean: color, layer, content...

To count all text entities:

(if (setq ssText (ssget "_X" '((0 . "TEXT"))))
(alert (strcat "This drawing contains " (itoa (sslength ssText)) " text entities."))
)

This will include mtext in selection:

(if (setq ssText (ssget "_X" '((0 . "*TEXT"))))
(alert (strcat "This drawing contains " (itoa (sslength ssText)) " text/mtext entities."))
)

Edited by MSasu
Fixed code example
Posted

Thanks for the quick response.

I must have done something stupid.

The AutoCAD gives an error "error: bad SSGET list"

What is wrong with this code?

(defun c:ntxt ()[font=&quot]
     (if (setq ssText (ssget "_X" '((0 . "*TEXT"))))[/font]  [font=&quot] (alert "This drawing contains " (strcat (itoa (sslength ssText)) " text/mtext entities."))[/font]
 [font=&quot])[/font]
 [font=&quot])[/font]

Posted

(alert (strcat "This drawing contains " (itoa (sslength ssText)) " text/mtext entities.")

 

Besides that , localize variables ..

 

(defun c:ntxt (/ ssText)

Posted

Thanks Lee.

It's really good, but what I wanted to learn, is how build code as you and these are small steps that help me understand how this works.

I hope don't bother you with same stupid questions in future.

Best regards.

Posted
Thanks Lee.

It's really good, but what I wanted to learn, is how build code as you and these are small steps that help me understand how this works.

 

Not a problem, I admire your willingness to learn.

 

I hope don't bother you with same stupid questions in future.

 

Ask as many questions as you need for your understanding!

Posted

@RMateus: I edited the counting report after pasted the code and thus the error. I have fixed my example now. Sorry for inconvenience!

  • 1 year later...
Posted

Dear Friends, I will like to download a lisp routine of a command that provides me the same functions of tcount instead of counting number counts in alphabetical order

Posted

CristianG do you want to know how many start with A or just a list in alphabetical order ?

 

(defun c:ntxt ()[font=&quot]      (if (setq ssText (ssget "_X" '((0 . "*TEXT")(1 . "A*"))))[/font]  [font=&quot] (alert "This drawing contains " (strcat (itoa (sslength ssText)) " text/mtext entities."))[/font]  [font=&quot])[/font]  [font=&quot])[/font]

Posted

Or even easier, check ACAD_STRLSORT function - it will not required defining the sorting function, but must validate that the argument isn't nil.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...