I need to be able to open a dxf using the dxfin command, via vb.net....Yes, for whatever reason, it really does have to be the dxfin command exactly like you'd use from the commend line. I can't open it any other way - not even in cad. These dxfs don't open at all unless you do it this way....so for now, you'll have to take my word for it.
So - I need to be able to not only run the dxfin command, but pass the filename to it so it opens the dxf file. I've tried all sorts of things, and just spinning in circles here now. I think that I'd like to use acedCmd to do this, so that the rest of my code will wait until the command is done, but for the life of me, I can't get it to take the filename. Is there something special about this command that's not letting me pass the filename? Any other command that I test out using this method works just fine - but this one's not.
Any suggestions??
Hi Andrew,
You can give a try at the two approaches illustrated below, one is with invoking DXFIN, the other with Database.DxfIn method.
Philippe.
[DllImport("accore.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedCommandS")] private static extern int acedCommandS( int type1, string str1, int type2, string str2, int end); [CommandMethod("DxfInNet")] public void DxfInNet() { Document doc = Application.DocumentManager.MdiActiveDocument; object filedia = Application.GetSystemVariable("FILEDIA"); Application.SetSystemVariable("FILEDIA", 0); acedCommandS(5005, "_DXFIN", 5005, "c:\\Temp\\test.dxf", 5000); Application.SetSystemVariable("FILEDIA", filedia); } [CommandMethod("netInsertDxf")] static public void netInsertDxf() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; Database TmpDb = new Database(false, true); TmpDb.DxfIn("C:\\Temp\\TempDb.dxf", "C:\\Temp\\TempDb.log"); Matrix3d Transform = Matrix3d.Identity; db.Insert(Transform, TmpDb, true); }
______________________________________________________________
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
I'd tried the database.dxfin method before, and that doesn't work in my case with this dxf. Unfortunately, that method always results in crashing Autocad the second I import the database into the activedocument database...
Your acedCommand method seems to get me a tiny bit further than I was able to get with acedCmd....I see the filename listed in the command prompt, but it's not doing anything. It's as though it's not ending the command....I see "_DXFIN File name: N:\drawings\45756660R.DXF", but it actually doesn't nothing.
I don't see what would prevent you from using the solution with acedCommand I just provided, but here is the version with acedCmd, you probably omit the empty string at the end that sends command to the command line. In the future, you may want to show the code you are using, it helps understand what's going wrong.
Both versions work fine on my side:
[DllImport("accore.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedCmd")] private static extern int acedCmd(System.IntPtr vlist); [CommandMethod("DxfInNet")] public void DxfInNet() { Document doc = Application.DocumentManager.MdiActiveDocument; object filedia = Application.GetSystemVariable("FILEDIA"); Application.SetSystemVariable("FILEDIA", 0); ResultBuffer rb = new ResultBuffer(); rb.Add(new TypedValue(5005, "_DXFIN")); rb.Add(new TypedValue(5005, "c:\\Temp\\test.dxf")); rb.Add(new TypedValue(5005, "")); acedCmd(rb.UnmanagedObject); Application.SetSystemVariable("FILEDIA", filedia); }
Regards,
Philippe.
Thanks - I didn't show any code because I was asking for example code, which is still the case. The only difference is that I'm using VB.net....but it's a pretty simple conversion in this case. Your acedCmd example is pretty much the same as the one I'd tried already....and I get the same result, which is nothing happening. I do see the command, but my dxf isn't open...It should be noted that my file name doesn't have the double slashes, but so far as I know, that's the way it should be with VB.net.....just for fun I tried it with the doubles and it didn't make any difference.
Here's what my command line looks like after:
Command: Download_SNB _DXFIN File name: N:\drawings\45756660R.DXF
Command:
Here is the VB.Net I used to test, no problem on my side. If this doesn't work for you, then I think it is beyond my competencies ...
<DllImport("accore.dll",
CharSet:=CharSet.Unicode,
CallingConvention:=CallingConvention.Cdecl,
EntryPoint:="acedCmd")> _ Private Shared Function acedCmd(ByVal vlist As IntPtr) As Integer End Function <CommandMethod("DXFINVB")> _ Public Sub DXFINVB() Dim rb As ResultBuffer = New ResultBuffer() rb.Add(New TypedValue(5005, "_DXFIN")) rb.Add(New TypedValue(5005, "c:\Temp\test.dxf")) acedCmd(rb.UnmanagedObject) End Sub
Usually invoking the commands with acedCommand / acedCmd has exactly the same effect than if you were typing them in the command line, but as you mehtioned DXFIN has a different behavior in that case. If you can get it done with VBA then stick with it. You can easily invoke the COM API from either a C# or VB.Net dll.
Regards,
Philippe.
Hi Philips:
I tried your C# code, but nothing happened, could you tried the attached solution by your side?
If it is stiil failed, could you change the code and let it run fine and save the entire solution and upload it?
Regards
swaywood
Can't find what you're looking for? Ask the community or share your knowledge.