Hi,
Is there a way to modify the properties of a dynamic block after the insert and before a jig?
I've tried a quite a few things but here is some code as a starting point. The blocks are affected by the change but not in a good way. The blocks have several parametric constraints. I wonder if this is part of the problem.
<CommandMethod("TestEntityJigger7")> _ Public Shared Sub TestEntityJigger7_Method() Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim db As Database = HostApplicationServices.WorkingDatabase Dim pr As PromptResult = ed.GetString(vbLf & "Block name:") If pr.Status = PromptStatus.OK Then Using tr As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = TryCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable) Dim btr As BlockTableRecord = TryCast(tr.GetObject(bt(pr.StringResult), OpenMode.ForRead), BlockTableRecord) If btr IsNot Nothing Then Dim br As New BlockReference(New Point3d(0, 0, 0), btr.ObjectId) Dim pc As DynamicBlockReferencePropertyCollection = br.DynamicBlockReferencePropertyCollection For i = 0 To pc.Count - 1 Dim prop As DynamicBlockReferenceProperty = pc(i) If prop.PropertyName = "A" Then prop.Value = 1000.0# If prop.PropertyName = "B" Then prop.Value = 2000.0# Next pc.Dispose() If BlockMovingRotating.Jig(br) Then Dim modelspace As BlockTableRecord = TryCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord) modelspace.AppendEntity(br) tr.AddNewlyCreatedDBObject(br, True) tr.Commit() Else tr.Abort() End If End If End Using End If End Sub
Also try this code, not tested
<CommandMethod("TestEntityJigger7")> _ Public Shared Sub TestEntityJigger7_Method() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim db As Database = HostApplicationServices.WorkingDatabase doc.TransactionManager.EnableGraphicsFlush(True) Dim pr As PromptResult = ed.GetString(vbLf & "Block name:") If pr.Status = PromptStatus.OK Then Using tr As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = TryCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable) Dim btr As BlockTableRecord = TryCast(tr.GetObject(bt(pr.StringResult), OpenMode.ForRead), BlockTableRecord) If btr IsNot Nothing Then Dim br As New BlockReference(New Point3d(0, 0, 0), btr.ObjectId) Dim pc As DynamicBlockReferencePropertyCollection = br.DynamicBlockReferencePropertyCollection For i = 0 To pc.Count - 1 Dim prop As DynamicBlockReferenceProperty = pc(i) If prop.PropertyName = "A" Then prop.Value = 1000.0# If prop.PropertyName = "B" Then prop.Value = 2000.0# Next pc.Dispose() tr.TransactionManager.QueueForGraphicsFlush() If BlockMovingRotating.Jig(br) Then Dim modelspace As BlockTableRecord = TryCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord) modelspace.AppendEntity(br) tr.AddNewlyCreatedDBObject(br, True) tr.TransactionManager.QueueForGraphicsFlush() doc.TransactionManager.FlushGraphics() tr.Commit() End If End If End Using End If End Sub
Hi Hallex,
It didn't seem to help. The dynamic grip points are not updated with the newly defined lengths.
And the properties palette
I can work around this by deleting the block reference and inserting a fresh one with the results from the jig.
The big problem is that I can't get the block to display properly for the jig in most cases.
Attached is an example.
Including a dimension change for the C parameter shows the problem.
If prop.PropertyName = "A" Then prop.Value = 1000.0# If prop.PropertyName = "B" Then prop.Value = 2000.0# If prop.PropertyName = "C" Then prop.Value = 3000.0#
If inserted without using a jig it seems to be fine, AutoCAD must analyse the constraints within a block more thoroughly and properly kick everything into position.
Hi DiningPhilosopher,
I made that change. The jigged object is now inserted correctly (modified with grips in the correct place) but it's still not displaying the modified block within the jig (just the block definition). It is an improvement but hopeing there's a solution still.
Using trans As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = TryCast(trans.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable) Dim btr As BlockTableRecord = TryCast(trans.GetObject(bt(BlockName), OpenMode.ForRead), BlockTableRecord) If btr IsNot Nothing Then Dim br As New BlockReference(New Point3d(0, 0, 0), btr.ObjectId) Dim modelspace As BlockTableRecord = TryCast(trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord) modelspace.AppendEntity(br) trans.AddNewlyCreatedDBObject(br, True) Dim pc As DynamicBlockReferencePropertyCollection = br.DynamicBlockReferencePropertyCollection For i = 0 To pc.Count - 1 Dim prop As DynamicBlockReferenceProperty = pc(i) If prop.PropertyName = "A" Then prop.Value = 500.0# If prop.PropertyName = "B" Then prop.Value = 500.0# If prop.PropertyName = "C" Then prop.Value = 500.0# Next trans.TransactionManager.QueueForGraphicsFlush() doc.TransactionManager.FlushGraphics() If AcadNetAddinWizard_Namespace.BlockMovingRotating.Jig(br) Then End If trans.Commit() End If End Using
You should set the DynamicBlockReferenceProperty's outside of your Transaction, after the commit.
Hi Fenton,
I'd like the modified block to display as modified before the jigging.
I've have tried modifying the blockreference within a seperate transaction and comitting it before the jig.
FlushGraphics doesn't seem to work.
FlushGraphics also shows the block at the insertion point until after the jig.
No idea why I can't get this to work.
Hello,
This behavior seems specific to the drawing that you attached. I could not reproduce it with a simple dynamic block that I was using to test this behavior. I have attached a test drawing with the dynamic block that I created.
I may be missing some of the details of your dynamic block.
A workaround in your case could be to have two custom commands. Not an elegant solution, but it worked ok with your drawing.
ObjectId _brefId = ObjectId.Null; [CommandMethod("Test1")] public void Test1() { // Insert the block reference and set the parameters // Store the ObjectId of the block ref in _brefId // Call another command to jig the inserted block reference Application.DocumentManager.MdiActiveDocument.SendStringToExecute("Test2 ", false, false, false); } [CommandMethod("Test2")] public void Test2() { // Use _brefId to access the inserted block reference // Jig the block reference and set its transform }
Can't find what you're looking for? Ask the community or share your knowledge.