Jump to content

Recommended Posts

Posted

When running an autolisp to export mtext it won't always grab the full string, it appears to start over after a certain number of characters or something so that the output is only the last few lines instead of the whole selected entity. The script is designed to allow the user to select multiple entities via windowed select and then export to a plain text file

 

(defun C:test ()
(progn
(setq lspdir "C:\") ;; set to directory of default txt file
(setq txtfile (strcat lspdir "test")) ;;default txt file
(setq FP (open (getfiled "Write out text file." txtfile "txt" 11) "a"))
;;dialogue box to pick file to create or append
(setq I 0)
(setq S (ssget))
(setq L (Sslength S))
(repeat L
(setq EN (Ssname S I))
(setq EL (Entget EN))
(setq TEXT (Cdr (Assoc 1 EL)))
(princ (strlen TEXT))
(write-line TEXT FP)
(setq I (+ 1 I)))
(close FP)));

text.dwg

Posted

well figured out the above problem, apparently some of the text was being stored on group 3 as well, modifying my above code to add this

(setq TEXT (Cdr (Assoc 3 EL)))
(setq TEXT2 (Cdr (Assoc 1 EL)))
(setq TEXT (strcat TEXT TEXT2))

now works, however i was wondering if there was an easy way to scan the entity looking for a group/assoc containing mtext?

Posted

If the Mtext has more than 250 characters, then the string is stored in group 3.

 

I would include a few IF statements to check that the file has been selected - and also a SelectionSet filter to filter for MTEXT only.

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:test [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] ss file[b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=#009900]0[/color][/b] . [b][color=#ff00ff]"MTEXT"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
          [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] file [b][color=RED]([/color][/b][b][color=BLUE]getfiled[/color][/b] [b][color=#ff00ff]"Output File"[/color][/b] [b][color=#ff00ff]""[/color][/b] [b][color=#ff00ff]"txt"[/color][/b] [b][color=#009900]9[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
   [b][color=RED]([/color][/b][b][color=BLUE]progn[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] file [b][color=RED]([/color][/b][b][color=BLUE]open[/color][/b] file [b][color=#ff00ff]"a"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]function[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b]x[b][color=RED])[/color][/b]
           [b][color=RED]([/color][/b][b][color=BLUE]write-line[/color][/b] x file[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
       [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]vla-get-TextString[/color][/b]
         [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]vlax-ename->vla-object[/color][/b]
           [b][color=RED]([/color][/b][b][color=BLUE]vl-remove-if[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]listp[/color][/b]
             [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]cadr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]ssnamex[/color][/b] ss[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
     [b][color=RED]([/color][/b][b][color=BLUE]close[/color][/b] file[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]
 [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b]

 

Posted

Thanks for the advice, works great, although now i've run into yet another problem... the following set of entities when extracted via the window mode outputs in an odd order, instead of the order as seen on the dwg, for the most part its just in inverse order which isn't too big of a problem, however 2 lines in particular

H4c/TB18:10\PPC1-9

H4b/TS3A:13

come out completely out of order

label.dwg

Posted
Thanks for the advice, works great, although now i've run into yet another problem... the following set of entities when extracted via the window mode outputs in an odd order, instead of the order as seen on the dwg, for the most part its just in inverse order which isn't too big of a problem, however 2 lines in particular

H4c/TB18:10\PPC1-9

H4b/TS3A:13

come out completely out of order

 

A selection set collection is not sorted in any particular order, you will need to sort the collection manually :)

 

Do you just want to sort them by y-value (max->min)?

Posted

Yeah, thats exactly what i'd want, sorted by y-coordinate i suppose, from top to bottom, so min -> max or max -> min, not sure which corner autocad has as 0,0. Thanks again for the quick reply's, much appreciated, that first problem was really roadblocking further usage of the script and the second bit is definitely being an inconvenience at the moment so the y-coord sort would be great

Posted

No probs, I'm happy to help out :)

 

(defun c:test (/ ss file)
 (vl-load-com)
 (if (and (setq ss (ssget '((0 . "MTEXT"))))
          (setq file (getfiled "Output File" "" "txt" 9)))
   (progn
     (setq file (open file "a"))
     (mapcar
       (function
         (lambda (x)
           (write-line x file)))
       (vl-sort
         (mapcar 'vla-get-TextString
           (mapcar 'vlax-ename->vla-object
             (vl-remove-if 'listp
               (mapcar 'cadr (ssnamex ss)))))
         (function
           (lambda (x y)
             (> (cadr x) (cadr y))))))
     (close file)))
 (princ))

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