public static void ChangeEntColour() { // // Get some user input: // _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; _AcEd.PromptEntityResult res = ed.GetEntity("Select an entity to change its colour:"); if (res.Status == _AcEd.PromptStatus.OK) { var entId = res.ObjectId; var db = _AcDb.HostApplicationServices.WorkingDatabase; using (var tr = db.TransactionManager.StartTransaction()) { var ent = tr.GetObject(entId, Teigha.DatabaseServices.OpenMode.ForWrite) as _AcDb.Entity; // // Ask the user for the new colour number // _AcEd.PromptIntegerResult intres = ed.GetInteger("\nEnter new colorindex integer (0 -> 255): "); if (intres.Status == _AcEd.PromptStatus.OK) { ent.ColorIndex = intres.Value; } tr.Commit(); } } }
static public void GetXData() { AcAp.Document doc = AcApp.DocumentManager.MdiActiveDocument; AcEd.Editor ed = doc.Editor; AcEd.PromptEntityOptions opt = new AcEd.PromptEntityOptions("\nSelect entity: "); AcEd.PromptEntityResult res = ed.GetEntity(opt); if (res.Status == AcEd.PromptStatus.OK) { using (AcDb.Transaction tr = doc.TransactionManager.StartTransaction()) { AcDb.DBObject obj = tr.GetObject(res.ObjectId, AcDb.OpenMode.ForRead); AcDb.ResultBuffer rb = obj.XData; if (rb == null) { ed.WriteMessage("\nEntity does not have XData attached."); } else { int n = 0; foreach (AcDb.TypedValue tv in rb) { ed.WriteMessage("\nTypedValue {0} - type: {1}, value: {2}", n++, tv.TypeCode, tv.Value); } rb.Dispose(); } } } }
static public void DynamicBlockProps() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; _AcEd.PromptStringOptions pso = new _AcEd.PromptStringOptions("\nEnter dynamic block name or enter to select: "); pso.AllowSpaces = true; _AcEd.PromptResult pr = ed.GetString(pso); if (pr.Status != _AcEd.PromptStatus.OK) { return; } _AcDb.Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { _AcDb.BlockReference br = null; // If a null string was entered allow entity selection if (pr.StringResult == "") { // Select a block reference _AcEd.PromptEntityOptions peo = new _AcEd.PromptEntityOptions("\nSelect dynamic block reference: "); peo.SetRejectMessage("\nEntity is not a block."); peo.AddAllowedClass(typeof(_AcDb.BlockReference), false); _AcEd.PromptEntityResult per = ed.GetEntity(peo); if (per.Status != _AcEd.PromptStatus.OK) { return; } // Access the selected block reference br = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference; } else { // Otherwise we look up the block by name _AcDb.BlockTable bt = tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead) as _AcDb.BlockTable; if (!bt.Has(pr.StringResult)) { ed.WriteMessage("\nBlock \"" + pr.StringResult + "\" does not exist."); return; } // Create a new block reference referring to the block br = new _AcDb.BlockReference(new _AcGe.Point3d(), bt[pr.StringResult]); } _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(br.DynamicBlockTableRecord, _AcDb.OpenMode.ForRead); // Call our function to display the block properties DisplayDynBlockProperties(ed, br, btr.Name); // Committing is cheaper than aborting tr.Commit(); } }
static public void SetXData() { AcAp.Document doc = AcApp.DocumentManager.MdiActiveDocument; AcEd.Editor ed = doc.Editor; AcEd.PromptEntityOptions opt = new AcEd.PromptEntityOptions("\nSelect entity: "); AcEd.PromptEntityResult res = ed.GetEntity(opt); if (res.Status == AcEd.PromptStatus.OK) { using (AcDb.Transaction tr = doc.TransactionManager.StartTransaction()) { AcDb.DBObject obj = tr.GetObject(res.ObjectId, AcDb.OpenMode.ForWrite); AddRegAppTableRecord("KEAN"); AcDb.ResultBuffer rb = new AcDb.ResultBuffer( new AcDb.TypedValue(1001, "KEAN"), new AcDb.TypedValue(1000, "This is a test string") ); obj.XData = rb; rb.Dispose(); tr.Commit(); } } }
static public void ZoomToEntity() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; // Get the entity to which we'll zoom _AcEd.PromptEntityOptions peo = new _AcEd.PromptEntityOptions( "\nSelect an entity:" ); _AcEd.PromptEntityResult per = ed.GetEntity(peo); if (per.Status != _AcEd.PromptStatus.OK) { return; } // Extract its extents _AcDb.Extents3d ext; _AcDb.Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { _AcDb.Entity ent = (_AcDb.Entity)tr.GetObject( per.ObjectId, _AcDb.OpenMode.ForRead ); ext = ent.GeometricExtents; tr.Commit(); } ext.TransformBy( ed.CurrentUserCoordinateSystem.Inverse() ); // Call our helper function // [Change this to ZoomWin2 or WoomWin3 to // use different zoom techniques] ZoomWin(ed, ext.MinPoint, ext.MaxPoint); }
static public void Plan2AutoIdSelPolygonLayer() { try { if (!OpenAutoIdPalette()) { return; } var opts = Globs.TheAutoIdOptions; _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { _AcAp.DocumentCollection dm = _AcAp.Application.DocumentManager; if (doc == null) { return; } _AcEd.Editor ed = doc.Editor; #if NEWSETFOCUS doc.Window.Focus(); #else Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView(); // previous 2014 AutoCAD - Versions #endif _AcEd.PromptNestedEntityOptions peo = new _AcEd.PromptNestedEntityOptions("\nPolylinie wählen: "); //peo.SetRejectMessage("\nDas gewählte Element ist keine Polylinie."); //peo.AddAllowedClass(typeof(Polyline), true); //peo.AddAllowedClass(typeof(Polyline2d), true); //peo.AddAllowedClass(typeof(Polyline3d), true); _AcEd.PromptEntityResult per = ed.GetNestedEntity(peo); if (per.Status == _AcEd.PromptStatus.OK) { using (var tr = doc.TransactionManager.StartTransaction()) { _AcDb.DBObject obj = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead); _AcDb.Entity ent = obj as _AcDb.Entity; if (ent != null) { if (ent is _AcDb.Polyline || ent is _AcDb.Polyline2d || ent is _AcDb.Polyline3d) { opts.SetPolygonLayer(Engine.RemoveXRefPart(ent.Layer)); } else { ed.WriteMessage("\nDas gewählte Element ist keine Polylinie."); } } tr.Commit(); } } } } catch (System.Exception ex) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2AutoIdSelPolygonLayer aufgetreten! {0}", ex.Message)); } }