Sajim Posted June 9, 2023 Posted June 9, 2023 Lisp to extract the 'contents' field of a group of selected simplenotes and to write them into a CSV. If there are duplicates then I want duplicate results in the CSV. The purpose is to extract a list of all the wirelabels from a wiring drawing so we can get the wirelabels printed. The wirelabels are all simplenotes and there are some with duplicates in which case we want to have a few of the same label as required. Quote
devitg Posted June 9, 2023 Posted June 9, 2023 (edited) 15 hours ago, Sajim said: Lisp to extract the 'contents' field of a group of selected simplenotes and to write them into a CSV. If there are duplicates then I want duplicate results in the CSV. The purpose is to extract a list of all the wirelabels from a wiring drawing so we can get the wirelabels printed. The wirelabels are all simplenotes and there are some with duplicates in which case we want to have a few of the same label as required. @SajimPlease upload your sample.dwg Edited June 9, 2023 by devitg add Quote
BIGAL Posted June 10, 2023 Posted June 10, 2023 Like Devitg "simplenotes" no idea what they are. Quote
Sajim Posted June 10, 2023 Author Posted June 10, 2023 (edited) Thanks for the replies. I'm sorry just away from my work PC over the weekend so can't send sample until Monday, but perhaps I can explain more. I should have mentioned I'm using Draftsight, and I believe the Simplenote is the equivalent of TEXT entity, a single line text string. In Draftsight it contains a field "contents" which holds the text string. The drawing contains a number of these notes and I want to get a list of these notes. Hope this helps. Thanks again. Edited June 10, 2023 by Sajim Correction Quote
Steven P Posted June 11, 2023 Posted June 11, 2023 1 hour ago, devitg said: @Sajim Do Draftsight support LISP? Looks like it after 2020 for premium or professional installations. This might work, put in the command line (or equivalent), then select a simplenote (entget (car (entsel "Select Simple Note") )) This might list how simplenote is made up - assuming similar to Bricscad and AutoCAD an entity is defined by dotted pairs, and from there we can work out how to extract the information I have never used Draftsight but if it can use LISP then there should be some equivalence with other CAD software Quote
Sajim Posted June 11, 2023 Author Posted June 11, 2023 Thanks much for the responses. Draftsight Premium does sup1235 Pneumatic Circuits-Labels.dwgport LISP. I think it is very similar to AutoCAD just different names for entities I suppose. I've attached the drawing which consists of a number of text entities (simplenotes). @Steven P I tried the entget suggestion and just got a Note inserted as below: This is a 'Note' which is a Mtext equivalent - multiline text. The notes I'm aiming for are SimpleNotes. A screen shot of the properties below and the contents field I'm trying to extract. I asked friend ChatGPT to make a lisp and it came up with this: simplenotes-to-csv.lsp (defun c:simplenotes-to-csv () (setq selection (ssget)) (if selection (progn (setq output-file (getfiled "Save CSV File" "" "csv" 1)) (setq output-string "Contents\n") (setq note-count 0) (repeat (sslength selection) (setq entity (ssname selection 0)) (setq selection (ssdel entity selection)) (if (eq (cdr (assoc 0 (entget entity))) "SIMPLENOTE") (progn (setq note-count (+ note-count 1)) (setq contents (cdr (assoc 1 (entget entity)))) (setq output-string (strcat output-string contents "\n")) ) ) ) (setq output-string (strcat output-string "\nTotal Notes: " (itoa note-count))) (setq output-file (open output-file "w")) (write-line output-string output-file) (close output-file) (princ "CSV file created successfully.") ) (princ "No Simplenotes found in the selection.") ) (princ) ) Quite impressive that it could prompt for selecting entites etc. But the CSV was empty unfortunately. ChatGPT (0) - Humans (TBC) Quote
BIGAL Posted June 11, 2023 Posted June 11, 2023 This is how I would approach, just the way I like to do it rather than using ssdel (setq selection (ssget (list (cons 0 "TEXT")))) this will only pick "Simplenotes" ie Text. (setq selection (ssget (list (cons 0 "*TEXT")))) should pick Text & Mtext. (setq selection (ssget (list (cons 0 "*TEXT")(cons 8 "Yourlayer")))) should pick Text & Mtext by layer. (if (= selection nil) (alert "no objects selected") (repeat (setq x (sslength selection)) (setq txt (cdr (assoc 1 (ssname selection (setq x (1- x)))))) ..... write to file ) ; end repeat Does this work in Drafsight, should return something like this. #<VLA-OBJECT _Application 000000002CA7D018> this would mean can write to Excel direct no need for a csv. (princ (vlax-get-or-create-object "excel.Application")) 1 Quote
Sajim Posted June 12, 2023 Author Posted June 12, 2023 Eureka! Many thanks BigAl, what you suggested works perfectly. LISP below. simplenotes-to-csv2.lsp Quote
BIGAL Posted June 12, 2023 Posted June 12, 2023 Did you see if you could open an application ? If its supported can write to Excel direct. Application should support Word and Access database also. 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.