TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Mark on July 01, 2004, 11:15:56 AM

Title: Storing notes in a dwg
Post by: Mark 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
Title: Storing notes in a dwg
Post by: hendie 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
Title: Storing notes in a dwg
Post by: Mark 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
Title: Storing notes in a dwg
Post by: MP 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.
Title: Storing notes in a dwg
Post by: JohnK on July 01, 2004, 11:34:44 AM
Wanna "encrypt" it? I've got that string->binary representation progy. (It converts bothways.)
Title: Storing notes in a dwg
Post by: sestes 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.
Title: Storing notes in a dwg
Post by: MP 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:
Title: Storing notes in a dwg
Post by: Mark 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:
Title: Storing notes in a dwg
Post by: MP 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.
Title: Storing notes in a dwg
Post by: Keith™ 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.
Title: Storing notes in a dwg
Post by: Mark 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.
Title: Storing notes in a dwg
Post by: MP 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. :)
Title: Storing notes in a dwg
Post by: SMadsen on July 01, 2004, 03:28:42 PM
Dicts are pretty easy to work with (http://www.afralisp.com/lisp/dict.htm). Just don't take the authors advice to ENTMOD dictionary entries (he knows nothing).
Title: Storing notes in a dwg
Post by: Mark 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!
Title: Storing notes in a dwg
Post by: Mark on July 01, 2004, 03:56:57 PM
Quote from: SMadsen
Dicts are pretty easy to work with (http://www.afralisp.com/lisp/dict.htm). 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
Title: Storing notes in a dwg
Post by: SMadsen on July 01, 2004, 04:02:15 PM
Glad if you can use it, Mark
Title: Storing notes in a dwg
Post by: Mark 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"
Title: Storing notes in a dwg
Post by: SMadsen on July 02, 2004, 08:41:00 AM
Mark, try without quoting the arg to ENTMAKEX :)
Title: Storing notes in a dwg
Post by: Mark 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")"
Title: Storing notes in a dwg
Post by: SMadsen 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
Title: Storing notes in a dwg
Post by: Mark 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))
Title: Storing notes in a dwg
Post by: Mark 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)
      )
    )
  )
Title: Storing notes in a dwg
Post by: SMadsen 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
           )
    )
  )
)
Title: Storing notes in a dwg
Post by: Mark on July 02, 2004, 11:29:46 AM
OH YEA....... thank you Mr. Madsen. :D
Title: Storing notes in a dwg
Post by: Mark on July 02, 2004, 11:32:25 AM
Code: [Select]
(cons (cons (cdar dict) (cdadr dict))
:D easy for you to say ............... whoa.
Title: Storing notes in a dwg
Post by: SMadsen 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
Title: Storing notes in a dwg
Post by: Mark 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>
Title: Storing notes in a dwg
Post by: Mark 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............
Title: Storing notes in a dwg
Post by: JohnK 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.
Title: Storing notes in a dwg
Post by: Mark 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?
Title: Storing notes in a dwg
Post by: nivuahc on July 09, 2004, 08:17:08 AM
Mine went from about 27,000K to about 28,500K with usage.

Snappy routine!  :)
Title: Storing notes in a dwg
Post by: nivuahc 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.
Title: Storing notes in a dwg
Post by: Mark 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.
Title: Storing notes in a dwg
Post by: Mark 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!
Title: Storing notes in a dwg
Post by: MSTG007 on July 13, 2004, 08:01:50 AM
NOT TO SHABBY
Title: Storing notes in a dwg
Post by: CAB 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?
Title: Storing notes in a dwg
Post by: nivuahc on July 13, 2004, 09:44:06 AM
Ditto what CAB just said ^^
Title: Storing notes in a dwg
Post by: Mark 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.
Title: Storing notes in a dwg
Post by: CAB 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.