Author Topic: Storing notes in a dwg  (Read 12878 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« on: July 01, 2004, 11:15:56 AM »
I'm looking for some ideas. I want to store notes in a dwg that are not seen by everyone who opens the file. Perhaps xdata?

thanks
TheSwamp.org  (serving the CAD community since 2003)

hendie

  • Guest
Storing notes in a dwg
« Reply #1 on: July 01, 2004, 11:17:50 AM »
depends upon how why and what you want to do with it. It could be something as simple as text.visible=false
xdata's good though

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #2 on: July 01, 2004, 11:24:19 AM »
Quote from: hendie
depends upon how why and what you want to do with it. It could be something as simple as text.visible=false
xdata's good though

I want something a little more than "text.visible=false" if possible. I realize I'll probably have to write an interface for it, what ever it is!

I want to mainly track changes and what not.

thanks hendie
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Storing notes in a dwg
« Reply #3 on: July 01, 2004, 11:30:01 AM »
I've been thinking of a similar thing for awhile, though it would be available to the user: a tree of notes that reside in dictionary type structure, with an appropriate interface to save, edit, delete, move ...

Anyway, not to derail you Mark ... consider using dictionaries (which sport higher capacities than xdata). If you need to have the data associated w/entites, link the entites to the dictinary by their xdata, otherwise the dictionar(s) can stand on their own.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10633
Storing notes in a dwg
« Reply #4 on: July 01, 2004, 11:34:44 AM »
Wanna "encrypt" it? I've got that string->binary representation progy. (It converts bothways.)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

sestes

  • Guest
Storing notes in a dwg
« Reply #5 on: July 01, 2004, 11:37:24 AM »
Quote from: MP
I've been thinking of a similar thing for awhile, though it would be available to the user: a tree of notes that reside in dictionary type structure, with an appropriate interface to save, edit, delete, move ...


That sounds great!  I could defiantly benefit from something like this.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Storing notes in a dwg
« Reply #6 on: July 01, 2004, 11:40:46 AM »
Quote from: sestes
That sounds great!  I could defiantly benefit from something like this.

Oops, didn't mean to hijack this thread! :oops:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #7 on: July 01, 2004, 11:46:09 AM »
Quote from: MP
I've been thinking of a similar thing for awhile, though it would be available to the user: a tree of notes that reside in dictionary type structure, with an appropriate interface to save, edit, delete, move ...

Anyway, not to derail you Mark ... consider using dictionaries (which sport higher capacities than xdata). If you need to have the data associated w/entites, link the entites to the dictinary by their xdata, otherwise the dictionar(s) can stand on their own.


something like this?
 create new dictionary in collection using the Add method
 add a new XRecord to the dictionary using AddXRecord
 at this point I'm still reading ......   :roll:
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Storing notes in a dwg
« Reply #8 on: July 01, 2004, 11:49:55 AM »
Quote from: Mark Thomas
something like this?
create new dictionary in collection using the Add method
add a new XRecord to the dictionary using AddXRecord
...

Yep, pretty much. Make sure you make the dictionary and it's entries are hard owned (dxf 280 or 281 I believe). That way they'll survive purges, wblocking etc.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Storing notes in a dwg
« Reply #9 on: July 01, 2004, 12:41:05 PM »
xdata would be attached to an object and as such if the object were deleted the data would be lost, other options include ldata and dictionaries.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #10 on: July 01, 2004, 12:58:47 PM »
So it looks like a dictionary is the way to go from what I've read. Correct me if I'm wrong, but it appears you can store most anything in an XRecord, namely text.
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Storing notes in a dwg
« Reply #11 on: July 01, 2004, 01:05:42 PM »
Quote from: Mark Thomas
So it looks like a dictionary is the way to go from what I've read. Correct me if I'm wrong, but it appears you can store most anything in an XRecord, namely text.

Most anything yes, without the 16K xdata ceiling, as well as the ability to be entity agnostic. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

SMadsen

  • Guest
Storing notes in a dwg
« Reply #12 on: July 01, 2004, 03:28:42 PM »
Dicts are pretty easy to work with. Just don't take the authors advice to ENTMOD dictionary entries (he knows nothing).

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #13 on: July 01, 2004, 03:37:10 PM »
thanks so much Stig, I knew should have looked over there.......... David Stein also has a bit about them in his book, so I've got some reading to do!
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #14 on: July 01, 2004, 03:56:57 PM »
Quote from: SMadsen
Dicts are pretty easy to work with. Just don't take the authors advice to ENTMOD dictionary entries (he knows nothing).

O........M.............G Where have I been!! Stig, that is great stuff. I know what I'm doing in the morning. :D
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Storing notes in a dwg
« Reply #15 on: July 01, 2004, 04:02:15 PM »
Glad if you can use it, Mark

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #16 on: July 02, 2004, 08:32:20 AM »
OK...... I'm stuck! Using your example Stig, I get "error: bad DXF group: (CONS 300 DATE)" in the following code. What am i missing?
Code: [Select]

(setq date (rtos (getvar 'cdate) 2 4))
(setq note (getstring T "\nEnter note: "))
        (setq anXrec (entmakex '((0 . "XRECORD")
                                (100 . "AcDbXrecord")
                                (cons 300 date)
                                (cons 301 note)
                                )
                     )
        )


the DXF group codes state
Quote
1–369 (except 5 and 105)
 These values can be used by an application in any way

that is under "Object" -> "XRECORD"
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Storing notes in a dwg
« Reply #17 on: July 02, 2004, 08:41:00 AM »
Mark, try without quoting the arg to ENTMAKEX :)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #18 on: July 02, 2004, 08:52:51 AM »
you mean like this;
Code: [Select]

(setq anXrec (entmakex ((0 . "XRECORD")
                                (100 . "AcDbXrecord")
                                (cons 300 date)
                                (cons 301 note)
                                )
                     )
        )


I get "error: bad syntax of function call: (0 . "XRECORD")"
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Storing notes in a dwg
« Reply #19 on: July 02, 2004, 09:32:59 AM »
No no, ...  (list '(0 . "XRECORD")....(cons 300 date)..etc..)

In the example on Afralisp, I only used hardcoded values and could therefore quote the entire list. You are evaluating some of the values so you need to build the list with LIST

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #20 on: July 02, 2004, 09:41:52 AM »
thanks Stig. I just got this to work before I read you post. It seems to work :?
Code: [Select]

(setq date (rtos (getvar 'cdate) 2 4))
(setq note (getstring T "\nEnter note: "))
(setq lst
  (list '(0 . "XRECORD")
'(100 . "AcDbXrecord")
(cons 300 date)
(cons 301 note)
)
 )
        (setq anXrec (entmakex lst))
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #21 on: July 02, 2004, 11:21:42 AM »
OK, this is what I have thus far. It will create a dictionary named NOTES_DICT then store xrecords incremented by one starting at one. I haven't got to the reading part yet. :-\  

comments .......... please!
Code: [Select]

(defun get-or-create-Dict (/ adict)

  (if (not (setq adict (dictsearch (namedobjdict) "NOTES_DICT")))
    (progn
      (setq adict (entmakex '((0 . "DICTIONARY")(100 . "AcDbDictionary"))))
      (if adict (setq adict (dictadd (namedobjdict) "NOTES_DICT" adict)))
      )
    (setq adict (cdr (assoc -1 adict)))
    )
  )

(defun get-next-record (/ adict rec cntr)
  (setq adict (get-or-create-Dict)
cntr  "1"
)

  (if (dictsearch adict cntr)
    (while (setq rec (dictsearch adict cntr))
  (setq cntr (itoa (1+ (atoi cntr))))
  )
    )
  cntr
  )

(defun get-or-make-Xrecord (date note cnt / adict date note anXrec)
  (cond
    ((setq adict (get-or-create-Dict))
     (cond
       ((not (setq anXrec (dictsearch adict cnt)))
(setq anXrec
     (entmakex
(list
 '(0 . "XRECORD")
 '(100 . "AcDbXrecord")
 (cons 300 date)
 (cons 301 note)
 )
)
     )
(if anXrec (setq anXrec (dictadd adict cnt anXrec)))
)
       (setq anXrec (cdr (assoc -1 (dictsearch adict cnt))))
       )
     )
    )
  )

(defun add-rec (/ date note recnum)
  (setq date (rtos (getvar 'cdate) 2 4))

  (if (setq note (getstring T "\nEnter note: "))
    (if (setq recnum (get-next-record))
      (get-or-make-Xrecord date note recnum)
      )
    )
  )
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Storing notes in a dwg
« Reply #22 on: July 02, 2004, 11:27:52 AM »
Excellent :)

I was just putting together some functions you might use but seems you've covered it already. Now that they're already written I might as well post them, though.

Code: [Select]
(defun get-or-create-Dict (name / myDict dict)
  (setq myDict (dictsearch (namedobjdict) name))
  (or (setq myDict (cdr (assoc -1 myDict)))
      (and (setq dict '((0 . "DICTIONARY") (100 . "AcDbDictionary")))
           (setq myDict (entmakex dict))
           (setq myDict (dictadd (namedobjdict) name myDict))
      )
  )
  myDict
)

(defun create-xNote (date txt xname / myDict xdat xrec)
  (and (setq myDict (get-or-create-Dict "MARK_NOTES"))
       (not (dictsearch myDict xname))
       (setq xdat (list '(0 . "XRECORD")
                        '(100 . "AcDbXrecord")
                        (cons 300 date)
                        (cons 301 txt)
                  )
       )
       (setq xrec (dictadd myDict xname (entmakex xdat)))
  )
  xrec
)

(defun get-all-xNotes (/ xnote myDict xnotes)
  (and (setq myDict (get-or-create-Dict "MARK_NOTES"))
       (while (setq xnote (dictnext myDict (not xnote)))
         (setq xnotes (cons xnote xnotes))
       )
  )
  xnotes
)

(defun get-all-xNames (/ myDict dict xnames)
  (and (setq myDict (get-or-create-Dict "MARK_NOTES"))
       (setq dict (entget myDict))
       (while (setq dict (member (assoc 3 dict) dict))
         (setq xnames (cons (cons (cdar dict) (cdadr dict)) xnames)
               dict   (cdr dict)
         )
       )
  )
  xnames
)

(defun parse-all-xNotes (/ xnotes xrec)
  (foreach n (get-all-xNames)
    (setq xrec (entget (cdr n)))
    (setq xnotes (cons
             (list (cons 2 (car n)) (assoc 300 xrec) (assoc 301 xrec))
             xnotes
           )
    )
  )
)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #23 on: July 02, 2004, 11:29:46 AM »
OH YEA....... thank you Mr. Madsen. :D
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #24 on: July 02, 2004, 11:32:25 AM »
Code: [Select]
(cons (cons (cdar dict) (cdadr dict))
:D easy for you to say ............... whoa.
TheSwamp.org  (serving the CAD community since 2003)

SMadsen

  • Guest
Storing notes in a dwg
« Reply #25 on: July 02, 2004, 11:37:07 AM »
LOL

(cons (cdr (car dict))(cdr (cadr dict))) .. is that better?

(setq cntr (itoa (1+ (atoi cntr)))) ??

^You should talk! heh

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #26 on: July 02, 2004, 11:45:42 AM »
>(cons (cdr (car dict))(cdr (cadr dict))) .. is that better?
much better, I can actually understand that. <g>
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #27 on: July 02, 2004, 11:49:01 AM »
Quote from: Se7en
Wanna "encrypt" it? I've got that string->binary representation progy. (It converts bothways.)


break it out man............
TheSwamp.org  (serving the CAD community since 2003)

JohnK

  • Administrator
  • Seagull
  • Posts: 10633
Storing notes in a dwg
« Reply #28 on: July 02, 2004, 12:06:41 PM »
Your ready already hugh? Alright, let me see if i can locate the right version. (I did it before i started using the new dir strusture and well i got crap all over the place since i moved all the files into the new struct. :lol:)

Ill get on it and post it.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #29 on: July 09, 2004, 07:27:25 AM »
this is a very rough version, but it works.
http://www.theswamp.org/swamp.files/mark/xNotes.lsp

I noticed when I ran this routine my cpu usage went up about 50% for the acad.exe until I saved the dwg. Could someone verify this?
TheSwamp.org  (serving the CAD community since 2003)

nivuahc

  • Guest
Storing notes in a dwg
« Reply #30 on: July 09, 2004, 08:17:08 AM »
Mine went from about 27,000K to about 28,500K with usage.

Snappy routine!  :)

nivuahc

  • Guest
Storing notes in a dwg
« Reply #31 on: July 09, 2004, 08:42:30 AM »
Mark, the terminology on the command line is a bit confusing. I'm used to seeing something like

Quote
Specify start point of text or [Justify/Style]:


Yours says

Quote
Read / Write xNotes [Add View]:


When I first ran it I typed W to write a note... perhaps it would be better presented like this:

Quote
Read and write xNotes for this drawing [Add/View]:


Or something like that with the default being Add if the user should press enter.

Just a suggestion.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #32 on: July 09, 2004, 08:55:40 AM »
good point. I just through that in there for a test, I want to make _one_ dialog box for the whole thing.
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #33 on: July 13, 2004, 07:42:27 AM »
new version. one dialog box. start with 'myxnotes'

http://www.theswamp.org/swamp.files/mark/MyxNotes.lsp

the code is still messy!
TheSwamp.org  (serving the CAD community since 2003)

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Storing notes in a dwg
« Reply #34 on: July 13, 2004, 08:01:50 AM »
NOT TO SHABBY
Civil3D 2020

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Storing notes in a dwg
« Reply #35 on: July 13, 2004, 09:26:10 AM »
Neat-o Mark,
Just tried it out.
One thing, when you type a long note the note scrolls in the entry window
but when you retrieve the notes the note in the view window doesn't wrap.
Did you have plans to high lite the existing note and have it appear in the
entry window so you can edit & or view the entire note?
I've reached the age where the happy hour is a nap. (°Ώ°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

nivuahc

  • Guest
Storing notes in a dwg
« Reply #36 on: July 13, 2004, 09:44:06 AM »
Ditto what CAB just said ^^

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Storing notes in a dwg
« Reply #37 on: July 13, 2004, 10:40:18 AM »
Quote from: CAB
Neat-o Mark,
Just tried it out.
One thing, when you type a long note the note scrolls in the entry window
but when you retrieve the notes the note in the view window doesn't wrap.
Did you have plans to high lite the existing note and have it appear in the
entry window so you can edit & or view the entire note?

haven't got that far yet! good idea though. right now if you just select an existing note and click OK it will print to the command line.
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Storing notes in a dwg
« Reply #38 on: July 13, 2004, 11:14:47 AM »
Something like this? I'm sure you can do better.
It messed up your return string at the command line though.

Code: [Select]
 (defun build-xnotes-lst (lst / notes_lst notes)
    (foreach item lst
      (setq notes (cdr (assoc 301 item)))
      (setq notes_lst
             (append
               (list
                 (strcat
                   (cdr (assoc 2 item))
                   "  "
                   (cdr (assoc 300 item))
                   "  "
                   (substr notes 1 40)
                 )
               )
               notes_lst
             )
      ); set
      (if (> (strlen notes) 40)
        (progn
          (setq idx 41)
          (while (< idx (strlen notes))
            (setq notes_lst
             (append
               (list
                 (strcat
                   "                  "
                   (substr notes idx 40)
                 )
               )
               notes_lst
             )
           ); set
           (setq idx (+ idx 40))
          ); while
        )        
      ); endif
   
    ); foreach
    (reverse notes_lst)
  )


PS i know you are buisy, so don't mess with this now, if you are Swamped. 8)
Couldn't resist.
I've reached the age where the happy hour is a nap. (°Ώ°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.