.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need DXFIN command access (via acedCmd?)

11 REPLIES 11
Reply
Message 1 of 12
andrew_demerchant
732 Views, 11 Replies

Need DXFIN command access (via acedCmd?)

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??

11 REPLIES 11
Message 2 of 12

 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!

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 3 of 12

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.

Message 4 of 12

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.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 5 of 12

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:

 

Message 6 of 12

Oh - and this is a plugin application...
Message 7 of 12

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

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 8 of 12

Looks like the problem is that these commands don't actually mimic the real DXFIN command in cad. I tried them with a different dxf (a more normal one) and it does work fine. But the clue that it's not behaving like the dxfin command normally does is that the document name is still just "Drawing1.dwg", and not the name of the dxf. If you open CAD and run dxfin, the document name is the name of the dxf. So it seems that these commands don't actually run dxfin in the same way....I was able to do this in VBA, but am trying to port things over to .net....so far, it's not going well.
Message 9 of 12

Guess I'm sticking with VBA then.
Message 10 of 12

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.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 11 of 12

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

Message 12 of 12
swaywood
in reply to: swaywood

I think the code maybe effected by 32 bit or 64 bit system.
My system is 64Bit.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost