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

Block made with dynamic blocks

1 REPLY 1
Reply
Message 1 of 2
tommam
300 Views, 1 Reply

Block made with dynamic blocks

I have code which creates a new block by using dynamic blocks.  The dynamic blocks are inserted and their parameters set, then they are added to the new block (see code below).  This is working good, the new block gets created using the dynamic blocks which have all the right parameter settings and dimensions.  The problem is that when this block is inserted, it looks good, but the user cannot snap to any of the geometry within the dynamic blocks.  For example, when measuring, they can't snap to a corner of any dynamic block within the main block.  Does anyone have any idea why this would be?  Am I creating the dynamic blocks wrong?  Or building the new block wrong?  Thanks!

 

            Document doc = Application.DocumentManager.MdiActiveDocument;

            Database db = doc.Database;

            String name = obj.Name;

 

            using (Transaction Tx = db.TransactionManager.StartTransaction())

            {

                BlockTable blkTbl = Tx.GetObject(db.BlockTableId, OpenMode.ForRead, false, true) as BlockTable;

 

                BlockTableRecord btr = new BlockTableRecord();

                btr.Name = name;

 

                blkTbl.UpgradeOpen();

                ObjectId btrId = blkTbl.Add(btr);

                Tx.AddNewlyCreatedDBObject(btr, true);

 

                // Add entities

                BlockReference dynBlk1 = InsertDynBlock(obj, 0, 0);

                BlockReference dynBlk2 = InsertDynBlock(obj, 10, 0);

 

                using (btr)

                {

                    btr.AppendEntity(dynBlk1);

                    Tx.AddNewlyCreatedDBObject(dynBlk1, true);

                    btr.AppendEntity(dynBlk2);

                    Tx.AddNewlyCreatedDBObject(dynBlk2, true);

                }

 

                Tx.Commit();

            }

 

 

        private static BlockReference InsertDynBlock(Object obj, Double x, Double y)

        {

            Document doc = Application.DocumentManager.MdiActiveDocument;

            Database db = doc.Database;

            ObjectId blkid;

            String name= "Drawings/Dyn1.dwg";

            BlockReference bref = null;

 

            using (Database bdb = new Database(false, true))

            {

                bdb.ReadDwgFile(name, System.IO.FileShare.Read, true, "");

                blkid = db.Insert(System.IO.Path.GetFileNameWithoutExtension(name), bdb, true);

                bref = new BlockReference(new Point3d(x, y, 0), blkid);

                Matrix3d mat = Matrix3d.Identity;

 

                bref.TransformBy(mat);

                bref.Rotation = 0.0;

 

                if (bref.IsDynamicBlock)

                {

                    DynamicBlockReferencePropertyCollection dynBrefColl = bref.DynamicBlockReferencePropertyCollection;

 

                    foreach (DynamicBlockReferenceProperty dynBrefProps in dynBrefColl)

                    {

                        if (dynBrefProps.PropertyName.ToUpper() == "HEIGHT")

                        {

                            dynBrefProps.Value = Convert.ToDouble(obj.Height);

                        }

                    }

                }

            }

            return bref;

        }

1 REPLY 1
Message 2 of 2
fenton.webb
in reply to: tommam

Quickly looking at this... what happens if you first add the dynblock to the database, then, update the dynamic properties? Also, make sure you call bdb.CloseInput(true) after your call to ReadDWGFile() so that the entire file is read in.




Fenton Webb
AutoCAD Engineering
Autodesk

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