Hi,
You cannot use the command function within a reactor callback function.
You can set "unpurgeable" a block definition (or any other object) using a hard pointer.
Some routines from my tool box:
;; gc:GetExtDict (gile)
;; Gets the object extension dictionary (or nil)
;;
;; Argument : obj (ENAME)
(defun gc:GetExtDict (obj)
(cdadr (member '(102 . "{ACAD_XDICTIONARY") (entget obj)))
)
;; gc:GetOrCreateExtDict (gile)
;; Gets the object extension dictionary
;; The dictionary is created if not already exists
;;
;; Argument : obj (ENAME)
(defun gc:GetOrCreateExtDict (ent / dict)
(cond
((cdadr (member '(102 . "{ACAD_XDICTIONARY") (entget ent))))
((setq dict (entmakex
'((0 . "DICTIONARY") (100 . "AcDbDictionary"))
)
)
(entmod
(vl-list*
(assoc -1 elst)
(assoc 0 elst)
(assoc 5 elst)
(cons 102 "{ACAD_XDICTIONARY")
(cons 360 dict)
(cons 102 "}")
(vl-remove-if (function (lambda (x) (member (car x) '(-1 0 5)))) elst)
)
)
dict
)
)
)
;; gc:SetXrecData (gile)
;; Returns the ENAME of the xrecord which data are set to
;;
;; Arguments
;; dict : ENAME of the parent dictionary
;; key : name of the xrecord
;; data : dotted pair list containg data
(defun gc:SetXrecData (dict key data / xrec)
(if (snvalid key)
(progn
(and (setq xrec (dictsearch dict key))
(entdel (cdr (assoc -1 xrec)))
)
(dictadd
dict
key
(entmakex
(append
(list '(0 . "XRECORD")
'(100 . "AcDbXrecord")
)
data
)
)
)
)
)
)
;; gc:GetXrecData (gile)
;; Gets the data of the xreord (dooted pair list)
;;
;; Arguments
;; dict : ENAME of the parent dictionary
;; key : name of the xrecord
(defun gc:GetXrecData (dict key / xrec)
(if (and
(setq xrec (dictsearch dict key))
(= (cdr (assoc 0 xrec)) "XRECORD")
)
(cdr (member (assoc 280 xrec) xrec))
)
)
;; gc:SetUnPurgeable (gile)
;; Sets unpurgeable the table record (AcDbSymbolTableRecord)
;; Returns T if succeeded; nil otherwise
;;
;; Arguments
;; table : the table name
;; name : the record name
(defun gc:SetUnPurgeable (table name / symbol xdict)
(and
(setq symbol (tblobjname table name))
(setq xdict (gc:GetOrCreateExtDict
(cdr (assoc -1 (entget (cdr (assoc 330 (entget symbol))))))
)
)
(gc:SetXrecData
xdict
"UnPurge"
(cons (cons 340 symbol) (gc:GetXrecData xdict "UnPurge"))
)
)
)
;; gc:ResetPurgeable (gile)
;; Reset purgeable the table record (AcDbSymbolTableRecord)
;;
;; Arguments
;; table : the table name
;; name : the record name
(defun gc:ResetPurgeable (table name / symbol xdict)
(and
(setq symbol (tblobjname table name))
(setq xdict (gc:GetOrCreateExtDict
(cdr (assoc 330 (entget symbol)))
)
)
(setq data (gc:GetXrecData xdict "UnPurge"))
(member (cons 340 symbol) data)
(or
(and (= 1 (length data)) (dictremove xdict "UnPurge"))
(gc:SetXrecData
xdict
"UnPurge"
(vl-remove (cons 340 symbol) data)
)
)
)
)
;; gc:ResetAllPurgeable (gile)
;; Reset purgeable all records previously set as unpurgeable
(defun gc:ResetAllPurgeable (/ name symbol xdict)
(foreach table '("LAYER" "LTYPE" "VIEW" "STYLE" "BLOCK" "UCS" "APPID" "DIMSTYLE" "VPORT")
(and
(setq name (cdr (assoc 2 (tblnext table T))))
(setq symbol (tblobjname table name))
(setq xdict (gc:GetExtDict (cdr (assoc 330 (entget symbol)))))
(gc:GetXrecData xdict "UnPurge")
(dictremove xdict "UnPurge")
)
)
)