Author Topic: Suppressing the Open File Dialog: is there a 4th way?  (Read 3095 times)

0 Members and 1 Guest are viewing this topic.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Suppressing the Open File Dialog: is there a 4th way?
« on: July 23, 2013, 04:01:36 AM »
I am trying to create a custom 'Recent Files' menu. If you click on an entry in the menu the Open File Dialog should be suppressed and a drawing should open directly.
I can think of three ways to accomplish this:

1.
Code: [Select]
^c^c(initdia)(command "_open" "C:/MyPath/MyDrawing.dwg")(princ)Problem: Only works if there is an open dwg.

2.
Code: [Select]
^c^c_filedia;0;_open;C:/MyPath/MyDrawing.dwg;_filedia;1Problem: Only works if there is an open dwg.

3.
Code: [Select]
^c^c_script;C:/MyScripts/Open_MyDrawing.scrWith a script that looks like this:
Code: [Select]
open C:/MyPath/MyDrawing.dwgThis also works if there is no open dwg.

I am looking for a 4th way that does not involve scripts but also works if no dwg is open.
Does anybody know a 4th way?

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Suppressing the Open File Dialog: is there a 4th way?
« Reply #1 on: July 23, 2013, 11:26:55 AM »
Unfortunately macros, lisp and script run inside the drawing's namespace. So if there's no drawing open at the time, it cannot run.

I haven't tried it, but if you compile a LSP into a FAS/VLX there's an option to compile it into its own namespace (separate from the DWG). How you would call that though is still a blur in my mind.

The only other alternatives I can think of would be
  • VBA (perhaps, but still how do you call it from the menu without any DWG open, perhaps using an event).
  • DotNet, you should probably also add an event to catch the menu choice. A command won't cut it as you can't issue a command without a DWG open.
  • ARX, same as the rest - an event is your only possible alternative (AFAICT)
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Suppressing the Open File Dialog: is there a 4th way?
« Reply #2 on: July 23, 2013, 03:13:32 PM »
This can be done in .net without much trouble.  VBA is another option I think

BlackBox

  • King Gator
  • Posts: 3770
Re: Suppressing the Open File Dialog: is there a 4th way?
« Reply #3 on: July 23, 2013, 04:48:43 PM »
FWIW -

Here's something in .NET so you don't have to start from scratch.
"How we think determines what we do, and what we do determines what we get."

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Suppressing the Open File Dialog: is there a 4th way?
« Reply #4 on: July 25, 2013, 04:04:03 AM »
Thank you for your answers. I was actually hoping there might some special Diesel code to do this... Using a .NET or VBA solution is something that I will keep in mind for the future. For now I will use the script solution (#3 in my first post).

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Suppressing the Open File Dialog: is there a 4th way?
« Reply #5 on: July 25, 2013, 08:41:10 AM »
This can be done in .net without much trouble.  VBA is another option I think
I.e. you'd use a Command Method with its Session flag set?
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/index.html?url=WS1a9193826455f5ff-e569a0121d1945c08-17d4.htm,topicNumber=d0e3788

Edit: I'm a bit confused. How exactly would you call that command (even though it isn't inside the document context)? I mean, if there's no document open, then even the command-line itself is unavailable. The entire menu structure changes such that the ribbon is void with only minimal stuff in the main menu button. Or if you've got the menubar turned on you only have minimal stuff there too. Can a macro be added to these menus so you can actually call your "session" command?
« Last Edit: July 25, 2013, 08:47:47 AM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Suppressing the Open File Dialog: is there a 4th way?
« Reply #6 on: July 25, 2013, 10:11:56 AM »
No options dialog either.  Although I *think* you can modify the Start menu...
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Suppressing the Open File Dialog: is there a 4th way?
« Reply #7 on: July 25, 2013, 01:55:11 PM »
I.e. you'd use a Command Method with its Session flag set?
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/index.html?url=WS1a9193826455f5ff-e569a0121d1945c08-17d4.htm,topicNumber=d0e3788

Edit: I'm a bit confused. How exactly would you call that command (even though it isn't inside the document context)? I mean, if there's no document open, then even the command-line itself is unavailable. The entire menu structure changes such that the ribbon is void with only minimal stuff in the main menu button. Or if you've got the menubar turned on you only have minimal stuff there too. Can a macro be added to these menus so you can actually call your "session" command?

You don't actually call a command to do the opening, but you're onto the right path with the session flag.  If you create a palette within a session command like I've shown attached it will live through the zero document state.  From there you can open drawings with Application.DocumentManager.Open() method.  In the case of the OP this would show a list of recent drawings rather than the file system treeview as I've done here.

An important note for anyone trying to go down this path: if you simply call open from the context of your palette you will get an error eInvalidContext (even though the file will open  :realmad: :ugly: :pissed: [which if you can't already tell cost me some sleep]), you must create a Application.Idle event handler and call it from there.

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Suppressing the Open File Dialog: is there a 4th way?
« Reply #8 on: July 25, 2013, 02:04:43 PM »
3.
Code: [Select]
^c^c_script;C:/MyScripts/Open_MyDrawing.scrWith a script that looks like this:
Code: [Select]
open C:/MyPath/MyDrawing.dwgThis also works if there is no open dwg.
I'm confused that this works with no open drawings.  How do you run the script if there is no drawing open?

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Suppressing the Open File Dialog: is there a 4th way?
« Reply #9 on: July 25, 2013, 03:22:17 PM »
I'm confused that this works with no open drawings.  How do you run the script if there is no drawing open?
My point exactly!
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Suppressing the Open File Dialog: is there a 4th way?
« Reply #10 on: July 26, 2013, 04:26:43 AM »
I'm confused that this works with no open drawings.  How do you run the script if there is no drawing open?
Sorry for causing confusion. I use BricsCAD.

In the meantime I have found a 4th way:

4.
Code: [Select]
^c^c_start;C:/MyPath/MyDrawing.dwgThis works if no dwg is open (at least in BC...), but is very slow.

BlackBox

  • King Gator
  • Posts: 3770
Re: Suppressing the Open File Dialog: is there a 4th way?
« Reply #11 on: July 26, 2013, 11:50:11 AM »
I.e. you'd use a Command Method with its Session flag set?
http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/index.html?url=WS1a9193826455f5ff-e569a0121d1945c08-17d4.htm,topicNumber=d0e3788

Edit: I'm a bit confused. How exactly would you call that command (even though it isn't inside the document context)? I mean, if there's no document open, then even the command-line itself is unavailable. The entire menu structure changes such that the ribbon is void with only minimal stuff in the main menu button. Or if you've got the menubar turned on you only have minimal stuff there too. Can a macro be added to these menus so you can actually call your "session" command?

You don't actually call a command to do the opening, but you're onto the right path with the session flag.  If you create a palette within a session command like I've shown attached it will live through the zero document state.  From there you can open drawings with Application.DocumentManager.Open() method.  In the case of the OP this would show a list of recent drawings rather than the file system treeview as I've done here.

An important note for anyone trying to go down this path: if you simply call open from the context of your palette you will get an error eInvalidContext (even though the file will open  :realmad: :ugly: :pissed: [which if you can't already tell cost me some sleep]), you must create a Application.Idle event handler and call it from there.

Thanks for sharing. *tips hat*
"How we think determines what we do, and what we do determines what we get."