using System.Collections.Generic;
using System.Linq;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using DrawingSynchronizer;
namespace ClassLibrary5
{
public class Class1
{
[CommandMethod("bll")]
public static void SetDynamicBlockProperty()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
List<Entity> blockNames = SelectObjectsOnScreen();
ObjectIdCollection ids = new ObjectIdCollection();
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockReference bref = tr.GetObject(blockNames.First().ObjectId, OpenMode.ForWrite, false, true) as BlockReference;
ids.Add(bref.BlockTableRecord);
if (bref.IsDynamicBlock)
{
double ang = -1011;
BlockTableRecord dynBtr = (BlockTableRecord)tr.GetObject(bref.DynamicBlockTableRecord, OpenMode.ForWrite, false, true);
DynamicBlockReferencePropertyCollection props = bref.DynamicBlockReferencePropertyCollection;
foreach (DynamicBlockReferenceProperty prop in props)
{
// object[] values = prop.GetAllowedValues();
//Switch Property
if (prop.PropertyName.Contains("Visibility") && !prop.ReadOnly)
{
if (prop.Value.ToString() == Selector.VisibilityStates.Removed)
{
prop.Value = Selector.VisibilityStates.Fitted;
}
if (prop.Value.ToString() == Selector.VisibilityStates.Hole)
{
prop.Value = Selector.VisibilityStates.HorizontalManhole;
}
if (prop.Value.ToString() == Selector.VisibilityStates.Projection)
{
prop.Value = Selector.VisibilityStates.Projection;
}
}
}
}
tr.Commit();
}
ed.Regen();
}
public static List<Entity> SelectObjectsOnScreen()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Transaction tr = db.TransactionManager.StartTransaction();
List<Entity> listOfEntities = new List<Entity>();
using (tr)
{
// Request for objects to be selected in the drawing area
PromptSelectionResult PrSeRes = doc.Editor.GetSelection();
// If the prompt status is OK, objects were selected
if (PrSeRes.Status == PromptStatus.OK)
{
SelectionSet SelSet = PrSeRes.Value;
// Step through the objects in the selection set
foreach (SelectedObject SelObj in SelSet)
{
// Check to make sure a valid SelectedObject object was returned
if (SelObj != null)
{
// Open the selected object for write
Entity entity = (Entity)tr.GetObject(SelObj.ObjectId, OpenMode.ForRead, false, true);
if (entity != null)
{
listOfEntities.Add(entity);
}
}
}
}
tr.Commit();
}
return listOfEntities;
}
}
}
namespace DrawingSynchronizer
{
public class Selector
{
public struct VisibilityStates
{
public static readonly string Fitted = "Fitted";
public static readonly string Removed = "Removed";
public static readonly string Hole = "Hole";
public static readonly string HorizontalManhole = "Horizontal manhole";
public static readonly string Projection = "Projection";
}
}
}