I am trying to setup a reactor that automatically renumbers/inserts blocks after a table has been edited. My code is below, after editing the table, I get the error: Automation Error. Object was notifying
I am not super familiar with reactors yet, but I am sure that I am doing something obviously wrong here, can someone please advise?
(vl-load-com)
;Supporting Functions
;;Ranjit Singh
;;7/11/17
;;Sets Cell Style
(defun FixStyle (x tblobj c / rows r)
(setq r 1
rows (vla-get-rows tblobj)
)
(while (< r rows)
(vl-catch-all-apply 'vla-setcellstyle (list tblobj r c x))
(setq r (1+ r))
)
(princ)
)
;The following fixes row heights
(defun FixHeight (tblobj / rows r)
(setq rows (- (vla-get-rows tblobj) 1))
(while (> rows -1)
(vla-setrowheight tblobj rows 0.01)
(setq rows (- rows 1))
)
)
(defun ChangeAttr (TableObject Row Column BlockName Value / BlockCollection Bk AttID EachBk)
(setq BlockCollection (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
Bk (vla-item BlockCollection BlockName)
)
(vlax-for EachBk Bk
(if (= (vla-get-objectname EachBk) "AcDbAttributeDefinition")
(Setq AttID (vla-get-objectid EachBk))
)
)
(vla-setblockattributevalue TableObject Row Column AttID Value)
)
;Add block to table - from https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/block-in-table/m-p/7827041/highlight/true#M366009
(defun InsertBlockTable (tableobject row column blockname / bk fg id bkid)
(setq bk (vla-item (vla-get-blocks
(vla-get-activedocument (vlax-get-acad-object))
)
blockname
)
)
(if (vlax-method-applicable-p
tableobject
'setblocktablerecordid32
)
(setq id (vla-get-objectid32 bk)
fg t
)
(setq id (vla-get-objectid bk))
)
((if fg
vla-setblocktablerecordid32
vla-setblocktablerecordid
)
tableobject row column id :vlax-false)
)
;Makes a Note Table based on type:
;GN = General Notes
;RN = Reference Notes
(defun MakeTable (Pt tType / ActDoc *Space* insPt tableObj NoteRactor)
(setq ActDoc (vla-get-activedocument (vlax-get-acad-object))
*Space* (vlax-get-property ActDoc (nth (vla-get-ActiveSpace ActDoc)'("PaperSpace" "ModelSpace")))
insPt (vlax-3d-point Pt)
)
(setq tableObj (vla-Addtable *Space* insPt 2 2 10 30))
(vla-put-HeaderSuppressed tableObj :vlax-true)
(vla-put-StyleName tableObj "BEI_Notes")
(Vla-unmergecells tableObj 0 0 1 1)
(vla-setcolumnwidth tableObj 0 0.51587034)
(vla-setcolumnwidth tableObj 1 3.75097081)
;Adjust to go through every row
(if (= tType "GN")
(progn
(vla-put-layer tableObj "$GN")
(FixStyle "GN_Number" tableObj 0)
(FixStyle "Data" tableObj 1)
(vla-setText tableObj 0 1 "\\LGENERAL NOTES")
(vla-setText tableObj 1 1 "PLEASE MODIFY THE TEXT HERE AND AS YOU ADD ROWS THEY WILL BE AUTOMATICALLY NUMBERED.")
(InsertBlockTable tableObj 1 0 "genn10")
)
(progn
(vla-put-layer tableObj "$RN")
(FixStyle "RN_Number" tableObj 0)
(FixStyle "Data" tableObj 1)
(vla-setText tableObj 0 1 "\\LREFERENCE NOTES")
(vla-setText tableObj 1 1 "PLEASE MODIFY THE TEXT HERE AND AS YOU ADD ROWS THEY WILL BE AUTOMATICALLY NUMBERED.")
(InsertBlockTable tableObj 1 0 "1m10")
)
)
(FixHeight tableObj)
(setq NoteReactor (vlr-object-reactor (list TableObj) "Notes Changed" '((:vlr-objectclosed . AutoRenumberNotes))))
(vlr-pers NoteReactor)
(princ)
)
(defun AutoRenumberNotes (Obj Rct Arg)
(RenumberNotes Obj)
)
(defun c:MakeRN (/ Pt)
(setq Pt (getpoint "\nPlease select insertion point:"))
(MakeTable Pt "RN")
)
(defun c:MakeGN (/ Pt)
(setq Pt (getpoint "\nPlease select insertion point:"))
(MakeTable Pt "GN")
)
(defun c:ReNumber (/ TableObject)
(setq TableObject (vlax-ename->vla-object (car (entsel "\nSelect table: "))))
(if (/= TableObject nil)
(RenumberNotes TableObject)
)
)
(defun RenumberNotes (TableObject / row rows TLayer bName cCellType)
(setq rows (vla-get-rows TableObject)
row 1
TLayer (vla-get-layer TableObject)
)
(if (= TLayer "$GN")
(setq bName "genn10")
(setq bName "1m10")
)
(while (< row rows)
(setq cCellType (vla-getcelltype TableObject Row 0))
(if (/= cCellType acblockcell)
(InsertBlockTable TableObject Row 0 bName)
)
(ChangeAttr TableObject Row 0 bName (rtos Row 2 0))
(setq row (+ row 1))
)
)
;End of Supporting Functions
;Add Automatic reactors