Results 1 to 5 of 5

Thread: Updating Drawing At VLR-beginSave Event Possible?

  1. #1
    Member
    Join Date
    2004-03
    Posts
    27
    Login to Give a bone
    0

    Default Updating Drawing At VLR-beginSave Event Possible?

    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

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Chelan WA
    Posts
    1,062
    Login to Give a bone
    0

    Default Re: Updating Drawing At VLR-beginSave Event Possible?

    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


    Code:
    (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

  3. #3
    Member
    Join Date
    2004-03
    Posts
    27
    Login to Give a bone
    0

    Default Re: Updating Drawing At VLR-beginSave Event Possible?

    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

  4. #4
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Chelan WA
    Posts
    1,062
    Login to Give a bone
    0

    Default Re: Updating Drawing At VLR-beginSave Event Possible?

    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

  5. #5
    Member
    Join Date
    2004-03
    Posts
    27
    Login to Give a bone
    0

    Thumbs up Re: Updating Drawing At VLR-beginSave Event Possible?

    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

Similar Threads

  1. Textures within xref not updating in main drawing
    By seneb in forum AutoCAD 3D (2007 and above)
    Replies: 2
    Last Post: 2018-05-16, 08:03 PM
  2. Replies: 9
    Last Post: 2014-07-07, 02:40 AM
  3. BeginSave event problems
    By tony.nichols in forum VBA/COM Interop
    Replies: 1
    Last Post: 2012-12-12, 04:03 PM
  4. Updating Page Setups From One Drawing to Another
    By roundbox52 in forum VBA/COM Interop
    Replies: 1
    Last Post: 2008-10-30, 08:36 PM
  5. Updating Drawing Properties thru VBA
    By CADdancer in forum VBA/COM Interop
    Replies: 1
    Last Post: 2004-11-15, 07:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •