I have a dynamic block of a steel beam, with a block table, by which I can change the size etc.
public static void InsertBlock(Database db, string FileName, Point3d InsertionPoint, double Rotation = 0) { ObjectId blkid = ObjectId.Null; using (Database bdb = new Database(false, true)) { bdb.ReadDwgFile(FileName, System.IO.FileShare.Read, true, ""); blkid = db.Insert(System.IO.Path.GetFileNameWithoutExtension(FileName), bdb, true); using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = default(BlockTableRecord); btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); using (btr) { BlockReference bref = new BlockReference(InsertionPoint, blkid); using (bref) { if (bref.IsDynamicBlock) { DynamicBlockReferencePropertyCollection dynBrefColl = bref.DynamicBlockReferencePropertyCollection; foreach (DynamicBlockReferenceProperty dynBrefProps in dynBrefColl) { if (dynBrefProps.PropertyName == "Name") { dynBrefProps.Value = "150UB18.0"; } } } Matrix3d mat = Matrix3d.Identity; bref.TransformBy(mat); bref.Layer = "0"; bref.Rotation = Rotation; btr.AppendEntity(bref); tr.AddNewlyCreatedDBObject(bref, true); } } tr.Commit(); } } }
Once the beam is placed from this code, I can change the size from the list, but there is no physical change.
If I comment out,
dynBrefProps.Value = "150UB18.0";
the size will change when I select it. The 150UB18.0 is in the list when you call GetAllowedValues for the Name.
Does anyone know how to successfully set a value? I have looked at
GetAllowedValues().SetValue(object value, int index) but not too sure how this one works.
Solved! Go to Solution.
Solved by hgasty1001. Go to Solution.
Hi,
I think you need to append the blockreference and add it to the transaction *BEFORE* to access and edit the dynamic properties, after that you need to call UpdateAnonymousBlocks() and commit the tranasaction.
Gaston Nunez
Here is the snippet. I replaced the original Using with this one.
using (btr) { bref = new BlockReference(InsertionPoint, blockID); btr.AppendEntity(bref); using (bref) { if (bref.IsDynamicBlock) { DynamicBlockReferencePropertyCollection dynBrefColl = bref.DynamicBlockReferencePropertyCollection; foreach (DynamicBlockReferenceProperty dynBrefProps in dynBrefColl) { if (dynBrefProps.PropertyName == "Name") { dynBrefProps.Value = "150UB18.0"; } } } Matrix3d mat = Matrix3d.Identity; bref.TransformBy(mat); bref.Layer = "0"; bref.Rotation = Rotation; tr.AddNewlyCreatedDBObject(bref, true); } }