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(); } }
private static bool GetNewText(_AcEd.Editor ed) { var prompt = new _AcEd.PromptStringOptions("\nNeuer Text: "); prompt.AllowSpaces = true; var prefixUserRes = ed.GetString(prompt); if (prefixUserRes.Status != _AcEd.PromptStatus.OK) { return(false); } _NewText = prefixUserRes.StringResult; return(true); }
/// <summary> /// Öffnen einer Dwg ohne Editor /// </summary> //[_AcTrx.CommandMethod("Plan2TestSideDb")] static public void Plan2TestSideDb() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcEd.Editor ed = doc.Editor; // Ask the user to select a file _AcEd.PromptResult res = ed.GetString("\nEnter the path of a DWG or DXF file: "); if (res.Status == _AcEd.PromptStatus.OK) { // Create a database and try to load the file _AcDb.Database db = new _AcDb.Database(false, true); using (db) { try { db.ReadDwgFile(res.StringResult, System.IO.FileShare.Read, false, ""); } catch (System.Exception) { ed.WriteMessage("\nUnable to read drawing file."); return; } _AcDb.Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { // Open the blocktable, get the modelspace _AcDb.BlockTable bt = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead); _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(bt[_AcDb.BlockTableRecord.ModelSpace], _AcDb.OpenMode.ForRead); // Iterate through it, dumping objects foreach (_AcDb.ObjectId objId in btr) { _AcDb.Entity ent = (_AcDb.Entity)tr.GetObject(objId, _AcDb.OpenMode.ForRead); // Let's get rid of the standard namespace const string prefix = "Autodesk.AutoCAD.DatabaseServices."; string typeString = ent.GetType().ToString(); if (typeString.Contains(prefix)) { typeString = typeString.Substring(prefix.Length); } ed.WriteMessage("\nEntity " + ent.ObjectId.ToString() + " of type " + typeString + " found on layer " + ent.Layer + " with colour " + ent.Color.ToString()); } } } } }
private static bool GetOldText(_AcEd.Editor ed) { var prompt = new _AcEd.PromptStringOptions("\nZu ersetzender Text: "); prompt.AllowSpaces = true; while (string.IsNullOrEmpty(_OldText)) { var prefixUserRes = ed.GetString(prompt); if (prefixUserRes.Status != _AcEd.PromptStatus.OK) { return(false); } _OldText = prefixUserRes.StringResult; } return(true); }
private static bool GetAttributeInfos(_AcEd.Editor ed, _AcAp.Document doc) { bool ok = false; _BlockName = string.Empty; _AttributeName = string.Empty; _AttributeValue = string.Empty; _AcEd.PromptNestedEntityResult per = ed.GetNestedEntity("\nZu änderndes Attribut wählen: "); if (per.Status == _AcEd.PromptStatus.OK) { using (var tr = doc.TransactionManager.StartTransaction()) { _AcDb.DBObject obj = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead); _AcDb.AttributeReference ar = obj as _AcDb.AttributeReference; if (ar != null && !ar.IsConstant) { _AcDb.BlockReference br = Plan2Ext.Globs.GetBlockFromItsSubentity(tr, per); if (br != null) { ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nBlockname: {0}, Attributname: {1}.", Plan2Ext.Globs.GetBlockname(br, tr), ar.Tag)); var prompt = new _AcEd.PromptStringOptions("\nText in Attribut: "); prompt.AllowSpaces = true; var prefixUserRes = ed.GetString(prompt); if (prefixUserRes.Status == _AcEd.PromptStatus.OK) { _AttributeValue = prefixUserRes.StringResult; _AttributeName = ar.Tag; _BlockName = Plan2Ext.Globs.GetBlockname(br, tr); log.InfoFormat(CultureInfo.CurrentCulture, "Block: {0}, Attribut: {1}, Wert: '{2}'", _BlockName, _AttributeName, _AttributeValue); ok = true; } } } tr.Commit(); } } return(ok); }