Jump to content

Sum of numbers in text strings


mikman

Recommended Posts

No, use entmake. Text in command is the most temperamental function that can be called.

That's right,

Here it goes with enmake ......

(defun C:STX (/ elist en ss sum sumtxt txt ins)
;;created by Fixo
;;revised by Reid B. for sanalmakina
(princ "\n\t\t>>>  Select text to get summ >>>")
(if
;;select texts/mtexts on screen :
(setq ss (ssget '((0 . "*TEXT"))))
;; if selected then :
(progn
 ;; set initial sum to zero :
 (setq sum 0.)
 ;; loop trough selected texts/mtexts :
 (while
   ;; get the first text in selection :
   (setq en (ssname ss 0))
   ;; get entity list of them :
   (setq elist (entget en))
   ;; get the textstring by key 1 from entity list :
   (setq txt (cdr (assoc 1 elist)))
   ;; create output string :
   (setq sumtxt
   ;; concatenate strings :
   (strcat
     ;; convert digits to string :
     (rtos
       ;; add to summ the digital value of text :
       (setq sum (+ (atof txt) sum))
       ;; 2 is for metric units (3 for engineering) :
       5;;revised by Reid B.
       ;; set precision by current :
       (getvar "dimdec"))" " "m3/h")
  )
   ;; delete entity from selection set :
   (ssdel en ss)
   )
 ;; Change to text :
   (setq ins (getpoint "\nSpecify text location: "));;start revision by Reid B.
 (entmake (list '(0 . "TEXT")
                  (cons 40 (getvar 'textsize))
                  (cons 10 ins)
                  (cons 1 sumtxt)
	   )))   
 
)
(princ)
 )
(princ "\nStart command with STX...")
(princ)

Link to comment
Share on other sites

(cons 7 (getvar 'textstyle))

thank you Alan! I'll definitely use this one

Actually, it was textsize I was thinking about. Entmake will use the current textstyle to create the text, you don't need it at all, unless you want a different style. Sorry about that.

Link to comment
Share on other sites

Actually, it was textsize I was thinking about.

this is something that is useful to me.

 

 

So, is (cons 100 "AcDbEntity") and (cons 100 "AcDbText") needed?

Link to comment
Share on other sites

this is something that is useful to me. So' date=' is (cons 100 "AcDbEntity") and (cons 100 "AcDbText") needed?[/quote']

It varies with certain objects.

Link to comment
Share on other sites

That's right,

Here it goes with enmake ......

(defun C:STX (/ elist en ss sum sumtxt txt ins)
;;created by Fixo
;;revised by Reid B. for sanalmakina
(princ "\n\t\t>>>  Select text to get summ >>>")
(if
;;select texts/mtexts on screen :
(setq ss (ssget '((0 . "*TEXT"))))
;; if selected then :
(progn
 ;; set initial sum to zero :
 (setq sum 0.)
 ;; loop trough selected texts/mtexts :
 (while
   ;; get the first text in selection :
   (setq en (ssname ss 0))
   ;; get entity list of them :
   (setq elist (entget en))
   ;; get the textstring by key 1 from entity list :
   (setq txt (cdr (assoc 1 elist)))
   ;; create output string :
   (setq sumtxt
   ;; concatenate strings :
   (strcat
     ;; convert digits to string :
     (rtos
       ;; add to summ the digital value of text :
       (setq sum (+ (atof txt) sum))
       ;; 2 is for metric units (3 for engineering) :
       5;;revised by Reid B.
       ;; set precision by current :
       (getvar "dimdec"))" " "m3/h")
  )
   ;; delete entity from selection set :
   (ssdel en ss)
   )
 ;; Change to text :
   (setq ins (getpoint "\nSpecify text location: "));;start revision by Reid B.
 (entmake (list '(0 . "TEXT")
                  (cons 40 (getvar 'textsize))
                  (cons 10 ins)
                  (cons 1 sumtxt)
	   )))   
 
)
(princ)
 )
(princ "\nStart command with STX...")
(princ)

 

Thank you so much , it worked! :)

-fixo

-Lt Dan's legs

-David Bethel

-tharwat313

-alanjt

Link to comment
Share on other sites

what about in this case? I wasn't sure if the version of acad played a factor
Version shouldn't have a factor, but don't quote me on that.
Link to comment
Share on other sites

don't quote me on that.

:P

 

 

I've come across this before but I didn't understand why it was used.. maybe I'll search for that routine and have another look at it.

 

Thanks

Link to comment
Share on other sites

Thank you so much , it worked! :)

-fixo

-Lt Dan's legs

-David Bethel

-tharwat313

-alanjt

 

First we should thank Mr.fixo because the codes were written by him.

 

I am glad you got it worked finally.. :)

 

Enjoy it ..

 

Tharwat

Link to comment
Share on other sites

So' date=' is (cons 100 "AcDbEntity") and (cons 100 "AcDbText") needed?[/quote']

 

For legacy reasons, entmake ignores DXF group code 100 data for the following entity types:

 

  • AcDbText
  • AcDbAttribute
  • AcDbAttributeDefinition
  • AcDbBlockBegin
  • AcDbBlockEnd
  • AcDbSequenceEnd
  • AcDbBlockReference
  • AcDbMInsertBlock
  • AcDb2dVertex
  • AcDb3dPolylineVertex
  • AcDbPolygonMeshVertex
  • AcDbPolyFaceMeshVertex
  • AcDbFaceRecord
  • AcDb2dPolyline
  • AcDb3dPolyline
  • AcDbArc
  • AcDbCircle
  • AcDbLine
  • AcDbPoint
  • AcDbFace
  • AcDbPolyFaceMesh
  • AcDbPolygonMesh
  • AcDbTrace
  • AcDbSolid
  • AcDbShape
  • AcDbViewport

 

 

It is required in all other entities.

Link to comment
Share on other sites

Would you say it's good practice to include or should I get familiar with this?

 

Its no harm to include them, but it will fail if those code are not included when needed.

 

I usually only include the codes that are needed, but then I usually can't be bothered to type it out lol

Link to comment
Share on other sites

Looking at the list all the things is use entmake for are there... but I am pretty forgetful. I think I'll include in my routines so I don't forget when it matters and wonder why it's not working. Thanks

Link to comment
Share on other sites

  • 4 months later...

Hey I just started to use this lisp... That Fixo wrote and others edited from this thread...

The problem I'm having is all out text is underlined for our key notes. and the lisp will not add them up.

 

here's the code. is there anyone that can fix it so it recognizes the underlined text strings.

 

(defun C:STX (/ cpent elist en ip newtxt pt ss sum sumtxt txt)
(princ "\n\t\t>>>  Select text to get summ >>>")
(if
;;select texts/mtexts on screen :
(setq ss (ssget '((0 . "*TEXT"))))
;; if selected then :
(progn
 ;; store the first text entity for using 'em further :
(setq cpent (ssname ss 0))
 ;; set initial sum to zero :
 (setq sum 0.)
 ;; loop trough selected texts/mtexts :
 (while
   ;; get the first text in selection :
   (setq en (ssname ss 0))
   ;; get entity list of them :
   (setq elist (entget en))
   ;; get the textstring by key 1 from entity list :
   (setq txt (cdr (assoc 1 elist)))
   ;; create output string :
   (setq sumtxt
   ;; concatenate strings :
   (strcat
     ;; convert digits to string :
     (rtos
       ;; add to summ the digital value of text :
       (setq sum (+ (atof txt) sum))
       ;; 2 is for metric units (3 for engineering) :
       2
       ;; set precision by current :
       (getvar "dimdec")))
  )
   ;; delete entity from selection set :
   (ssdel en ss)
   )
 ;; display message in the command line:
 (princ (strcat "\nSumm=" sumtxt))
 (setq pt (getpoint "\nSpecify the new text location: "))
 ;; get the insertion point of stored entity :
 (setq ip (cdr (assoc 10 (entget cpent))))
 ;; copy text entity to the new destination point :
 (command "_copy" cpent "" ip pt)
 ;; get the last created entity :
 (setq newtxt (entlast))
 ;; get entity list of them :
 (setq elist (entget newtxt))
 ;; modify entity list with new text string :
 (entmod (subst (cons 1 sumtxt)(assoc 1 elist) elist))
 ;; update changes :
 (entupd newtxt)
 )
)
(princ)
 )
(princ "\nStart command with STX...")
(princ)

Edited by sandman007
Wearing the wrong shoes
Link to comment
Share on other sites

Assuming Alan used (getvar 'textsize)

 

if you want to have 4" high text then

(setvar 'textsize 4)

 

__edit__

actually I do not see it...

Link to comment
Share on other sites

Assuming Alan used (getvar 'textsize)

 

if you want to have 4" high text then

(setvar 'textsize 4)

 

__edit__

actually I do not see it...

vla-AddMText uses the current text settings (style and textsize variable). I use it over entmake because it works with annotative text styles.

Link to comment
Share on other sites

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...