Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to write a program to select some circles, and then zoom to those circles. So far I can select them, or I can zoom to them. But I cannot do both. I would like to know if someone can tell me what I have done wrong.
The following is a sample program that demonstrates the problem. It tries to select all the circles in the drawing, and then it tries to zoom to the circles:
[CommandMethod("Test_ZoomSelectCircle", CommandFlags.Session)]
public void TestZoomSelectCircle()
// Find all the circles in the drawing. Zoom to them, and select them.
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
// Find the Object-ID of all the circles.
List<ObjectId> lisCircleObjId = new List<ObjectId>();
lisCircleObjId = this.lisFindObjIdOfCircle();
// Zoom to the area where the circles are.
Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;
using( Transaction trans = db.TransactionManager.StartTransaction() )
{
// Get the 3D-coordinates of the area where the circles are.
var extSelObj = new Extents3d();
foreach( ObjectId idObj in lisCircleObjId )
{
Entity entObj = (Entity)trans.GetObject( idObj, OpenMode.ForRead );
if ( entObj != null )
{
extSelObj.AddExtents( entObj.GeometricExtents );
}
}
///////////////////////////////////
//// OPTION 1: This can zoom and select. But after the circles have been zoomed correctl,
//// the drawing was reversed back to the original location. This is like the
//// zoom has been reversed.
String sLowerLeftCornerCoord = extSelObj.MinPoint.X.ToString() + "," +
extSelObj.MinPoint.Y.ToString() + "," +
extSelObj.MinPoint.Z.ToString();
String sUpperRightCornerCoord = extSelObj.MaxPoint.X.ToString() + "," +
extSelObj.MaxPoint.Y.ToString() + "," +
extSelObj.MaxPoint.Z.ToString();
String sZoomCmd = "_.ZOOM _W " + sLowerLeftCornerCoord + " " + sUpperRightCornerCoord + " ";
dynamic appAcad = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
appAcad.ActiveDocument.SendCommand( sZoomCmd );
ed.SetImpliedSelection( lisCircleObjId.ToArray() );
///////////////////////////////////
}
} // TestZoomSelectCircle()
private List<ObjectId> lisFindObjIdOfCircle()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
List<ObjectId> lisObjectIdFound = new List<ObjectId>();
try
{
TypedValue[] aTypeValue = new TypedValue[]
{
new TypedValue( Convert.ToInt32( DxfCode.Start ), "CIRCLE" )
};
SelectionFilter oSF = new SelectionFilter( aTypeValue );
PromptSelectionResult oPSR = ed.SelectAll( oSF );
if ( oPSR.Status == PromptStatus.OK )
{
SelectionSet ssCircle = oPSR.Value;
foreach( SelectedObject oCircle in ssCircle )
{
lisObjectIdFound.Add( oCircle.ObjectId );
}
}
}
catch( System.Exception ex )
{
ed.WriteMessage( "\nError in getting ObjectId of all circles on the drawing. " +
"Error message is: " + ex.Message );
}
return( lisObjectIdFound );
}
The following are the various other options that I have tried:
///////////////////////////////////
//// OPTION 2: This can zoom; but cannot select.
String sLowerLeftCornerCoord = extSelObj.MinPoint.X.ToString() + "," +
extSelObj.MinPoint.Y.ToString() + "," +
extSelObj.MinPoint.Z.ToString();
String sUpperRightCornerCoord = extSelObj.MaxPoint.X.ToString() + "," +
extSelObj.MaxPoint.Y.ToString() + "," +
extSelObj.MaxPoint.Z.ToString();
String sZoomCmd = "_.ZOOM _W " + sLowerLeftCornerCoord + " " + sUpperRightCornerCoord + " ";
ed.Document.SendStringToExecute( sZoomCmd, true, false, true );
ed.SetImpliedSelection( lisCircleObjId.ToArray() );
///////////////////////////////////
///////////////////////////////////
//// OPTION 3: This cannot zoom; but can select.
dynamic appAcad = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
appAcad.ZoomWindow( extSelObj.MinPoint.ToArray(), extSelObj.MaxPoint.ToArray() );
ed.SetImpliedSelection( lisCircleObjId.ToArray() );
///////////////////////////////////
///////////////////////////////////
//// OPTION 4: This cannot zoom; but can select.
Autodesk.AutoCAD.Internal.Utils.SelectObjects( lisCircleObjId.ToArray() );
Autodesk.AutoCAD.Internal.Utils.ZoomObjects( false );
///////////////////////////////////
///////////////////////////////////
//// OPTION 5: This cannot zoom; but can select.
String sLowerLeftCornerCoord = extSelObj.MinPoint.X.ToString() + ", " +
extSelObj.MinPoint.Y.ToString() + ", " +
extSelObj.MinPoint.Z.ToString();
String sUpperRightCornerCoord = extSelObj.MaxPoint.X.ToString() + ", " +
extSelObj.MaxPoint.Y.ToString() + ", " +
extSelObj.MaxPoint.Z.ToString();
await ed.CommandAsync( "_.ZOOM", "W", sLowerLeftCornerCoord, sUpperRightCornerCoord );
ed.SetImpliedSelection( lisCircleObjId.ToArray() );
///////////////////////////////////
///////////////////////////////////
//// OPTION 6: This can select and zoom. But I have to hit ENTER to start zooming,
//// and the selection-grips disappears after zooming.
ed.SetImpliedSelection( lisCircleObjId.ToArray() );
await ed.CommandAsync( "_.ZOOM", "Object", "p", "" );
///////////////////////////////////
Please let me know the correct way to zoom and select the circles (or select and then zoom to the circles). Thanks.
JC_BL
Solved! Go to Solution.