TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: roy_043 on December 30, 2016, 04:46:44 AM

Title: Reactor solution does not work in AutoCAD. Why?
Post by: roy_043 on December 30, 2016, 04:46:44 AM
Trying to help a member of a different forum (http://www.cadsite.be/smf/index.php?topic=6540.0), I have created a small reactor based solution. It works fine in BricsCAD (the program I use) but, sadly, for some reason, not in AutoCAD.

The goal of the solution is to link objects in modelspace and paperspace: if you erase one of these objects all objects that are linked to it will automatically also be erased. Comparable to the group mechanism except the objects need not be in the same space.

I have created two versions. One version uses a temporary command reactor, the other a 'post process'. In both cases data is stored as Xdata.

Test (works in BC not in AC):
1. Open the dwg file.
2. Load one of the two Lisp files.
3. On Layout1 erase the 'PS' text.
4. Result: the 'MS' text, in modelspace, is also erased.
5. Use _U.
6. Activate the VP.
7. Erase the 'MS' text.
8. Result: the 'PS' text is also erased.
9. There are also some paired entities in modelspace.

In AC there is an error message that is not very informative:
Code: [Select]
; error: Automation Error. Description was not provided.
If anybody can shed some light on this I would really appreciate it.
Title: Re: Reactor solution does not work in AutoCAD. Why?
Post by: Lee Mac on December 30, 2016, 06:50:30 AM
The code fails at:
Code: [Select]
      (setq obj (vlax-ename->vla-object (cadr lst)))  ; Also checks if ename exists.
Changing the code to:
Code: [Select]
      (/= (logand (getvar 'cmdactive) 3) 0)           ; Check if a command is active.
      (print (entget (cadr lst)))
      (setq obj (vlax-ename->vla-object (cadr lst)))  ; Also checks if ename exists.

Reveals that (entget (cadr lst)) returns nil when the callback function is evaluated.
Title: Re: Reactor solution does not work in AutoCAD. Why?
Post by: CAB on December 30, 2016, 03:08:43 PM
In my very short time using BricsCAD I see that it will forgive (ignore) some LISP errors that Autocad will not.
Title: Re: Reactor solution does not work in AutoCAD. Why?
Post by: roy_043 on December 30, 2016, 04:18:13 PM
@Lee:
Thank you very much for that.

@CAB:
In some cases BricsCAD is more flexible. For example vla-* functions that require point arguments will also accept points-as-lists. But I would not call this behavior 'ignoring errors'.

In the case of this reactor solution it seems that if an object is 'openedForModify' (= The object is about to be modified) entget cannot be used to retrieve its Xdata in AutoCAD. Whereas this is possible in BricsCAD. IMO it is another *very* useful BricsCAD feature.

Attached is a new version that stores data (derived from Xdata) as reactor data.
Needless to say I have got my fingers crossed :-)