Hi, guys
I can't fix my problem entire the day, it's
driving me mad ...
What's wrong with my code snip?
At the first glance even thouh
/// <summary>
///
/// </summary>
[CommandMethod("DBB", CommandFlags.UsePickSet)]
public void ChangeDynBlock()
{
Document oDoc = AcadApp.DocumentManager.MdiActiveDocument;
Editor ed = oDoc.Editor;
using (DocumentLock dlock = oDoc.LockDocument(DocumentLockMode.Write, "", "DBB", false))
{
using (Database db = HostApplicationServices.WorkingDatabase)
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
try
{
BlockTable bt = (BlockTable)(trans.GetObject(db.BlockTableId, OpenMode.ForRead));
PromptSelectionOptions pso = new PromptSelectionOptions();
pso.SingleOnly = true;
pso.MessageForRemoval = "\nWrong selection. Try again!";
pso.MessageForAdding = "\nSelect block:";
PromptSelectionResult pr = ed.GetSelection(pso);
if (pr == null)
return;
SelectionSet ss = pr.Value;
ObjectId[] oids = ss.GetObjectIds();
ObjectId id = oids[0];
BlockReference bref = (BlockReference)trans.GetObject(id, OpenMode.ForRead);
DynamicBlockReferencePropertyCollection dpcoll = bref.DynamicBlockReferencePropertyCollection;
for (int n = 0; n < dpcoll.Count; n++)//iteration is just for the future programm
{
DynamicBlockReferenceProperty vizz = dpcoll[n];
switch (vizz.PropertyName.ToUpper())
{
case "VISIBILITY":
Object[] props = vizz.GetAllowedValues();
PromptKeywordOptions pko = new PromptKeywordOptions("");
for (int m = 0; m < props.Length; m++)
pko.Keywords.Add(props[m].ToString());
pko.Keywords.Default = props[0].ToString();
pko.AllowArbitraryInput = true;
pko.AllowNone = true;
pko.Message = "\nChoose a visibility color ";// setup your message to suit
pko.AppendKeywordsToMessage = true;
PromptResult prr = ed.GetKeywords(pko);
string typ = prr.StringResult.ToString();
vizz.Value = typ;
break;
}
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
MessageBox.Show(ex.Message +
"------------------------------------------" +
ex.StackTrace);
}
trans.Commit();
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="tr"></param>
/// <param name="blkref"></param>
/// <returns></returns>
public string EffectiveName(Transaction tr, BlockReference blkref)
{
if (blkref.IsDynamicBlock)
{
using (BlockTableRecord obj = (BlockTableRecord)
tr.GetObject(blkref.DynamicBlockTableRecord, OpenMode.ForRead))
return obj.Name;
}
return blkref.Name;
}
~'J'~