Jump to content

Calculator From Hell Lisp?


Recommended Posts

Posted

Hey y'all,

Here's the deal. I have created a coordinate table for a gas pipeline. There are 77 distances that I want to add up. Each distance is it's own DTEXT entity. Is it possible for all 77 distances to be highlighted and added up with out having to manually entering in every number in the calculator? Or is there a lisp routine for this?

 

I know it's kind of a funky question...:unsure:

 

Muchos Gracias!

Posted

Step through a selection set of TEXT and add each (cdr (assoc 1 (entget ent.

Posted

Alanjt, can you clarify a little please? You just made my brain have a conniption fit! :P

Posted

To write your LISP.

 

  1. Select your text.
  2. Step through selection, extracting each text value and converting to number with (atof (cdr (assoc 1 (entget ent
  3. Add each value to a total value.
  4. When finished, (princ (rtos total value to screen.

Do you have any LISP experience or am I speaking Swahili?

Posted

Sir, you are definitely speaking Swahili, however I am beginning the process of learning the lisp world. This information will be helpful im sure. Thank you!

Posted
Sir, you are definitely speaking Swahili, however I am beginning the process of learning the lisp world. This information will be helpful im sure. Thank you!
I'm more than happy to help. :)
Posted
To write your LISP.

 

  1. ...
  2. Step through selection, extracting each text value and converting to number with (atof (cdr (assoc 1 (entget ent
  3. ....

 

Alan, can you walk me through what this is doing with the entity (ent?)? Specifically, what is the (assoc 1 doing?

I assume you would use something like

(Foreach ent (selectionset) to walk through it..?

 

I really am trying to learn this...:?

 

Thanks

Posted

Alan, can you walk me through what this is doing with the entity (ent?)? Specifically, what is the (assoc 1 doing?

I assume you would use something like

(Foreach ent (selectionset) to walk through it..?

 

I really am trying to learn this...:?

 

Thanks

Sure thing. :) Here's an example (not exactly how I'd do it, but it's a simpler way to newer LISPers.

 

(defun c:Test (/ total i ss)
 (if (setq total 0. ; define a value to start with
           i     -1 ; will need to step through SS
           ss    (ssget '((0 . "TEXT"))) ; select text
     )
   (progn
     (while (setq e (ssname ss (setq i (1+ i)))) ; step through SS and get each entity
       (setq total (+ total ; add total to new value
                      (atof ; convert string value to real
                        (cdr ; take item in dotted pair list
                          (assoc 1 ; extract (1 . "") from entity list
                                 (entget e) ; get entity list from EName
                          )
                        )
                      )
                   )
       )
     )
     (or (zerop total) (alert (strcat "Total: " (rtos total)))) ; print total if > zero
   )
 )
 (princ)
)

This is how I'd do it (wrote it earlier)...

(defun c:TAdd (/ ss)
 ;; Alan J. Thompson, 06.28.10
 (if (setq ss (ssget '((0 . "TEXT"))))
   ((lambda (i total)
      (while (setq e (ssname ss (setq i (1+ i))))
        (setq total (+ total (atof (cdr (assoc 1 (entget e))))))
      )
      (or (zerop total) (alert (strcat "Total: " (rtos total))))
    )
     -1
     0.
   )
 )
 (princ)
)

Let me know if you have any questions.

Posted

Thanks Alan!

I think I see how entget gives the data associated with the object, but

where do I find the entity data info (for a specific entity type) to know what item to extract with (assoc #)?

I had been playing with some other text editing, but could never figure out how to get the contents of the text object into a string that I could manipulate...

Posted

I may have answered my own question - is that the DXF Group code? Is that the same for all types of objects (i.e. some objects don't have data for all the codes)?

Posted

VLIDE help

http://autodesk.com/techpubs/autocad/acad2000/dxf/

 

I also use this for selecting objects...

 

(defun c:Info (/ opt obj)
 ;; VLA & DXF Info of selected Primary or Nested object
 ;; Alan J. Thompson
 (initget 0 "Nested Primary")
 (setq opt (cond ((getkword "\nSpecify selection mode [Nested/Primary] <Primary>: "))
                 ("Primary")
           )
 )
 (if (setq obj (car ((if (eq opt "Primary")
                       entsel
                       nentsel
                     )
                      (strcat "\nSelect " opt " object for VLA & DXF info: ")
                    )
               )
     )
   (progn
     (textscr)
     (princ "\nVLA Info:\n\n")
     (vlax-dump-object (vlax-ename->vla-object obj) T)
     (princ "\nDXF Info:\n")
     (mapcar 'print (entget obj))
   )
 )
 (princ)
)

Posted

BTW, since I posted the code anyway, did you get what you needed out of this, muddbutter?

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