Author Topic: Dictionaries and Xrecords ...  (Read 7375 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Dictionaries and Xrecords ...
« on: May 02, 2005, 08:15:39 PM »
Ths has probably been covered ad nauseum, but a colleague asked if I'd show him how to do this so I penned this quick ...

GetOrAddDict

Code: [Select]
(defun GetOrAddDict ( parentDict dictName )

    ;;  no error checking in the interests of speed,
    ;;  caller responsible for ensuring appropriate
    ;;  data is passed

    (cond
        (   (cdr
                (assoc -1
                    (dictsearch
                        parentDict
                        dictName
                    )
                )
            )    
        )
        (   (dictadd parentDict dictName
                (entmakex
                   '(   (0 . "DICTIONARY")
                        (100 . "AcDbDictionary")
                    )
                )
            )
        )    
    )
)

AddOrReplaceXrec

Code: [Select]
(defun AddOrReplaceXrec ( parentDict xrecName xrecData / xrec )

    ;;  no error checking in the interests of speed,
    ;;  caller responsible for ensuring appropriate
    ;;  data is passed

    (if
        (setq xrec
            (dictsearch
                parentDict
                xrecName
            )
        )
        (entdel
            (cdr
                (assoc -1 xrec)
            )
        )
    )
   
    (dictadd
        parentDict
        xrecName
        (entmakex
            (append    
               '(   (0 . "XRECORD")
                    (100 . "AcDbXrecord")
                )
                xrecData
            )
        )
    )
)

c:Test

Code: [Select]
(defun c:test ( / dict1 dict2 xrec1 xrec2 )

    ;;  dict1 is child of primary dictionary

    (setq dict1
        (GetOrAddDict
            (namedobjdict)
            "MyDictionary1"
        )
    )
   
    ;;  dict2 is a child of dict1
   
    (setq dict2
        (GetOrAddDict
            dict1
            "MyDictionary2"
        )
    )
   
    ;;  add xrec to dict1
   
    (setq xrec1
        (AddOrReplaceXrec
            dict1
            "MyXrecord1"
           '(   (1 . "KOOL")
                (10 0.0 0.0 0.0)
                (70 . 42)
            )
        )
    )
   
    ;;  add xrec to dict2
   
    (setq xrec2
        (AddOrReplaceXrec
            dict2
            "MyXrecord2"
           '(   (1 . "KOOL")
                (10 0.0 0.0 0.0)
                (70 . 42)
            )
        )
    )

    ;;  show what we made ...
   
    (mapcar
       '(lambda (ename)
            (princ (strcat (chr 40) "\n"))
            (foreach pair (entget (eval ename))
                (princ "    ")
                (princ pair)
                (princ "\n")
            )
            (princ (strcat (chr 41) "\n\n"))
        )
       '(
            dict1
            dict2
            xrec1
            xrec2
        )
    )    
   
    (princ)
   
)

Running c:Test might produce something like this ...

Code: [Select]
(
    (-1 . <Entity name: 4007ce50>)
    (0 . DICTIONARY)
    (5 . 72)
    (102 . {ACAD_REACTORS)
    (330 . <Entity name: 4007cc60>)
    (102 . })
    (330 . <Entity name: 4007cc60>)
    (100 . AcDbDictionary)
    (280 . 0)
    (281 . 1)
    (3 . MyDictionary2)
    (350 . <Entity name: 4007ce58>)
    (3 . MyXrecord1)
    (350 . <Entity name: 4007ce60>)
)

(
    (-1 . <Entity name: 4007ce58>)
    (0 . DICTIONARY)
    (5 . 73)
    (102 . {ACAD_REACTORS)
    (330 . <Entity name: 4007ce50>)
    (102 . })
    (330 . <Entity name: 4007ce50>)
    (100 . AcDbDictionary)
    (280 . 0)
    (281 . 1)
    (3 . MyXrecord2)
    (350 . <Entity name: 4007ce68>)
)

(
    (-1 . <Entity name: 4007ce60>)
    (0 . XRECORD)
    (5 . 74)
    (102 . {ACAD_REACTORS)
    (330 . <Entity name: 4007ce50>)
    (102 . })
    (330 . <Entity name: 4007ce50>)
    (100 . AcDbXrecord)
    (280 . 1)
    (1 . KOOL)
    (10 0.0 0.0 0.0)
    (70 . 42)
)

(
    (-1 . <Entity name: 4007ce68>)
    (0 . XRECORD)
    (5 . 75)
    (102 . {ACAD_REACTORS)
    (330 . <Entity name: 4007ce58>)
    (102 . })
    (330 . <Entity name: 4007ce58>)
    (100 . AcDbXrecord)
    (280 . 1)
    (1 . KOOL)
    (10 0.0 0.0 0.0)
    (70 . 42)
)

For what its worth thought I'd share it here.

Cheers.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

daron

  • Guest
Dictionaries and Xrecords ...
« Reply #1 on: May 03, 2005, 08:06:49 AM »
It's worth a lot. Added to Favorites. Thanks.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Dictionaries and Xrecords ...
« Reply #2 on: May 03, 2005, 08:09:23 AM »
Thanks Daron. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Dictionaries and Xrecords ...
« Reply #3 on: May 03, 2005, 08:14:01 AM »
Thanks a bunch MP, that's good stuff.

wish I had time to use it right now ...
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Dictionaries and Xrecords ...
« Reply #4 on: May 03, 2005, 08:17:28 AM »
My pleasure Mr. T.

It will wait patiently for you.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

daron

  • Guest
Dictionaries and Xrecords ...
« Reply #5 on: May 03, 2005, 08:19:01 AM »
Mr. T??? Now I have a different visual of Mark with an AFRO and gold chains and calling everyone a pitiful fool. hehehehe.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Dictionaries and Xrecords ...
« Reply #6 on: May 03, 2005, 08:24:29 AM »
Sounds like a photoshop challenge to me.

Where's craig?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

daron

  • Guest
Dictionaries and Xrecords ...
« Reply #7 on: May 03, 2005, 08:29:14 AM »
Got any pictures of Mr. T? I know where to find some of Mark.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Dictionaries and Xrecords ...
« Reply #8 on: May 03, 2005, 01:11:07 PM »
Quote from: MP
Sounds like a photoshop challenge to me.


Oh please no ... not Mr T. aaahhhh ..... :)
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Dictionaries and Xrecords ...
« Reply #9 on: May 03, 2005, 01:45:00 PM »
Michael,
Very nice of you to share your knowledge.
I'd love to dive into this but it will have to wait as my free time is gone for awhile.
I reserve the right to as questions later. :)

Thanks

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

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Dictionaries and Xrecords ...
« Reply #10 on: May 03, 2005, 02:02:58 PM »
No worries Alan, as long as I'm around it's my pleasure to share the few bits I claim to remotely understand.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

SMadsen

  • Guest
Dictionaries and Xrecords ...
« Reply #11 on: May 03, 2005, 05:02:09 PM »
Quote from: Mark Thomas
Quote from: MP
Sounds like a photoshop challenge to me.


Oh please no ... not Mr T. aaahhhh ..... :)

No Mr. T? How'bout this then?

Sorry Mark, couldn't help it!!

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Dictionaries and Xrecords ...
« Reply #12 on: May 03, 2005, 05:07:14 PM »
I scared to look .... :)
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Dictionaries and Xrecords ...
« Reply #13 on: May 03, 2005, 05:08:41 PM »
I was after I looked. :shock:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Dictionaries and Xrecords ...
« Reply #14 on: May 03, 2005, 06:32:08 PM »
:shock: EXACTLY
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.