nil28 Posted March 19 Posted March 19 I am looking a program to copy multiple texts and making a list of those selected text in same sequence to paste in excel sheet. But need each text 2 times. E.g. in below image several texts are available. Need list like below. So 1st user need to provide input as a table title. That text will come (with prefix and suffix "##") 1st in list. After that whichever text user will select will come twice in same sequence below the table title. I need this list to paste in any excel sheet. Please someone help. Quote
Steven P Posted March 19 Posted March 19 So you can use a selection set, (ssget) to select the text items, perhaps apply a filter to only select text: (setq MySS (ssget '((0 . "*TEXT")))) You could loop through the length of the selection set, use (sslength MySS) perhaps to get the length: (setq acount 0) (while (< acount (sslength MySS)) ;; Do Stuff here ;; (setq acount (+ acount 1)) ) ; end while and you can get the text from each entity perhaps like this: (setq MyEnt (ssname MySS acount)) (setq MyText (cdr (assoc 1 (entget MyEnt) ))) (princ MyText) with that going into ;;Do stuff here ;; and of course you could make a list of 'mytext's as you go to make a list of the texts: Create an empty list at the start of the LISP before the while loop: (setq MyList (list)) and append the text into it, remembering that the text should be a list item: This part replaces the (princ MyText) (setq MyList (append MyList (list Mytext))) (setq MyList (append MyList (list Mytext))) done twice.. for 2 texts. Then all you need is google to search for "AutoCAD LISP list to CSV file" or "AutoCAD LISP List to Excel", something like that for the last part Quote
BIGAL Posted March 20 Posted March 20 (edited) Can write direct to excel. As you pick text puts value into Excel twice a bit odd request but not a problem. Try this asks for label then text use Enter to exit note need 2 enters to exit totally. ; simple text to Excel ; By AlanH March 2024 (defun c:wow ( / col txt) ;; Thanks to fixo ;; ;; = Set Excel cell text = ;; ;; ;; (defun xlsetcelltext ( row column text) (setq cells (vlax-get-property (vlax-get-property myxl "ActiveSheet") "Cells")) (vl-catch-all-apply 'vlax-put-property (list cells 'Item row column (vlax-make-variant (vl-princ-to-string text) vlax-vbstring))) ) (if (= myxl nil) (setq myxl (vlax-get-object "Excel.Application")) ) (if (= myxl nil) (progn (setq myxl (vlax-get-or-create-object "Excel.Application")) (vla-put-visible myXL :vlax-true) (vlax-put-property myxl 'ScreenUpdating :vlax-true) (vlax-put-property myXL 'DisplayAlerts :vlax-true) (vlax-invoke-method (vlax-get-property myXL 'WorkBooks) 'Add) ) (princ "Excel open") ) (if (= row nil)(setq row 1)) (while (/= (setq txt (getstring "\nEnter new label Press Enter to exit " T)) "") (xlsetcelltext row 1 txt) (setq row (1+ row)) (while (setq txt (entsel "\nPick a text or Enter to exit ")) (setq txt (cdr (assoc 1 (entget (car txt))))) (xlsetcelltext row 1 txt) (setq row (1+ row)) (xlsetcelltext row 1 txt) (setq row (1+ row)) ) ) ; (if (not (vlax-object-released-p myXL))(progn(vlax-release-object myXL)(setq myXL nil))) (princ) ) Edited March 22 by BIGAL 1 Quote
robierzo Posted March 20 Posted March 20 Hello Bigal. The app only works the first time you run it. The second time, it doesn't work anymore. Quote
BIGAL Posted March 20 Posted March 20 (edited) Ok its to do with the check is Excel open. I wrote it to do what you have currently in a dwg, so can do multiple groups of text. You can not currently stop and start that is a very different modification to the code to allow stop start. I can maybe do a quick fix will have a think. When you stop have to save the row number and so on, the other problem is close the dwg and Excel, open the dwg and add more data to the reopened excel file. A lot more steps needed as multiple scenarios. Edited March 20 by BIGAL 1 Quote
nil28 Posted March 22 Author Posted March 22 Hi BIGAL, thanks for your help! Macro is fulfilling the requirement. But I dont want to create a new Excel workbook. I have my excel template which is already open. So I just want a list which I will paste in my already open Excel sheet. Also, as mentioned by robierzo, it works only 1st time, next time it is working. So I need to perform this macro multiple times in same drawings. Every time I will paste manually in already open in my Excel sheet. Quote
BIGAL Posted March 22 Posted March 22 (edited) The problem is centered around wether an Excel is open or not will do some more testing. Edited March 22 by BIGAL 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.