TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MP 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
(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
(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
(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 ...
(
(-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.
:)
-
It's worth a lot. Added to Favorites. Thanks.
-
Thanks Daron. :)
-
Thanks a bunch MP, that's good stuff.
wish I had time to use it right now ...
-
My pleasure Mr. T.
It will wait patiently for you.
:)
-
Mr. T??? Now I have a different visual of Mark with an AFRO and gold chains and calling everyone a pitiful fool. hehehehe.
-
Sounds like a photoshop challenge to me.
Where's craig?
-
Got any pictures of Mr. T? I know where to find some of Mark.
-
Sounds like a photoshop challenge to me.
Oh please no ... not Mr T. aaahhhh ..... :)
-
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
-
No worries Alan, as long as I'm around it's my pleasure to share the few bits I claim to remotely understand.
:)
-
Sounds like a photoshop challenge to me.
Oh please no ... not Mr T. aaahhhh ..... :)
No Mr. T? How'bout this (http://www.theswamp.org/lilly_pond/smadsen/mark-photo3.jpg?nossi=1) then?
Sorry Mark, couldn't help it!!
-
I scared to look .... :)
-
I was after I looked. :shock:
-
:shock: EXACTLY