Jump to content

make a list of selected text


nil28

Recommended Posts

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.

 image.png.e636c2a24f24159c733d951cff673460.png image.png.7518e2a0342c3b9277fd2361a5788c58.png

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

image.png.00a55de83a3524c176af15ea48b9b87f.png

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

Hello Bigal. The app only works the first time you run it. The second time, it doesn't work anymore.

Link to comment
Share on other sites

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 by BIGAL
  • Like 1
Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

The problem is centered around wether an Excel is open or not will do some more testing. 

 

Edited by BIGAL
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...