muddbutter Posted June 28, 2010 Posted June 28, 2010 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... Muchos Gracias! Quote
alanjt Posted June 28, 2010 Posted June 28, 2010 Step through a selection set of TEXT and add each (cdr (assoc 1 (entget ent. Quote
muddbutter Posted June 28, 2010 Author Posted June 28, 2010 Alanjt, can you clarify a little please? You just made my brain have a conniption fit! Quote
alanjt Posted June 28, 2010 Posted June 28, 2010 To write your LISP. Select your text. Step through selection, extracting each text value and converting to number with (atof (cdr (assoc 1 (entget ent Add each value to a total value. When finished, (princ (rtos total value to screen. Do you have any LISP experience or am I speaking Swahili? Quote
muddbutter Posted June 28, 2010 Author Posted June 28, 2010 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! Quote
alanjt Posted June 28, 2010 Posted June 28, 2010 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. Quote
chulse Posted June 28, 2010 Posted June 28, 2010 To write your LISP. ... Step through selection, extracting each text value and converting to number with (atof (cdr (assoc 1 (entget ent .... 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 Quote
alanjt Posted June 28, 2010 Posted June 28, 2010 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. Quote
chulse Posted June 29, 2010 Posted June 29, 2010 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... Quote
chulse Posted June 29, 2010 Posted June 29, 2010 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)? Quote
alanjt Posted June 29, 2010 Posted June 29, 2010 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) ) Quote
alanjt Posted June 29, 2010 Posted June 29, 2010 BTW, since I posted the code anyway, did you get what you needed out of this, muddbutter? Quote
Recommended Posts
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.