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

0 Members and 1 Guest are viewing this topic.

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