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

eInvalidInput when using DXFOUT method

5 REPLIES 5
Reply
Message 1 of 6
ConstantineS
2054 Views, 5 Replies

eInvalidInput when using DXFOUT method

I'm trying write VB.NET code to batch open a set of files and produce DXF files.  I am transitioning from VBA to VB.NET and still have a lot to learn, but I'm making some progress (slowly).  I have created a small version of the code that creates the error using a single file - see below.  Two sample files are attached below.  The "Without Viewport" file works fine.  The "With Viewport" file is the one that vauses the error and only under the conditions described below.

 

The strange thing is that the error only occurs when the code tries to save the DXF file while in a layout and in Paper Space and there is a viewport in the same layout.  It does not occur if you delete the viewport, or if you run the code when in a different layout, or in model space, or in floating model space.

 

I'm getting the following error:

 

eInvalidInput

--------

Application does not support just-in-time (JIT)
debugging. See the end of this message for details.

 

************** Exception Text **************
Autodesk.AutoCAD.Runtime.Exception: eInvalidInput
   at Autodesk.AutoCAD.DatabaseServices.Database.DxfOut(String fileName, Int32 precision, Boolean saveThumbnailImage)
   at ClassLibrary1.Class1.Test() in C:\Documents and Settings\TestUser\my documents\visual studio 2010\Projects\Test\Test\Class1.vb:line 35
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()

... 

 

 

Here is my code:

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime

Imports System.Windows.Forms

Public Class Class1
    <Autodesk.AutoCAD.Runtime.CommandMethod("runTest", CommandFlags.Session)> _
    Public Sub Test()

        Dim AddFiles As New OpenFileDialog
        Dim sFileName As String
        Dim NewFile As Document
        Dim tr As Autodesk.AutoCAD.DatabaseServices.Transaction

        AddFiles.ShowReadOnly = False
        AddFiles.Multiselect = False
        AddFiles.CheckFileExists = True
        AddFiles.Filter = "AutoCAD Files (*.dwg)|*.dwg|All Files (*.*)|*.*"
        AddFiles.FileName = ""
        AddFiles.InitialDirectory = "C:\"

        If AddFiles.ShowDialog() = DialogResult.Cancel Then
            Exit Sub
        End If

        sFileName = AddFiles.FileName

        NewFile = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open( _
            sFileName, False)

        sFileName = Strings.Left(sFileName, Strings.Len(sFileName) - 4)

        tr = NewFile.Database.TransactionManager.StartTransaction()
        Using (tr)
            NewFile.Database.DxfOut(sFileName & ".dxf", 16, True)
        End Using

        NewFile.CloseAndDiscard()

    End Sub
End Class

 

 I'm using VS2010 running AutoCAD 2010 on Win XP 32-bit.  This laptop has VS2010 installed.  I have also tesed on a desktop running AutoCAD 2010 on Win XP 64-bit and got the same results.  The desktop does not have VS installed.

 

I believe a work-around is to have the code switch to model space before trying to save the DXF file, but I would prefer finding the true solution and to learn how to avoid thee problem.

 

Any help is appreciated.

 

Thanks,

Constantine

 

 

5 REPLIES 5
Message 2 of 6
dan.glassman
in reply to: ConstantineS

Looks like it will succeed if you use a side database.

 

 

sFileName = AddFiles.FileName

Using tmpDb As New Database(False, True)
  tmpDb.ReadDwgFile(sFileName, FileShare.ReadWrite, True, "")
  tmpDb.DxfOut(Path.ChangeExtension(sFileName, "dxf"), 16, DwgVersion.Current)
End Using

Note that if you use this method, you don't need CommandFlags.Session. 

 

The "dxfout" command built into AutoCAD also succeeds.  So as an alternative to using a side database, you could keep CommandFlags.Session and use Document.SendStringToExecute().

 

Message 3 of 6
ConstantineS
in reply to: dan.glassman

Dan,

 

Thank you very much, that works!  Can you figure out or explain why the original code caused the error?

 

Also, I will be using the code in a batch process where it opens one file after another.  Doesn't that mean I should keep the CommandFlags.Session setting, so that the values of any varaibles are mantained across multiple files?

 

Thanks,

Constantine

Message 4 of 6
dan.glassman
in reply to: ConstantineS

I can't figure out why the original code would fail.  I will point out [in case it helps a more experienced developer explain] that if you use your original code, without CommandFlags.Session, and just export the active document (i.e. DocumentManager.MdiActiveDocument.Database.DxfOut(), it succeeds.

 

Regarding CommandFlags.Session, I don't think you need it if you use the "side database" technique.  My understanding is that you only need CommandFlags.Session if you'll be changing the active Document.  Using side databases, AutoCAD won't even create a Document object for the files you open -- hence no Session required despite the fact that you're processing multiple files.

 

-drg

Message 5 of 6
ConstantineS
in reply to: dan.glassman

Dan,

 

Thank you.  I'm doing more thorough testing today, but so far the batch process is working well.  One of the benefits of using the "side database" is that it runs MUCH faster.  Although I miss seeing the files open and close on the screen.

 

Constantine

Message 6 of 6
01688686718
in reply to: ConstantineS

hey, i'm have error in here:

Dim oHatch As New Hatch()
oHatch.SetDatabaseDefaults()
Dim normal As New Vector3d(0.0, 0.0, 1.0)
oHatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID")
oHatch.ColorIndex = 8
oHatch.AppendLoop(HatchLoopTypes.Default, ObjIds)
oHatch.EvaluateHatch(True)
ents.Add(oHatch)

 

cad show megbox: eInvalidInput. Please help me

ko0ls

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