.NET c# send command synchron - AcDoc.Editor.Command

#1
Hi All,

//----------------------------------------------------
[CommandMethod("solp")]
public static void solp()
{
Document AcDoc = Application.DocumentManager.MdiActiveDocument;
AcadFuncVer.SwitchToModelSpace();
string CmdTxt = @"solprof all Yes No Yes Ja"; // Ja --- because german version
// AcDoc.SendStringToExecute(CmdTxt, true, true, true); it works but asyncron
AcDoc.Editor.Command(CmdTxt); // don't work
}
//----------------------------------------------------
An example it need a "Return" is helpfull to.

Thanks in advance.

Re: .NET c# send command synchron - AcDoc.Editor.Command

#2
Hi
Not sure I fully understand your idea. Please refer this example about editor.command:

Code: Select all

        [CommandMethod("ExDrawCircleFromPoints")]
        public static void ExDrawCircleFromPoints()
        {
            try
            {
                Document doc = IntelliCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
                Editor ed = doc.Editor;

                Point3d oPointA = new Point3d(5.0, 5.0, 0.0);
                Point3d oPointB = new Point3d(4.5, 4.5, 0.0);
                Point3d oPointC = new Point3d(10.0, 0.0, 0.0);

                ed.Command("CIRCLE", "3P", oPointA, oPointB, oPointC);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }

Re: .NET c# send command synchron - AcDoc.Editor.Command

#3
Thanks a lot :-)

"_circle" work but see this :

//----------------------------------------------------
[CommandMethod("ExLin")]
public static void ExDrawLine()
{
try
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Point3d oPointA = new Point3d(0, 0, 0);
Point3d oPointB = new Point3d(1000, 0, 0);
ed.Command("_LINE", oPointA, oPointB);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
//----------------------------------------------------

Here you see the problem, you can not send Key like SPACE RETURN ESC

Re: .NET c# send command synchron - AcDoc.Editor.Command

#5
Thanks a lot.
But I have to start by "Palette Button" in sessionmode this:
If I call from command line "t123_ed" (paperspace with auto vieport)
its work correct.
OutPut:
//---------------------------------------------------------------------------
BLOCK REC NAM : *Model_Space
BLOCK REC NAM : *Paper_Space
BLOCK REC NAM : *Paper_Space0
BLOCK REC NAM : A$2D5
LAY NAM : PV-2CF
//---------------------------------------------------------------------------
//----------------------------------------------------
[CommandMethod("t123_ed", CommandFlags.Session)]
public static void t0()
{
Document AcDoc = Application.DocumentManager.MdiActiveDocument;
AcDoc.Editor.Command("t1"); // activate viewport
AcDoc.Editor.Command("t2"); // run solprof (need t1 before)
AcDoc.Editor.Command("t3"); // check created blockref and its layername
}
//----------------------------------------------------
[CommandMethod("t1")]
public static void t1()
{
Document AcDoc = Application.DocumentManager.MdiActiveDocument;
AcDoc.Editor.Command("_mspace");
}
//----------------------------------------------------
[CommandMethod("t2")]
public static void t2()
{
Utils.ExecuteCommand("solprof", "all", " ", "Yes", "No", "Yes", " ");
}
//----------------------------------------------------------------------------------------
[CommandMethod("t3")]
public static void t3()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
ObjectIdCollection BlkRefObjIDs = new ObjectIdCollection(), ItrObjIDs = new ObjectIdCollection();
//----------------------------------------------------------------------------
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
BlockTable BlkTab = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\n");
//---------------------------------------------------------------------
foreach (ObjectId BlkTabRecObjID in BlkTab)
{
BlockTableRecord BlkTabRec = acTrans.GetObject(BlkTabRecObjID, OpenMode.ForRead) as BlockTableRecord;
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("BLOCK REC NAM : " + BlkTabRec.Name + "\n");
if (!BlkTabRec.IsLayout && !BlkTabRec.IsDynamicBlock)
{
ItrObjIDs = BlkTabRec.GetBlockReferenceIds(true, false);
foreach (ObjectId ItrObjID in ItrObjIDs)
{
BlockReference BlkRef = acTrans.GetObject(ItrObjID, OpenMode.ForRead) as BlockReference;
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("LAY NAM : " + BlkRef.Layer + "\n");
}
}
}
//----------------------------------------------------------------------
}
}
//----------------------------------------------------------------------------------------
cron