//
切换三维视图
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmd3D : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
Transaction ts = new Transaction(uiDoc.Document, " Change3D ");
try
{
ts.Start();
View3D view3D = uiDoc.Document.Create.NewView3D( new XYZ(- 1, 1, - 1)); // 斜视45度
ts.Commit();
// 切换视图必须在事务结束后,否则会提示错误:
// Cannot change the active view of a modifiable document
uiDoc.ActiveView = view3D;
}
catch (Exception ex)
{
TaskDialog.Show( " ex ", ex.ToString());
ts.RollBack();
}
return Result.Succeeded;
}
}
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmd3D : IExternalCommand
{
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.ActiveUIDocument;
Transaction ts = new Transaction(uiDoc.Document, " Change3D ");
try
{
ts.Start();
View3D view3D = uiDoc.Document.Create.NewView3D( new XYZ(- 1, 1, - 1)); // 斜视45度
ts.Commit();
// 切换视图必须在事务结束后,否则会提示错误:
// Cannot change the active view of a modifiable document
uiDoc.ActiveView = view3D;
}
catch (Exception ex)
{
TaskDialog.Show( " ex ", ex.ToString());
ts.RollBack();
}
return Result.Succeeded;
}
}