OpenDCL Forums

OpenDCL => Runtime/AutoLISP => Topic started by: Peter2 on March 25, 2014, 07:33:45 AM

Title: "Send command" to not-current drawing?
Post by: Peter2 on March 25, 2014, 07:33:45 AM
(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

Title: Re: "Send command" to not-current drawing?
Post by: 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.
Title: Re: "Send command" to not-current drawing?
Post by: Peter2 on March 25, 2014, 08:24:52 AM
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.
Title: Re: "Send command" to not-current drawing?
Post by: Fred Tomke on March 25, 2014, 12:14:09 PM
Hi, give me a second until I've entered the hotel. Have an idea using modeless Form and OnDocActivated.
Fred
Title: Re: "Send command" to not-current drawing?
Post by: Peter2 on March 25, 2014, 12:49:35 PM
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.
Title: Re: "Send command" to not-current drawing?
Post by: Fred Tomke on March 25, 2014, 04:34:50 PM
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
Title: Re: "Send command" to not-current drawing?
Post by: Peter2 on March 26, 2014, 02:14:12 AM
Hi Fred

thank you. In your code you have a "dcl_project_load", but there are no OpenDCL data ?
Title: Re: "Send command" to not-current drawing?
Post by: Fred Tomke on March 26, 2014, 04:39:48 AM
Yes, I've uploaded the lisp but not the zip which also contained the odcl. It was simply too late.
Regards, Fred
Title: Re: "Send command" to not-current drawing?
Post by: Peter2 on March 26, 2014, 05:07:20 AM
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?
Title: Re: "Send command" to not-current drawing?
Post by: Fred Tomke on March 26, 2014, 05:50:38 AM
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
Title: Re: "Send command" to not-current drawing?
Post by: owenwengerd on March 26, 2014, 06:07:56 AM
Did you try (dcl-SendString "_CLOSE\n")?
Title: Re: "Send command" to not-current drawing?
Post by: Peter2 on March 26, 2014, 07:10:12 AM
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"...)
Title: Re: "Send command" to not-current drawing?
Post by: Peter2 on March 26, 2014, 07:34:18 AM
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.
Title: Re: "Send command" to not-current drawing?
Post by: Fred Tomke on March 26, 2014, 11:18:30 AM
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
Title: Re: "Send command" to not-current drawing?
Post by: Peter2 on March 26, 2014, 02:35:17 PM
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.