Author Topic: Reactor solution does not work in AutoCAD. Why?  (Read 2174 times)

0 Members and 1 Guest are viewing this topic.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Reactor solution does not work in AutoCAD. Why?
« on: December 30, 2016, 04:46:44 AM »
Trying to help a member of a different forum, 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.
« Last Edit: December 30, 2016, 04:51:13 AM by roy_043 »

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Reactor solution does not work in AutoCAD. Why?
« Reply #1 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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Reactor solution does not work in AutoCAD. Why?
« Reply #2 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.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Reactor solution does not work in AutoCAD. Why?
« Reply #3 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 :-)