editor.Command in 2015 einvalidinput error

editor.Command in 2015 einvalidinput error

marcwalen
Participant Participant
4,597 Views
5 Replies
Message 1 of 6

editor.Command in 2015 einvalidinput error

marcwalen
Participant
Participant

Hi all,

 

I.m trying to convert my 2012 code to 2015, but I'm having problems with a part of my code where I want to switch to modelspace. In 2012 I used 

ed.Command("_.TILEMODE", "1");

 This works as expected. But in 2015 this gives an 'einvalidinput' exception. After reading the ObjectArx 2015 documentation I changed that line to:

ed.Command(new Object[] { "_.TILEMODE", "1" });

 but that still gives an 'einvalidinput' exception. 

I also tried

Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("TILEMODE", 1);
 
oDoc.SendStringToExecute("_.TILEMODE 1 ", true, false, false);

 but both seem to do nothing.

 

Below is the entire code which is called from an UserControl within a paletteset:

private void exportbutton_Click(object sender, EventArgs e)
{
    string dwgFileName = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("DWGNAME") as string;
    string dwgPath = Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("DWGPREFIX") as string;

    string tmp = "TBX_" + dwgFileName.Remove(dwgFileName.Length - 4);

    SaveFileDialog saveFileDialog1 = new SaveFileDialog();
    saveFileDialog1.FileName = tmp;
    saveFileDialog1.InitialDirectory = dwgPath;
    saveFileDialog1.RestoreDirectory = true;
    saveFileDialog1.Filter = "Autocad dwg(*.dwg)|*.dwg";
    DialogResult result1 = saveFileDialog1.ShowDialog();

    if (result1 == DialogResult.OK)
    {
        try
        {
            Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
            db.SaveAs(saveFileDialog1.FileName, DwgVersion.Current);

            Document oDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(saveFileDialog1.FileName, false);
            var ed = oDoc.Editor;
                    

            string bordlaag = "";

            BordnrClass bnc = new BordnrClass();
            bordlaag = bnc.bordlaag();

            if (bordlaag == "")
            {
                bordlaag = "tekstborden";
            }

            TSNedTool.clsTSNed tscl = new TSNedTool.clsTSNed();

            using (Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
            {
                corelExportClass cec = new corelExportClass();
                cec.export_to_corel();

                UnlockLayersClass ul = new UnlockLayersClass();
                ul.UnlockAllLayers();

                BordColorClass bcc = new BordColorClass();
                bcc.Change_bord_color();

                SorteerBordenClass srtbrd = new SorteerBordenClass();
                srtbrd.SorteerBorden();

                tscl.ReScaleBorden();
                tscl.RotateBorden();
                tscl.LayersOnUnlockUnfrozen();
                tscl.CleanUpEverythingExceptBorden(bordlaag);

                tscl.CleanUpVisibility();
                tscl.LayersVerwijderen();
                //tscl.PurgeAll();

                //PurgeAll pg = new PurgeAll();
                //while (pg.purgeAll(db, false))
                //    continue;                        

                if (LayoutManager.Current.CurrentLayout != "Model")
                {
                    ed.Command("_.TILEMODE", "1");                            
                    //Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("TILEMODE", 1);
                    //ed.Command(new Object[] { "_.TILEMODE", "1" });  
                    //oDoc.SendStringToExecute("_.TILEMODE 1 ", true, false, false);
                }
                ed.Command("_.ZOOM", "EXTENTS");
                //ed.Command(new Object[] { "_.ZOOM", "EXTENTS" });                        
                //oDoc.SendStringToExecute("_.ZOOM EXTENTS ", true, false, false);

                oDoc.Editor.Regen();                        
            }
            oDoc.CloseAndSave(oDoc.Name);
            Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen();
        }
        catch(Autodesk.AutoCAD.Runtime.Exception ex)
        {
            MessageBox.Show("Fout bij exporteren naar Coreldraw bestand!", "Export error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
}

 

Am I using editor.command incorrectly, or is there something else I'm missing?

Accepted solutions (2)
4,598 Views
5 Replies
Replies (5)
Message 2 of 6

_gile
Consultant
Consultant
Accepted solution

Hi,

 

The Editor.Command() method requires arguments of the same type used in LISP (int, double, Point3d, ...), so, for the "tilemode" command, you have to pass an integer:

ed.Command("tilemeode", 1);

 

Anyway, I think it's a better practice to avoid calling commands when it's possible. In this case, it's quite easy using the DatabaseTileMode property:

if (!db.TileMode)
    db.TileMode = true;

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 6

SENL1362
Advisor
Advisor
i'll guess you're running into a bug.
Did you tried to only switch from paper to model, without other actions and the dialogs?
Some more tests you can do but i'm pretty sure it will make no difference.
//Goto Modelspace: Modelspace: Setvar.Tilemode=1
if (!db.TileMode)
db.TileMode=true;

Application..SetSystemVariable("CTAB", "Model");

0 Likes
Message 4 of 6

marcwalen
Participant
Participant

Changing 

ed.Command("TILEMODE", "1");

 to

ed.Command("TILEMODE", 1);

 didn't make any difference, stil eInvalidInput exception. But using

if (!db.TileMode)
{
    db.TileMode = true;
}

 works, so thank you for that, I didn't know about this possibility. Now all that remains is the 

ed.Command("ZOOM", "EXTENTS");
ed.Command(new Object[] { "_.ZOOM", "EXTENTS" });

 part. Both of these still give an eInvalidInput exception. Is there any other way to do this?

0 Likes
Message 5 of 6

marcwalen
Participant
Participant
Yes, its only switching to modelspace and then Zoom Extents. The only dialog is the SaveAs dialog at the start of the class.
0 Likes
Message 6 of 6

_gile
Consultant
Consultant
Accepted solution

For a zoom extents without calling the command, you can have a look to this code provided in the AutoCAD .NET Developer's Guide or these little extension methods.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub