Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am using a toolbar to display a number of grid sizes that I commonly switch between. I am using this function to loop though all viewports and change the gird size on all of them when the button is pressed on the toolbar.
void SetGrid(double size, short spacing)
{
// Get AutoCAD objects.
Document doc = Application.DocumentManager.MdiActiveDocument;
KernelDescriptor kd = new KernelDescriptor();
Database database = doc.Database;
Autodesk.AutoCAD.EditorInput.Editor ed = doc.Editor;
// Get the current CVPORT.
int currentCVPORT = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"));
// Get the other View Ports.
List<int> viewPortNumbers = new List<int>();
using (Transaction transaction = database.TransactionManager.StartTransaction())
{
SymbolTable symTable = (SymbolTable)transaction.GetObject(database.ViewportTableId, OpenMode.ForRead);
foreach (ObjectId id in symTable)
{
ViewportTableRecord symbol = (ViewportTableRecord)transaction.GetObject(id, OpenMode.ForWrite);
viewPortNumbers.Add(symbol.Number);
symbol.GridEnabled = true;
symbol.GridIncrements = new Autodesk.AutoCAD.Geometry.Point2d(size, size);
symbol.GridMajor = spacing;
symbol.SnapIncrements = new Autodesk.AutoCAD.Geometry.Point2d(size, size);
}
transaction.Commit();
doc.Editor.UpdateTiledViewportsFromDatabase();
}
// Switch back to original view port.
Application.SetSystemVariable("CVPORT", currentCVPORT);
}
It seems to work except for if there is another command already in progress. I was wondering how I can cancel the previous command if there is one via .net?
Solved! Go to Solution.