public static PromptNestedEntityThroughViewportResult GetNestedEntityThroughViewport(this Editor acadEditor, PromptNestedEntityThroughViewportOptions options) { Document acadDocument = acadEditor.Document; Database acadDatabase = acadDocument.Database; LayoutManager layoutManager = LayoutManager.Current; SelectThroughViewportJig stvpJig = new SelectThroughViewportJig(options); PromptResult pointResult = acadEditor.Drag(stvpJig); if (pointResult.Status == PromptStatus.OK) { Point3d pickedPoint = stvpJig.Result.Value; PromptNestedEntityOptions pneOpions = options.Options; pneOpions.NonInteractivePickPoint = pickedPoint; pneOpions.UseNonInteractivePickPoint = true; PromptNestedEntityResult pickResult = acadEditor.GetNestedEntity(pneOpions); if ((pickResult.Status == PromptStatus.OK) || (acadDatabase.TileMode) || (acadDatabase.PaperSpaceVportId != acadEditor.CurrentViewportObjectId)) { return(new PromptNestedEntityThroughViewportResult(pickResult)); } else { SelectionFilter vportFilter = new SelectionFilter(new TypedValue[] { new TypedValue(0, "VIEWPORT"), new TypedValue(-4, "!="), new TypedValue(69, 1), new TypedValue(410, layoutManager.CurrentLayout) }); PromptSelectionResult vportResult = acadEditor.SelectAll(vportFilter); if (vportResult.Status == PromptStatus.OK) { using (Transaction trans = acadDocument.TransactionManager.StartTransaction()) { foreach (ObjectId objectId in vportResult.Value.GetObjectIds()) { Viewport viewport = (Viewport)trans.GetObject(objectId, OpenMode.ForRead, false, false); if (viewport.ContainsPoint(pickedPoint)) { pneOpions.NonInteractivePickPoint = TranslatePointPsToMs(viewport, pickedPoint); pneOpions.UseNonInteractivePickPoint = true; acadEditor.SwitchToModelSpace(); Application.SetSystemVariable("CVPORT", viewport.Number); PromptNestedEntityResult pneResult = acadEditor.GetNestedEntity(pneOpions); acadEditor.SwitchToPaperSpace(); if (pneResult.Status == PromptStatus.OK) { return(new PromptNestedEntityThroughViewportResult(pneResult, objectId)); } } } } } return(new PromptNestedEntityThroughViewportResult(pickResult)); } } else { return(new PromptNestedEntityThroughViewportResult(pointResult)); } }