Home > Back-end >  AutoCAD Command Line Spaces In Filename
AutoCAD Command Line Spaces In Filename

Time:03-14

I'm creating my own application to programmatically add a block from an external file into the model space. My custom command begins by asking the user to specify the filepath of the block to be inserted.

The problem is that the filepath has spaces in it, therefore AutoCAD command line accepts each space as pressing enter. Is there any way to suppress this issue for entering the filepath?

I'm hoping someone can help me out with the below code.

Thanks in advance.

        <CommandMethod("AddHardware")>
        Public Shared Sub Add_Hardware()
            Dim doc As Document = AutoCADApp.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor

            Using tr As Transaction = db.TransactionManager.StartTransaction()

                Dim FileName As String = ed.GetString("Filename").StringResult

CodePudding user response:

You can use a PromptStringOptions with Allowspaces = true. Apart from that, you should check the PromptResult.Satus value before going on.

var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var options = new PromptStringOptions("\nEnter the file name: ");
options.AllowSpaces = true;
var result = ed.GetString(options);
if (result.Status == PromptStatus.OK)
{
    string fileName = result.StringResult;
    // ...
}
  • Related