issues with LISP-function (dictremove) in V23
We have two LISP-functions (write_var) and (read_var) which we use to store and read userdata of type STRING in our drawings. These functions work fine for many years in BricsCAD as well as in AC.
With BricsCAD V23 I get an error when rewriting a variables value.
This rewriting first deletes the old variable with (dictremove) and tries to write it again.
(dictremove) says the first argument is not of type ENAME. Analysing datatypes in the debugger, everything seems fine.
Does anyone have similar experience with (dictremove) in BCV23?
Any suggestions would be very appreciated.
Rolf
Source:
;-----------------------------------------------------------------
;Diese Funktion erstellt ein Dictionary
;-----------------------------------------------------------------
(defun get_or_create_Dict (dict / adict)
(if (not (setq adict (dictsearch (namedobjdict) dict)));test if "dict" is already present in the main dictionary
(progn ;if not present then create a new one and set the main dictionary as owner
(setq adict (entmakex '((0 . "DICTIONARY")(100 . "AcDbDictionary"))))
(if adict (setq adict (dictadd (namedobjdict) dict adict)));if succesfully created, add it to the main dictionary
); End of Progn
(progn
(setq adict (cdr (assoc -1 adict)));if present then just return its entity name
); End of Progn
); End of If
adict
); End of Function
;---------------------------------------------------------------
; Diese Funktion erzeugt eine StringVariable im Dictionary
; und ordnet ihr einen Wert zu
;---------------------------------------------------------------
(defun write_var (dict var val / adict anXrec)
(cond
((setq adict (get_or_create_Dict dict));first get dictionary. Notice that "dict" will be created here in case it doesn't exist
(cond
((not (setq anXrec (dictsearch adict var)));if "dict" is now valid then look for "var" Xrecord
(setq anXrec (entmakex (list ;if "var" was not found then create it
'(0 . "XRECORD")
'(100 . "AcDbXrecord")
(cons 8 val)
)
)
)
(if anXrec;if creation succeeded then add it to our dictionary
(setq anXrec (dictadd adict var anXrec))
); End of If
)
(progn
(setq anXrec(cdr (assoc -1 (dictsearch adict var))));if it's already present then just return its entity name
(dictremove anXrec var)
(entdel anXrec)
(if val ;Wenn ein Wert übergeben wurde
(progn
(setq anXrec (entmakex (list ;if "var" was not found then create it
'(0 . "XRECORD")
'(100 . "AcDbXrecord")
(cons 8 val)
); End of List
); End of Entmakex
); End of Setq
(if anXrec;if creation succeeded then add it to our dictionary
(setq anXrec (dictadd adict var anXrec))
); End of If
); End of Progn
); End of If
); End of Progn
)
)
)
anXrec
); End of Function
;------------------------------------------------------------
; Diese Funktion liest eine StringVariable aus dem Dictionary
;------------------------------------------------------------
(defun read_var (dict var / enDict varlist erg)
(if(setq enDict (dictsearch (namedobjdict) dict))
(if(setq varlist (dictsearch (cdr (assoc -1 enDict)) var))
(setq erg (cdr(assoc 8 varlist)))
); End of If
); End of If
erg
);End of Function
With BricsCAD V23 I get an error when rewriting a variables value.
This rewriting first deletes the old variable with (dictremove) and tries to write it again.
(dictremove) says the first argument is not of type ENAME. Analysing datatypes in the debugger, everything seems fine.
Does anyone have similar experience with (dictremove) in BCV23?
Any suggestions would be very appreciated.
Rolf
Source:
;-----------------------------------------------------------------
;Diese Funktion erstellt ein Dictionary
;-----------------------------------------------------------------
(defun get_or_create_Dict (dict / adict)
(if (not (setq adict (dictsearch (namedobjdict) dict)));test if "dict" is already present in the main dictionary
(progn ;if not present then create a new one and set the main dictionary as owner
(setq adict (entmakex '((0 . "DICTIONARY")(100 . "AcDbDictionary"))))
(if adict (setq adict (dictadd (namedobjdict) dict adict)));if succesfully created, add it to the main dictionary
); End of Progn
(progn
(setq adict (cdr (assoc -1 adict)));if present then just return its entity name
); End of Progn
); End of If
adict
); End of Function
;---------------------------------------------------------------
; Diese Funktion erzeugt eine StringVariable im Dictionary
; und ordnet ihr einen Wert zu
;---------------------------------------------------------------
(defun write_var (dict var val / adict anXrec)
(cond
((setq adict (get_or_create_Dict dict));first get dictionary. Notice that "dict" will be created here in case it doesn't exist
(cond
((not (setq anXrec (dictsearch adict var)));if "dict" is now valid then look for "var" Xrecord
(setq anXrec (entmakex (list ;if "var" was not found then create it
'(0 . "XRECORD")
'(100 . "AcDbXrecord")
(cons 8 val)
)
)
)
(if anXrec;if creation succeeded then add it to our dictionary
(setq anXrec (dictadd adict var anXrec))
); End of If
)
(progn
(setq anXrec(cdr (assoc -1 (dictsearch adict var))));if it's already present then just return its entity name
(dictremove anXrec var)
(entdel anXrec)
(if val ;Wenn ein Wert übergeben wurde
(progn
(setq anXrec (entmakex (list ;if "var" was not found then create it
'(0 . "XRECORD")
'(100 . "AcDbXrecord")
(cons 8 val)
); End of List
); End of Entmakex
); End of Setq
(if anXrec;if creation succeeded then add it to our dictionary
(setq anXrec (dictadd adict var anXrec))
); End of If
); End of Progn
); End of If
); End of Progn
)
)
)
anXrec
); End of Function
;------------------------------------------------------------
; Diese Funktion liest eine StringVariable aus dem Dictionary
;------------------------------------------------------------
(defun read_var (dict var / enDict varlist erg)
(if(setq enDict (dictsearch (namedobjdict) dict))
(if(setq varlist (dictsearch (cdr (assoc -1 enDict)) var))
(setq erg (cdr(assoc 8 varlist)))
); End of If
); End of If
erg
);End of Function
0
Comments
-
Hi Martin,
thanks for the answer.
I used Afralisp as a source for the program above.
I looked at the site currently, but there were no new information about dictionaries.
Until now I could not find any information about new behavior of (dictremove) in V23.
When I looked around in other groups, i get the feeling, that there are some issues with the LISP-Engine in V23.
Hopefully (dictremove) will work in upcoming versions of BricsCAD as it did in previous versions and in AC.
Unfortunately I have no idea for a workaround because (dictremove) is a native LISP-Function.
Any suggestions are very appreciated.0 -
The first argument for dictremove should be the ename of a dictionary, not of an Xrecord.
You should replace:(setq anXrec(cdr (assoc -1 (dictsearch adict var)))) (dictremove anXrec var) (entdel anXrec)
With:(dictremove adict var)
0 -
> (dictremove adict var)
exactly
I tried to eplain the same here, but forum rejected my credentials :-(
Thank you Roy !
and greetings to Rolf0 -
Thanks Roy, thanks Torsten for opening my eyes.
Now the function works fine.0