Jump to content

Help Finishing this Script Urgent plz


smallpixel

Recommended Posts

Hi people,i'm a newbies in AutoLisp

and my script is pretty easy and i already make 99% of the work ,

i have a lot of text in my DWG file and i want to ouput the XY coordonate of each text(look down for the script),and get the centent of the text and put that into the Z coordonate (look down for the script used to ouput the name of the text)

in the end i wanna combine those too script to ouput all the data in some file in this format X,Y,Centent of the text (us the Z component)

 

///////Script for Exporting the Name of text////////

 

(defun C:txtex (/ et)
(setq fl (open "dtext.txt" "w")
et (entnext)
)
(while et
(setq el (entget et)
tp (cdr (assoc 0 el))
)
(if (or (= tp "TEXT") (= tp "MTEXT"))
(write-line (cdr (assoc 10 el)) fl)
)
(setq et (entnext et))
)
(close fl)
)

///////Script for XY Exporting////////

 

(defun c:PO2TXT (/ file points c i) ;POints to TeXT 
 (setq file (open (getfiled "specify output file" "c:/" "TXT" 1) "w"))
 (setq points (ssget) i 0)
 (repeat (sslength points)
   (if (= "TEXT" (cdr (assoc 0 (entget (ssname points i)))))
     (setq c (cdr (assoc 10 (entget (ssname points i))))
    i (1+ i)
     )
   )
   (write-line
     (strcat (rtos (car c)) " , "
      (rtos (cadr c)) 
         ) file)
 )
 (close file)
 (Princ)
)

Link to comment
Share on other sites

This will write content:

 

(defun C:txtex (/ fl ss ssl index ent)
   (setq fl    (open "dtext.txt" "w")
     ss    (ssget "x" (list (cons 0 "TEXT,MTEXT")))
     ssl    (sslength ss)
     index    0
   ) ;_  end setq
   (repeat ssl
   (setq ent (entget (ssname ss index)))
   (write-line (cdr (assoc 1 ent)) fl)
   (setq index (1+ index))
   ) ;_  end repeat
   (close fl)
   (princ)
) ;_  end defun

Link to comment
Share on other sites

This will write points:

 

(defun c:PO2TXT    (/ file points c i)
   (setq file (open (getfiled "Specify Output File" "c:/" "txt" 1) "w"))
   (setq points (ssget "X" (list (cons 0 "TEXT,MTEXT")))
     i     0
   ) ;_  end setq
   (repeat (sslength points)
   (setq c    (cdr (assoc 10 (entget (ssname points i))))
         i    (1+ i)
   ) ;_  end setq
   (write-line
       (strcat (rtos (car c))
           " , "
           (rtos (cadr c))
       ) ;_  end strcat
       file
   ) ;_  end write-line
   ) ;_  end repeat
   (close file)
   (princ)
) ;_  end defun

Link to comment
Share on other sites

Maybe this to link them?

 

(defun c:PO2TXT    (/ file points c vl i)
   (setq file (open (getfiled "Specify Output File" "c:/" "txt" 1) "w"))
   (setq points (ssget '((0 . "TEXT,MTEXT")))
     i     0
   ) ;_  end setq
   (repeat (sslength points)
   (setq c     (cdr (assoc 10 (entget (ssname points i))))
         vl (cdr (assoc 1 (entget (ssname points i))))
         i     (1+ i)
   ) ;_  end setq
   (write-line
       (strcat (rtos (car c))
           " , "
           (rtos (cadr c))
           "\t"
           vl
       ) ;_  end strcat
       file
   ) ;_  end write-line
   ) ;_  end repeat
   (close file)
   (princ)
) ;_  end defun

(All three untested)

Link to comment
Share on other sites

LISPs updated. ---> they didn't include MTEXT - sorry about that :oops:

 

Also, there are two ways to do it:

 

Have a LISP in which the user selects which text to print to file:

 

(defun c:PO2TXT1    (/ file points c vl i)
   (setq file (open (getfiled "Specify Output File" "c:/" "txt" 1) "w"))
   (setq points (ssget '((0 . "TEXT,MTEXT")))
     i     0
   ) ;_  end setq
   (repeat (sslength points)
   (setq c     (cdr (assoc 10 (entget (ssname points i))))
         vl (cdr (assoc 1 (entget (ssname points i))))
         i     (1+ i)
   ) ;_  end setq
   (write-line
       (strcat (rtos (car c))
           " , "
           (rtos (cadr c))
           "\t"
           vl
       ) ;_  end strcat
       file
   ) ;_  end write-line
   ) ;_  end repeat
   (close file)
   (princ)
) ;_  end defun

Link to comment
Share on other sites

Or have a LISP which selects all the text entities automatically and prints them:

 

(defun c:PO2TXT    (/ file points c vl i)
   (setq file (open (getfiled "Specify Output File" "c:/" "txt" 1) "w"))
   (setq points (ssget "X" (list (cons 0 "TEXT,MTEXT")))
     i     0
   ) ;_  end setq
   (repeat (sslength points)
   (setq c     (cdr (assoc 10 (entget (ssname points i))))
         vl (cdr (assoc 1 (entget (ssname points i))))
         i     (1+ i)
   ) ;_  end setq
   (write-line
       (strcat (rtos (car c))
           " , "
           (rtos (cadr c))
           "\t"
           vl
       ) ;_  end strcat
       file
   ) ;_  end write-line
   ) ;_  end repeat
   (close file)
   (princ)
) ;_  end defun

Link to comment
Share on other sites

LeeMac,

Here is another way to approach the routine.

Note that only text in the current space are used.

(defun c:PO2TXT (/ ss file fn)
 (if
   (and
     (setq file (getfiled "Specify Output File" "c:/" "txt" 1))
     (setq ss (ssget "X" (list (cons 0 "TEXT,MTEXT")(cons 410 (getvar "ctab")))))
     (setq fn (open file "W"))
   )
    (progn
      (mapcar
        '(lambda (ent)
           (print (cdr (assoc 10 (entget ent))) fn)
           (princ (strcat "\t" (cdr (assoc 1 (entget ent)))) fn)
         )
        (mapcar 'cadr (ssnamex ss))
      )
      (close fn)
    )
 )
 (princ)
) ;_  end defun

Link to comment
Share on other sites

Thanks for your help and advice CAB, I notice that you like to use the lambda function and also ssnamex - I saw them in your other routine with min, max and average :P

 

I realise I did not specify the current tab, but is this necessary?

 

But could you help me to understand the following please:

 

        '(lambda (ent)
           (print (cdr (assoc 10 (entget ent))) fn)
           ([b][color=Red]princ[/color][/b] (strcat "\t" (cdr (assoc 1 (entget ent)))) fn) 
         )

 

Should the highlighted be "print"? Also, I notice that you use the "ent" argument in the lambda function, do you input this argument using the ssnamex? and if so, how is ssnamex used? I tried to use it on a selection set and found it didn't return much that is of any use...

 

Thanks for your help.

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