.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dynamic Block Block Tables

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
BrentBurgess1980
1003 Views, 4 Replies

Dynamic Block Block Tables

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.

4 REPLIES 4
Message 2 of 5

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

 

Message 3 of 5

Gaston - You are a champ!!! that worked!!

Message 4 of 5

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);
                            }
                        }

 

Message 5 of 5

Hi Brent,

 

Glad to help you.

 

Gaston Nunez

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost