TheSwamp
Code Red => .NET => Topic started by: Glenn R on September 06, 2006, 11:24:23 PM
-
Can anybody see a .net wrapping of this or know a way to get at it from .net?
Cheers,
Glenn.
-
Okay, I'll bite.
What's the difference between that and this?
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open()
-
Synchronicity :D
Try using what you suggested and put a messagebox directly after the open and get it to put up the currently active document's name.
The point is, the line to open is executed and immediately follows on to your next statement WITHOUT waiting for the open to finish. You can imagine what this would do to a batch type program............
Cheers,
Glenn.
-
hmm. I see, that makes sense.
We have re-written our batch programs and I checked with my co-worker, who I had develop them and he had a similar problem with the plotting, and used Thread.Sleep(0) just beyond the static method that does the autocad work.
I checked the help and it doesn't seem like a viable solution but it seems to be working as we batch 10,000's of drawings at a time - xbinding, plotting, saving, etc.
-
Synchronicity :D
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
[assembly: CommandClass(typeof(Rivilis.AppOpen))]
namespace Rivilis
{
public class AppOpen
{
public enum OpenFlag
{
kDisallowReadOnly = 0x01,
kRequireReadOnly = 0x02,
kFileNameArgIsUnicode = 0x04,
kViewNameArgIsUnicode = 0x08,
kUseUIOnErrors = 0x10
};
public enum ViewFlag
{
kUnknown = 0, // not used
kDefaultView = 1, // open in last saved view
kLayoutName = 2, // specify layout by name
kViewName = 3, // specify view by name
kLayoutHandle = 4, // specify layout by acdb handle
kViewHandle = 5, // specify view by acdb handle
kViewWorldCoords = 6
};
public struct DocOpenParams
{
public string filename;
public string viewname;
public byte mnInitialViewType;
public Int32 mnFlags;
public string mpwszPassword;
public Int32 mpUnused;
public Int32 mnUnused;
};
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint="?appContextOpenDocument@@YA?AW4ErrorStatus@Acad@@PBUDocOpenParams@AcApDocManager@@@Z")]
private static extern Int32 appContextOpenDocument(ref DocOpenParams parm);
[CommandMethod("FOPEN",CommandFlags.Session)]
static public void Fopen()
{
Autodesk.AutoCAD.Windows.OpenFileDialog dlg = new Autodesk.AutoCAD.Windows.OpenFileDialog(
"AutoCAD dwg-file:","","dwg", "Select dwg-file:",
(Autodesk.AutoCAD.Windows.OpenFileDialog.OpenFileDialogFlags) 0);
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
DocOpenParams parm = new DocOpenParams();
parm.filename = dlg.Filename;
parm.viewname = null;
parm.mnInitialViewType = (byte) ViewFlag.kDefaultView;
parm.mnFlags = 0;
parm.mpUnused = 0;
parm.mpUnused = 0;
Int32 err = appContextOpenDocument(ref parm);
System.Windows.Forms.MessageBox.Show(
dlg.Filename, "Opening",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
}
}
}
}
But I did not found any difference with Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open()
If I try execute appContextOpenDocument or Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open() in other Thread AutoCAD crashed. :(
-
It apeears to work exactly as I expected it would Alexander - thanks very much.
I didn't realise you had to pass the DocOpenParms in - the docs don't mention it in the function call signature.
I'll do some more testing, but it's exactly what I wanted. I was using COM to open up a sequence of drawings and optionally run macros, scripts and plot them...I always wanted to reduce the amount of COM calls I needed to make and this will get rid of the COM Open calls.
Once again, thanks.
Cheers,
Glenn.
-
Well I just modified my batching program to use this method of opening documents/drawings and it worked flawlessly - thanks again Alexander.
The only things that are still COM are the running of VBA macros and scripts...
Cheers,
Glenn.
-
But I did not found any difference with Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open()
If I try execute appContextOpenDocument or Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open() in other Thread AutoCAD crashed. :(
Hi Alex. Very nice.
What release of AutoCAD did you test this on?
-
I'm using '6 btw if you're suspecting maybe a unicode thing in '7 there Tony...?
-
I'm using '6 btw if you're suspecting maybe a unicode thing in '7 there Tony...?
Yes, I have a wrapper for the same API (except it only
works on '07), that's similar to Alex's except that it uses
unicode.
Alex's code should work on 07 if you make the following
changes:
1. On the DllImport() attribute, you to set the
CharSet=CharSet.Unicode
2. On the struct, you need to add the following
attribute:
[StructLayout( LayoutKind.Sequential, CharSet = CharSet.Unicode )]
3. When you set the struct's fields, you need to
set the 'flags' field to 0x4 and if you supply a
string in the second field (view or layout name),
you also need to include 0x8.
-
Hi Alex. Very nice.
What release of AutoCAD did you test this on?
AutoCAD 2006.
-
Hmmm...seeing as Alex has stated that he's on '06, as am I and it works fine for me, maybe it's a framework thing.
I know I have gotten different results (crashes) using 1.1 code on Autocad that has not has it's .config modified (ie always using the latest).............
Cheers,
Glenn.
-
Hmmm...seeing as Alex has stated that he's on '06, as am I and it works fine for me, maybe it's a framework thing.
I know I have gotten different results (crashes) using 1.1 code on Autocad that has not has it's .config modified (ie always using the latest).............
Cheers,
Glenn.
I have installed both AutoCAD 2006 and AutoCAD 2007. Config of AutoCAD 2006 is modified for using .NET 1.1
Crash was only if I start appContextOpenDocument() from other then main Thread.