Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am trying to insert and update a block with a constrain parameter and see this change while the command is still active. Attached is the block "EL" that has constrain parameter "WIDTH" (default value of 8 which I would like to set in the command to 16 and update to the screen while the command is still active. I will have more code added at the end but wanted to have the block updated correctly. The block is inserted with "WIDTH" set to 8, and only when the program is exited the "WIDTH" is set to 16.
Thank you
using System; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Runtime; namespace ClassLibrary1 { public static class MyBlockReference { private static Document doc = Application.DocumentManager.MdiActiveDocument; public static BlockReference Insert(String name, Point3d point1) { try { using (Transaction trans = doc.Database.TransactionManager.StartTransaction()) { BlockTable bt = trans.GetObject(doc.Database.BlockTableId, OpenMode.ForRead) as BlockTable; ObjectId objId = bt[name]; BlockTableRecord btr = trans.GetObject(objId, OpenMode.ForRead) as BlockTableRecord; BlockReference br = new BlockReference(point1, objId); br.SetDatabaseDefaults(); Matrix3d ucs = doc.Editor.CurrentUserCoordinateSystem; br.TransformBy(ucs); BlockTableRecord ms = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; ms.AppendEntity(br); trans.AddNewlyCreatedDBObject(br, true); trans.Commit(); return br; } } catch (System.Exception ex) { doc.Editor.WriteMessage(ex.ToString() + "\nError in BlockReference.Insert() function!\nBlock Reference is null!"); return null; } } public static void SetParameter(BlockReference br, String parameterName, double num) { using (Transaction trans = doc.Database.TransactionManager.StartTransaction()) { BlockReference br1 = trans.GetObject(br.ObjectId, OpenMode.ForWrite) as BlockReference; if (br1 != null && br1.IsDynamicBlock) { DynamicBlockReferencePropertyCollection props = br1.DynamicBlockReferencePropertyCollection; foreach (DynamicBlockReferenceProperty prop in props) { if (prop.PropertyName == parameterName && !prop.ReadOnly) { prop.Value = num; } } } trans.Commit(); } } [CommandMethod("TestBlockFunctions")] public static void Test_Method() { PromptResult pr = doc.Editor.GetString("\nBlock name:"); if (pr.Status == PromptStatus.OK) { PromptPointOptions ppo = new PromptPointOptions("\nBlock position:"); PromptPointResult ppr = doc.Editor.GetPoint(ppo); if (ppr.Status == PromptStatus.OK) { BlockReference br = MyBlockReference.Insert(pr.StringResult, ppr.Value); if (br == null) { doc.Editor.WriteMessage("\nCommand aborted!"); return; } MyBlockReference.SetParameter(br, "WIDTH", 16); // HERE I WOULD LIKE AUTOCAD TO VISUALLY UPDATE THE WIDTH OF THE BLOCK TO 16. NOT WHEN EXITING THIS METHOD. // THIS IS ALL I FOUND ONLINE THAT WAS SUPPOSED TO HELP ME, AND DID NOT doc.TransactionManager.EnableGraphicsFlush(true); doc.TransactionManager.QueueForGraphicsFlush(); doc.TransactionManager.FlushGraphics(); Autodesk.AutoCAD.Internal.Utils.FlushGraphics(); doc.Editor.Regen(); doc.Editor.UpdateScreen(); ppo = new PromptPointOptions("\nHERE THE ELBOW NEEDED TO BE ALREADY 16 WIDE. \nCLICK AGAIN."); ppr = doc.Editor.GetPoint(ppo); } } } } }
Solved! Go to Solution.