"Send command" to not-current drawing?

Started by Peter2, March 25, 2014, 07:33:45 AM

Previous topic - Next topic

Peter2

(This is a short-spin-off from my question at "theswamp" - link see below)

Regarding this issue I found many questions, only a few answers (.net, VBA, ...), but nothing inside the (V)Lisp-world ...

I have
- an opened, empty drawing: "basic.dwg"
- running Lisp+OpenDCL+Doslib

I want
a) start a lisp in "basic.dwg"
b) calculate some filename, e.g. "test1.dwg"
c) open "test1.dwg"
d) run any lisp I want in "test1.dwg"
e) close "test1.dwg"

Short question for a short answer:
- Are there any features in OpenDCL (some "send command" or "invoke" or "execute..") which can handle Step d) ?

Long question for long answers:
- main discussion here: http://www.theswamp.org/index.php?topic=46615.0

Regards

Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

owenwengerd

I don't think OpenDCL will help. In my opinion, the only viable general purpose solution is manage this from the application context, which requires .NET or ObjectARX.
Owen Wengerd (Outside The Box) / ManuSoft

Peter2

Quote from: owenwengerd on March 25, 2014, 08:17:19 AM
I don't think OpenDCL will help. In my opinion, the only viable general purpose solution is manage this from the application context, which requires .NET or ObjectARX.
This is the answer I was afraid of ...  :'(
OK, thanks Owen. Now I have to see if I can find a workaround based on the lowest level (script) or have to look for someone who makes the solution.
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

Fred Tomke

Hi, give me a second until I've entered the hotel. Have an idea using modeless Form and OnDocActivated.
Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Peter2

Quote from: Fred Tomke on March 25, 2014, 12:14:09 PM
Hi, give me a second until I've entered the hotel. ...
Also 5 sec or more ...
Yes, a modeless form already exists and can be used.
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

Fred Tomke

Hi Peter, it depends on what you're going to do: if you want to query the other drawing (execute analysis of geometry or attribute data) you really should prefer using ObjectDBX. You can even change the drawing (add or modify entities) and save your changes.

Code (autolisp) Select
(defun GetFileLayers (strDwg / oDbx oLayer lstLayers)
  (if (and (setq oDbx (vl-catch-all-apply 'vla-GetInterfaceObject (list (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." (substr (getvar "ACADVER") 1 2)))))
   (not (vl-catch-all-error-p oDbx)))
    (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list oDbx strDwg)))
      (vlax-release-object oDbx)
      (progn
(vlax-for oLayer (vla-get-layers oDbx) (setq lstLayers (cons (vla-get-name oLayer) lstLayers)))
(vlax-release-object oDbx)
      ); progn
    ); if
  ); if
); GetFileLayers


In the case you want to open a drawing to do something, Lisp requires an active document context: you cannot execute Lisp in an inactive drawing.
That's why I tried a modeless form which calls OnDocActivated event after switching between drawings. You should also be able to do this using  Document-Reactors, but I had no try yet.
If you want to use OnDocActivated in a newly opened drawing you have to make sure that your lisp file is loaded by (vl-load-all ...).
The only problem I had was that the calling drawing has still a pointer/focus to the opened drawing so AutoCAD freezes while closing the drawing.

Have a test. Maybe you can catch the rest.
I recommend you to go the DBX-path.
Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Peter2

Hi Fred

thank you. In your code you have a "dcl_project_load", but there are no OpenDCL data ?
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

Fred Tomke

Yes, I've uploaded the lisp but not the zip which also contained the odcl. It was simply too late.
Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Peter2

Hi Fred

thanks, it works fine in the version you attached. But now I tried to use the commented "(command close)" and to comment out the messages - and get an AutoCAD crash. How to run it incl. "close" and with no messages?
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

Fred Tomke

Hi, and thats the thing it took me hours to figure out. At least I surrendered and now it's your task to investigate it - it's not OpenDCL related.
That's why I mentioned that you should consider ObjectDBX as a solution.
Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

owenwengerd

Did you try (dcl-SendString "_CLOSE\n")?
Owen Wengerd (Outside The Box) / ManuSoft

Peter2

Quote from: owenwengerd on March 26, 2014, 06:07:56 AM
Did you try (dcl-SendString "_CLOSE\n")?
One step ahead  :)

I will report (e.g. how to send "_close _yes"...)
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

Peter2

Here is the slightly modified code from Fred.

Changes:
- dcl_sendstring instead of "command"
- changed "alert" to "princ"
- added "draw a line" to modify the drawing
- added (acad-push-dbmod)/(acad-pop-dbmod) to "close without asking for saving"

-> Now it seems to do what is needed:
The current drawing opens another, runs a lisp, closes the drawing and comes back to current drawing.

I will try more and will report.
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10

Fred Tomke

Hi, thanks. But I keep my position: Have a look at my ObjectDBX sample and there you will see that it is much easier to create a new line in the silently opened drawing. You cannot fight the battle with all the possible 3rd party apps and maybe AutoCAD itself which are catching opening and closing events of drawings to show messageboxes to notify the user about anything. I've already had my troubles with that in the past.

Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Peter2

The discussion at theswamp (see link in first post) brought a way with "S::startup", document reactors, registry and (vl-cmdf "close"). Tomorrow I will continue with testing and will see which way to go.

Thanks.
Peter
ODCL 8.1.... German, AutoCAD 2017 - 2018, Win 7 x64, Win 10