PDA

View Full Version : Updating Drawing At VLR-beginSave Event Possible?


relysoft
2005-01-19, 07:56 PM
If I establish a reactor to give me notice when a VLR-beginSave event occurs, can I update the drawing in the reactor callback routine? I would like to update some XDATA that has the initials of the last drafter to have edited the drawing as it is saved. I have the drafter's initials at that point, but am concerned about this being a "legal" and possible time to make a drawing change. I have read from time to time about timing issues when ACAD is saving. Any experienced help would be appreciated.

Thanks,
Bob

peter
2005-01-20, 01:37 PM
I built this little test to check to see if your concept works. It did.

Yes it is possible to change xdata inside the beginsave event.

I really wish the indenting in the forums could be fixed!

Peter Jamtgaard



(defun evtBeginSaveXdata (CALL CALLBACK / strLogin)
(setq strLogin (variant-value
(vla-getvariable
(vla-get-activedocument
(vlax-get-acad-object)) "loginname")))
(setxdata (vla-item
(vla-get-layouts
(vla-get-activedocument
(vlax-get-acad-object)
)
)
"Model"
)
(list (list "LOGIN" strLogin))
)
)
; The setxadatalist function will add a list of sublists to an object as xdata.
; The first item in each sublist is a unique string application name
; Syntax (setxdata vla-object (list (list "test" 1 2 "a" )(list "app2" "hello" "world")))
(defun SetXData (objSelection lstOfSubLists / DataItem lstData
intDataType lstOfSublistsDXFCodes lstOfSublistsValues
safDXFCodes safDataValues)
(if debug (princ "\nSetXdata: "))
(foreach lstData lstOfSublists
(setq lstOfSublistsDXFCodes (cons 1001 lstOfSublistsDXFCodes)
lstOfSublistsValues (cons (car lstData) lstOfSublistsValues))
(RegApp (car lstData))
(foreach DataItem (cdr lstData)
(cond ; Determine the data type and corrusponding DXF Code
((= (type DataItem) 'INT) (setq intDataType 1070)) ; Integer Data Type
((= (type DataItem) 'REAL)(setq intDataType 1040)) ; Real Data Type
((= (type DataItem) 'STR)
(if (or (= DataItem "{")(= DataItem "}")) ; String Data Type
(setq intDataType 1002)
(setq intDataType 1000)
)
)
)
(setq lstOfSublistsDXFCodes (cons intDataType lstOfSublistsDXFCodes)
lstOfSublistsValues (cons DataItem lstOfSublistsValues))))
(setq safDXFCodes (listToSafearray vlax-vbinteger
(reverse lstOfSublistsDXFCodes))
safDataValues (listToSafeArray vlax-vbvariant
(reverse lstOfSublistsValues)))
(vla-setXData objSelection safDXFCodes safDataValues))

(setq rxnBeginSaveXdata (vlr-editor-reactor nil '((:vlr-beginsave . evtBeginSaveXdata))))



m

relysoft
2005-01-21, 10:40 PM
Peter,

I have decided to use the vlax-ldata-* dictionary functions to store the initials and some other data instead of using xdata. That part is working OK.

However, I have a question regarding reactors - surprised to hear that aren't you?


First I set the dwg reactor :
(setq rnxbeginSave (vlr-dwg-reactor nil '((:vlr-beginSave . evtbeginSave ))))

The callback got hit 3 times every time a save was done - my logic needs one and only one.

Then I looked at your sample code again and save that you had specified an editor reactor, so I change my code to:
(setq rnxbeginSave (vlr-editor-reactor nil '((:vlr-beginSave . evtbeginSave ))))

This seemed to only cause the callback to be activated once per save. I thought I was home free. But, then I saw it was a logic bust. After fixing the bust I once again saw my callback routine getting hit 3 times.

Why the three call for a single save command?

Also, I'm getting an infrequent and apparently random ACAD crash - a memory exception I think it is - when my logic executes during the callback. In that logic I update some text on the drawing and manipulate my dictionary vlax-ldata-* functions. Am I asking for trouble trying to do this while a save is going on?

Thanks,
Bob

peter
2005-01-24, 04:13 PM
I would suggest adding a boolean flag to the routine that allows it to only run once. Then use a command ended reactor to reset the boolean to nil

Peter Jamtgaard

relysoft
2005-01-24, 11:23 PM
Thanks for the suggestion. I will give that a try as soon as I put out another "fire".

I guess I am spoiled by my Windows SDK development experiences, but working with the ACAD reactors is a real pain - multiple callbacks from what appears to be a single ACAD event, etc. I suppose I shouldn't complain. It is light years ahead of the tools available a few years back. But if one doesn't complain and ask for more, how are we going to get better tools- right?

Anyone know of some good reference web sites/books that go into some detail about what is going on behind the scene with the reactors and, maybe, why the callback calls occur as they do?

Bob