Author Topic: Autolisp ssget help aarrrggh  (Read 1794 times)

0 Members and 1 Guest are viewing this topic.

diarmuid

  • Bull Frog
  • Posts: 417
Autolisp ssget help aarrrggh
« on: December 20, 2012, 07:09:48 AM »
I'm rusty at this, below is a piece of lisp that i wrote.  It is basically a part of a routine to select a piece of text in a titleblock (it is an old cad file and it has no attributes, it is just dumb text).  The text appears in the same location every drawing (about 200 of them, ISO's).  It just woudn't seem to select the text.  when i manage to select the text i will extract the contents and write it to a file along with the filename and file loaction etc.  Can anyone see where i'm going wrong?

Here is my original lisp, but for this one i need to select the text individually.

Code - Auto/Visual Lisp: [Select]
  1. (setq iso (entsel))
  2. (setq txttle (entget (car iso)))
  3. (setq txt1 (cdr(assoc 1 txttle)))
  4. (setq f (open "c:\\Documents and Settings\\ryand\\Desktop\\Isodata.txt" "a"))
  5. (write-line txt1 f)
  6. (close f)
  7.  


I've been tryin to sustitute the code below to pick the text via a window croosing or point click etc, but i'm im getting no where

Code - Auto/Visual Lisp: [Select]
  1. (setq pt1 '(345 26))
  2. (setq pt2 '(413 20))
  3. (setq iso1 (ssget "w" pt1 pt2))
  4. (setq EN (entget (car (iso1))))
  5.  


Any help or pointers would be greatly appreciated.

What i'm trying to do.

Open the cad file select the piece of text extract the contents and write that to a txt file (write-line) its actually 3 different pices of text in the drawing but the same process will apply.  (filename - tag - the revision)  All dumb text.
If you want to win something run the 100m, if you want to experience something run a marathon

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Autolisp ssget help aarrrggh
« Reply #1 on: December 20, 2012, 08:00:39 AM »
try changing:
 
Code: [Select]
(car (iso1))
to

Code: [Select]
(ssname iso 0)
Though some robust error checking probably would be advisable.  -David
R12 Dos - A2K

hmspe

  • Bull Frog
  • Posts: 362
Re: Autolisp ssget help aarrrggh
« Reply #2 on: December 20, 2012, 08:07:33 AM »
To get text at a specific point I use code similar to this:
Code: [Select]
(defun getss_filter (point distance filter)
  (ssget "c"
         (list (- (car point) distance) (- (cadr point) distance))
         (list (+ (car point) distance) (+ (cadr point) distance))
         filter
  )
)

I call the function like this:
Code: [Select]
(setq point1 (list 379.0 23.0 0.0))
(setq box_size 3.0)
(setq filter_set '((-4 . "<OR") (0 . "TEXT") (0 . "MTEXT") (-4 . "OR>")))
(setq selset (getss_filter point1 box_size filter_set))


"Science is the belief in the ignorance of experts." - Richard Feynman

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Autolisp ssget help aarrrggh
« Reply #3 on: December 20, 2012, 09:08:36 AM »
Code: [Select]
;;   How to itterate through a selection set

;;==========   Fastest Method   ============================================
;;  http://www.theswamp.org/index.php?topic=14184.msg171131#msg171131
(defun ss->lst (ss / i ename result)
  (and (eq 'pickset (type ss))
       (setq i -1)
       (while (setq ename (ssname ss (setq i (1+ i))))
         (setq result (cons ename result))
       )
  )
  result
)

Another way
Code: [Select]
(setq lst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

diarmuid

  • Bull Frog
  • Posts: 417
Re: Autolisp ssget help aarrrggh
« Reply #4 on: December 20, 2012, 11:30:32 AM »
Thansk for all of the help guy's.

Working away.  THis is going to save me a ton of pain.  here is the final product.  I've kinda taken snipets from David's and hmspe's suggestions.

Great stuff!

Happy Christmas Guys!

Diarmuid

Code - Auto/Visual Lisp: [Select]
  1. (princ "\nEnter:isograb to run")
  2.  
  3. (defun c:isograb (/ pt1 pt2 pt21 pt22 pt31 pt32 iso1 iso2 iso3 EN1 EN2 EN3 f )
  4.  
  5.     (setq pt1 '(340 27))
  6.     (setq pt2 '(414 19))
  7.     (setq iso1 (ssget "w" pt1 pt2 '((-4 . "<OR") (0 . "TEXT") (0 . "MTEXT") (-4 . "OR>"))))
  8.     (setq EN1 (cdr(assoc 1 (entget (ssname iso1 0)))))
  9.  
  10.     (princ "\nEN1 extracted...")
  11.  
  12.  
  13.     (setq pt21 '(375 19))
  14.     (setq pt22 '(386 13))
  15.     (setq iso2 (ssget "w" pt21 pt22 '((-4 . "<OR") (0 . "TEXT") (0 . "MTEXT") (-4 . "OR>"))))
  16.     (setq EN2 (cdr(assoc 1 (entget (ssname iso2 0)))))
  17.  
  18.     (princ "\nEN2 extracted...")
  19.    
  20.    
  21.     (setq pt31 '(404 19))
  22.     (setq pt32 '(414 5))
  23.     (setq iso3 (ssget "w" pt31 pt32 '((-4 . "<OR") (0 . "TEXT") (0 . "MTEXT") (-4 . "OR>"))))
  24.     (setq EN3 (cdr(assoc 1 (entget (ssname iso3 0)))))
  25.  
  26.     (princ "\nEN3 extracted...")
  27.  
  28. (setq f (open "c:\\Documents and Settings\\ryand\\Desktop\\Isodata.txt" "a"))
  29. (setq infoline (strcat "Drawing Number: " EN1 "      Sheet of: " EN2 "      Revision No: " EN3))
  30. (write-line infoline f)
  31. (close f)
  32.  
  33.  
  34. )
  35.  
If you want to win something run the 100m, if you want to experience something run a marathon

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Autolisp ssget help aarrrggh
« Reply #5 on: December 20, 2012, 01:02:38 PM »
Condensed:

Code: [Select]
(and (setq pt1 '(340 27)
           pt2 '(414 19))
     (setq iso1 (ssget "w" pt1 pt2 '((0 . "MTEXT,TEXT"))))
     (= (sslength iso1) 1)
     (setq EN1 (ssname iso1 0)))

-David
R12 Dos - A2K