I'm still having difficulty. The program will work for a little bit but then goes screwy and I get the Access Violation stuff again. Here's my code, can you see if I missed something? The attached file has the block I'm working with.
Code:
(vl-load-com)
(vl-load-reactors)
(setq CautionBoxChangedList nil)
(setq ModifyingCautionBoxes nil)
; This function is used as the Object Modified Reactor Callback.
(defun ObjectChanged
(Reactor ObjectList
/ Object ObjectName DynProps
LineAngle TextAngle Index
DynPropName Db Status)
; Check that the object is not being modified from the command reactor.
(if ModifyingCautionBoxes (VL-EXIT-WITH-VALUE ""))
; Check that the drawing is not closed.
(setq Status (VL-CATCH-ALL-APPLY 'vla-get-active (list (vlr-document Reactor))))
(if (= (type Status) 'VL-CATCH-ALL-APPLY-ERROR) (VL-EXIT-WITH-VALUE ""))
(setq Db (nth 0 ObjectList))
; Check that the object is not erased.
(if (null (entget (nth 1 ObjectList))) (VL-EXIT-WITH-VALUE ""))
(setq Object (vlax-ename->vla-object (nth 1 ObjectList)))
(setq ObjectName (VL-CATCH-ALL-APPLY 'vla-get-objectname (list Object)))
; Check that the modified item is a block reference.
(if (= ObjectName "AcDbBlockReference")
(progn
; Check that it was a dynamic block.
(if (and (= (vla-get-effectivename Object) "abc") (vla-get-IsDynamicBlock Object))
(progn
; Find the required dynamic properties.
(setq DynProps (vlax-safearray->list (vlax-variant-value (vla-GetDynamicBlockProperties Object))))
(setq Index 0)
(while (< Index (length DynProps))
(setq DynPropName (vla-get-PropertyName (nth Index DynProps)))
(cond
((= DynPropName "Angle")
(setq LineAngle (nth Index DynProps))
)
((= DynPropName "TextAngle")
(setq TextAngle (nth Index DynProps))
)
)
(setq Index (1+ Index))
)
; Check that the required properties where found.
(if (not (and (null LineAngle) (null TextAngle)))
; Retain the modified block for post processing.
(setq CautionBoxChangedList (append CautionBoxChangedList (list Object)))
)
)
)
)
)
)
; This function is used as the Command Ended Reactor Callback.
(defun CommandEnded
(Reactor ObjectList
/ Index Block DynProps
DynPropIndex DynPropName LineAngle
TextAngle dLineAngle dTextAngle)
(if (not (null CautionBoxChangedList))
(progn
; Keep the Object Modified Reactor from firing.
(setq ModifyingCautionBoxes T)
(setq Index 0)
(while (< Index (length CautionBoxChangedList))
(setq Block (nth Index CautionBoxChangedList))
; Find the requried properties.
(setq DynProps (vlax-safearray->list (vlax-variant-value (vla-GetDynamicBlockProperties Block))))
(setq DynPropIndex 0)
(while (< DynPropIndex (length DynProps))
(setq DynPropName (vla-get-PropertyName (nth DynPropIndex DynProps)))
(cond
((= DynPropName "Angle")
(setq LineAngle (nth DynPropIndex DynProps))
)
((= DynPropName "TextAngle")
(setq TextAngle (nth DynPropIndex DynProps))
)
)
(setq DynPropIndex (1+ DynPropIndex))
)
; Check that the block had the required properties.
(if (not (and (null LineAngle) (null TextAngle)))
; Process the block.
(progn
(setq dLineAngle (vlax-variant-value (vla-get-value LineAngle)))
(setq dTextAngle (vlax-variant-value (vla-get-value TextAngle)))
; Debug - (alert (strcat "Line: " (rtos dLineAngle) "nText: " (rtos dTextAngle)))
; Change the values of the block.
(cond
((and (> dLineAngle (/ Pi 2)) (<= dLineAngle (* Pi 1.5)))
(vla-put-value TextAngle (variant Pi))
)
(T
(vla-put-value TextAngle (variant (* Pi 2)))
)
)
)
)
(setq Index (1+ Index))
)
; Clear the values for the next time objects are modified.
(setq ModifyingCautionBoxes nil)
(setq CautionBoxChangedList nil)
)
)
)
; Create reactors.
(if (/= (type ObjectAppendedReactor) 'VLR-AcDb-Reactor)
; This reactor is used to catch blocks that have changed.
(setq ObjectAppendedReactor (VLR-AcDb-Reactor nil '((:VLR-objectAppended . ObjectChanged))))
)
(if (/= (type ObjectChagnedReactor) 'VLR-AcDb-Reactor)
; This reactor is used to catch blocks that have changed.
(setq ObjectChagnedReactor (VLR-AcDb-Reactor nil '((:VLR-objectModified . ObjectChanged))))
)
(if (/= (type CommandEndedReactor) 'VLR-Command-Reactor)
; this reactor is used to change the blocks after the user is finished their edits.
(setq CommandEndedReactor (VLR-Command-Reactor nil '((:VLR-commandEnded . CommandEnded))))
)