Jump to content

Exporting selected text to Excel Cell


CafeJr

Recommended Posts

:? Guys,

 

 

I need one help, someone knows one Lisp that I can get Texts (words) on AutoCad and export it in order of selection to a cell on Excel...

 

 

Eg.: If I have 10 words, as I'll selecting it and when finished these then words will be exported to a cell (could be cels) to Excel.

 

 

Thanks in advance...

Link to comment
Share on other sites

Can you explain your goal with an example ?

Are you wanting to select one by one to keep them in the same order exported to Excel ?

 

In these picture In trying to clarify the task.

 

Tharwat, the selection is one by one, because I have a Big drawing with a lot of information, and I need to follow the names and select it to export by selection order. To show the example I put A and B, but it's only to exemplify, not is necessary to work with two collumns or two line of cells, only get the words and export it to Excel in order of selection, it will help a lot.

Text exported by order selection to Excel.jpg

Edited by CafeJr
Link to comment
Share on other sites

Your request is two parts, actually writing to excel is the easy bit and thinking about provide you always use A C C etc it can be done.

 

Thinking about it now if you just make a list of text (A-1 B-1 B-3 A-2 ETC ) You can take 1st character and check if its A B C D etc and set column (asc(text)) last number A-23 = 23+row offset = cell row so if some missing will jump over blanks. B-23 = cell 2,27

 

Thanks to Lee-mac for this it will give a number as an answer.

; use say nth of your list of text selected (setq nthtext (nth x testlist))
; to use (setq cellnum (Lm:parsenumbers nthtext))

;;-------------------=={ Parse Numbers }==--------------------;;
;;                                                            ;;
;;  Parses a list of numerical values from a supplied string. ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  s - String to process                                     ;;
;;------------------------------------------------------------;;
;;  Returns:  List of numerical values found in string.       ;;
;;------------------------------------------------------------;;

(defun LM:ParseNumbers ( s )
 (
   (lambda ( l )
     (read
       (strcat "("
         (vl-list->string
           (mapcar
             (function
               (lambda ( a b c )
                 (if
                   (or
                     (< 47 b 58)
                     (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                     (and (= 46 b) (< 47 a 58) (< 47 c 58))
                   )
                   b 32
                 )
               )
             )
             (cons nil l) l (append (cdr l) (list nil))
           )
         )
         ")"
       )
     )
   )
   (vl-string->list s)
 )
)

Link to comment
Share on other sites

Sorry Bigal, the text at AutoCad, isn't a specific address to Excel, it's any kind of text, to be exported to Excel in "any" cell. I didn't pay attention on AutoCad text that I wrote... similar a Excel cell address...

Link to comment
Share on other sites

Getexecl.lsp it is a library of excel-autocad functions both ways.

 

 

 

Bigal, I don't know why, but I loaded the Getexcl lisp but it doesn't work, the command isn't recognized. I did it in two AutoCad softwares, 2012 and 2013 versions...

Link to comment
Share on other sites

Bigal, I don't know why, but I loaded the Getexcl lisp but it doesn't work, the command isn't recognized. I did it in two AutoCad softwares, 2012 and 2013 versions...

 

The GetExcel.lsp is a function to deal to Excel files that release after the year 2003 and which their extension files would be formatted to .xls and xlsx ... etc so this function alone does not help you with any .

 

Anyway , I have a plan to write a program with a dialog box to obtain the selected text strings before exporting them to txt format or Excel file with a format .csv . Would this be suitable for your needs ?

 

I am busy at the moment but would write it since that I think it would be handy program in general .

 

Tharwat

Link to comment
Share on other sites

Thank you Tharwat... I don't know if it's simple, but the idea is, is only collect a spread texts (words) in a drawing in order of selection... to export it to Excel.

Link to comment
Share on other sites

Thank you Tharwat... I don't know if it's simple, but the idea is, is only collect a spread texts (words) in a drawing in order of selection... to export it to Excel.

 

Try this program and let me know .

Note: At the end of selecting texts , just press enter and type ( n ) or ( no ) to display the dialog for the last process .

 

(defun c:Test  (/ *error* _dialog dlg s name s l k save path o)
;;;        Tharwat 13.01.2015        ;;
 (defun *error*  (msg)
   (if (and dlg (findfile dlg))
     (vl-file-delete dlg)
     )
   (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))
     (princ (strcat "\n** Error: " msg " **"))
     )
   (princ)
   )
 (defun _dialog  (/ id f)
   (cond
     ((not
        (and
          (setq dlg (vl-filename-mktemp nil nil ".dcl"))
          (setq f (open dlg "w"))
          (write-line
            "test : dialog {label = \"Test Strings\"; width = 40;
            : text { key = \"path\"; }
            spacer_1 ;
            : list_box { key = \"lst\"; height = 18;}
            : boxed_row {
            : button { label = \"Okay\"; key = \"oki\"; width = 12;}
            : button { label = \"Exit\"; key = \"esc\"; is_default = true; is_cancel = true; width = 12;}
            : button { label = \"Save to\"; key = \"sv\"; width = 12;}
            }}"
            f
            )
          (not (close f))
          )
        )
      (alert "Can't load the temporary file <!>")
      )
     ((or (not dlg)
          (not (> (setq id (load_dialog dlg)) 0))
          (not (new_dialog
                 "test"
                 id
                 )
               )
          )
      (princ "\n Can not load Dialog !")
      )
     (t
      (start_list "lst")
      (mapcar 'add_list (reverse l))
      (end_list)
      (mode_tile "oki" 1)
      (set_tile "lst" "0")
      (action_tile
        "sv"
        "(if (setq path (getfiled \"Save to\" (getvar 'DWGPREFIX) \"csv\" 1))
             (progn
             (set_tile \"path\" path)
             (mode_tile \"oki\" 0))
           (mode_tile \"oki\" 1))"
        )
      (action_tile
        "oki"
        "(setq save t)(done_dialog)"
        )
      (action_tile "esc" "(setq save nil)(done_dialog)")
      (start_dialog)
      (unload_dialog id)
      (vl-file-delete dlg)
      )
     )
   save
   )
 (while
   (cond
     ((and (setq s (car (entsel "\n Pick Texts :")))
           (wcmatch (cdr (assoc 0 (entget s))) "TEXT,MTEXT")
           )
      (setq l (cons (cdr (assoc 1 (entget s))) l))
      )
     ((or s (not s))
      (princ "\nInvalid Selection !! Select text ONLY ")
      (initget 6 "Yes No")
      (or (not (setq k
                      (getkword "\n Missed !! Continue [Yes/No] <Yes> :")))
          (eq k "Yes")
          )
      )
     )
   )
 (if (and l (setq save (_dialog)) (setq o (open path "w")))
   (progn
     (mapcar '(lambda (x) (write-line x o)) (reverse l))
     (close o)
     (princ "\n Well done ...")
     )
   (princ "\n Exit by User ")
   )
 (princ)
 )




Link to comment
Share on other sites

Woowwwww... He he he... Thanks Tharwat!... It Works as good as I need!!!...

 

 

The unique "delay" that I have it's work with spreadsheets (by the number of usages), I'm thinking if has a way to fill up one spreadsheet only (I don't know), or using a Ram memory to copy these texts to paste one a cell in a Excel file open... It's that possible?...

Link to comment
Share on other sites

Woowwwww... He he he... Thanks Tharwat!... It Works as good as I need!!!...

 

I am happy that you liked the program ;)

 

The unique "delay" that I have it's work with spreadsheets (by the number of usages), I'm thinking if has a way to fill up one spreadsheet only (I don't know), or using a Ram memory to copy these texts to paste one a cell in a Excel file open... It's that possible?...

 

I don't think that I got your point :unsure:

Link to comment
Share on other sites

Sorry,

 

 

Let me try to explain!...

 

 

Every time that I use it, I'll create a spreadsheet (it's ok, no problem, it's help a lot even why I need to rewrite the path on Excel!).

 

 

It'll be used to follow electrical cables on a drawing, think in one electrical installation I have one point (origin) and a target of the cable (instruments on the field), so, I have to do these follow the path texts (address of electrical pipes or cable trays) to select where the cable pass through, are many cable to do it one by one, you got it?...

Installation.jpg

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