Jump to content

Lisp: extract the 'contents' of simplenotes to CSV


Sajim

Recommended Posts

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.

Link to comment
Share on other sites

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 by devitg
add
Link to comment
Share on other sites

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 by Sajim
Correction
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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:

image.thumb.png.8fca6c431ce5ada99d9371a483ea6384.png 

 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.

image.thumb.png.08c88895c074f5cb6b31fe14fa038c5c.png

 

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

image.png

Link to comment
Share on other sites

 

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

 

 

  • Thanks 1
Link to comment
Share on other sites

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.

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