.NET

Reply
Active Member
andrew.demerchant
Posts: 7
Registered: ‎03-29-2010
Message 1 of 12 (243 Views)

Need DXFIN command access (via acedCmd?)

243 Views, 11 Replies
03-13-2014 11:15 AM

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

ADN Support Specialist
philippe.leefsma
Posts: 576
Registered: ‎06-02-2009
Message 2 of 12 (205 Views)

Re: Need DXFIN command access (via acedCmd?)

03-16-2014 01:31 PM in reply to: andrew.demerchant

 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

Active Member
andrew.demerchant
Posts: 7
Registered: ‎03-29-2010
Message 3 of 12 (182 Views)

Re: Need DXFIN command access (via acedCmd?)

03-17-2014 05:11 AM in reply to: philippe.leefsma

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.

ADN Support Specialist
philippe.leefsma
Posts: 576
Registered: ‎06-02-2009
Message 4 of 12 (177 Views)

Re: Need DXFIN command access (via acedCmd?)

03-17-2014 06:17 AM in reply to: andrew.demerchant

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

Active Member
andrew.demerchant
Posts: 7
Registered: ‎03-29-2010
Message 5 of 12 (172 Views)

Re: Need DXFIN command access (via acedCmd?)

03-17-2014 06:52 AM in reply to: philippe.leefsma

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:

 

Active Member
andrew.demerchant
Posts: 7
Registered: ‎03-29-2010
Message 6 of 12 (171 Views)

Re: Need DXFIN command access (via acedCmd?)

03-17-2014 06:52 AM in reply to: andrew.demerchant
Oh - and this is a plugin application...
ADN Support Specialist
philippe.leefsma
Posts: 576
Registered: ‎06-02-2009
Message 7 of 12 (163 Views)

Re: Need DXFIN command access (via acedCmd?)

03-17-2014 07:13 AM in reply to: andrew.demerchant

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

Active Member
andrew.demerchant
Posts: 7
Registered: ‎03-29-2010
Message 8 of 12 (156 Views)

Re: Need DXFIN command access (via acedCmd?)

03-17-2014 07:37 AM in reply to: philippe.leefsma
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.
Active Member
andrew.demerchant
Posts: 7
Registered: ‎03-29-2010
Message 9 of 12 (134 Views)

Re: Need DXFIN command access (via acedCmd?)

03-18-2014 09:44 AM in reply to: andrew.demerchant
Guess I'm sticking with VBA then.
ADN Support Specialist
philippe.leefsma
Posts: 576
Registered: ‎06-02-2009
Message 10 of 12 (124 Views)

Re: Need DXFIN command access (via acedCmd?)

03-18-2014 02:24 PM in reply to: andrew.demerchant

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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community