Thanks Jeff , I translated Your Code to Vb( Using those Web Tools , I have no Idea about C#) , and code is working.
The hard part is a connection between 2 objects. I am just struggle to find a way to link 2 different objects on drawing.
How would it be possible? something similar to group command in autocad.
But we need some common Identification for all objects inside the group. What is that Identifiation?
I thought maybe a uniqe group name will help. Like when user change something. program looks to find what group it belongs to ?
This is basic thing I am thinking. Any idea ?
Below is Jeff code in Vb. This would be one of my Function in Future Program for sure.
==============================
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Module JeffCode1
<CommandMethod("DynamicBlocksThingy")> _
Public Sub DynamicBlocksThingy()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Using trx As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = TryCast(db.BlockTableId.GetObject(OpenMode.ForRead), BlockTable)
For Each objId As ObjectId In bt
Dim btr As BlockTableRecord = DirectCast(objId.GetObject(OpenMode.ForRead), BlockTableRecord)
If btr.IsDynamicBlock Then
Dim brefObjidColl As ObjectIdCollection = btr.GetBlockReferenceIds(True, True)
Dim anonObjIdsColl As ObjectIdCollection = btr.GetAnonymousBlockIds()
For Each anonObjId As ObjectId In anonObjIdsColl
Dim btrAnon As BlockTableRecord = DirectCast(anonObjId.GetObject(OpenMode.ForRead), BlockTableRecord)
Dim ObjidColl As ObjectIdCollection = btrAnon.GetBlockReferenceIds(True, True)
For Each Id As ObjectId In ObjidColl
brefObjidColl.Add(Id)
Next
Next
For Each brefObjId As ObjectId In brefObjidColl
Dim bref As BlockReference = TryCast(brefObjId.GetObject(OpenMode.ForWrite), BlockReference)
Dim dynBrefColl As DynamicBlockReferencePropertyCollection = bref.DynamicBlockReferencePropertyCollection
For Each dynBrefProps As DynamicBlockReferenceProperty In dynBrefColl
If dynBrefProps.PropertyName = "Distance1" Then
dynBrefProps.Value = 25.0
End If
Next
Next
End If
Next
trx.Commit()
End Using
End Sub