Author Topic: the Dimension & Hatch of Dynamic block can't update automatically  (Read 1748 times)

0 Members and 1 Guest are viewing this topic.

jerome2003

  • Guest
we use RealDWG SDK for dynamic block. we can change the dynamic block's user parameter, but failed with automatically update the dimension and hatch of the dynamic block.

I had test it in AutoCAD 2012(manually), the hatch will automatically update if the user parameter had been changed, but the dimension need use "regen" to update.

are there some ways to update the dimension and hatch in the dynamic block?

thanks for any input!

Jerome

jerome2003

  • Guest
Re: the Dimension & Hatch of Dynamic block can't update automatically
« Reply #1 on: November 17, 2011, 03:56:41 AM »
We did it in AutoCAD, but failed in RealDWG.

the methodology is find the dynamic block definition and re-generate all dimensions, after re-generate, the hatch and dimension will update it automatically.

Who know how to do it in RealDWG?

the C# code is following:

            Dictionary<string, object> updatePropertys = new Dictionary<string, object>();
            updatePropertys.Add("Seg_L", 18);
            updatePropertys.Add("Seg_H", 20);

            Document doc = AcadApp.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            bool IsModify = false;
            List<ObjectId> RefreshBlock = new List<ObjectId>();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                foreach (ObjectId id in btr)
                {
                    if (id.IsErased || id.IsNull || !id.IsValid)
                        continue;
                    Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
                    if (!ent.Visible)
                        continue;
                    if (ent is BlockReference)
                    {
                        BlockReference block = ent as BlockReference;
                        if (!block.Name.Equals("CC_101"))
                            continue;
                        if (block.IsDynamicBlock)
                        {
                            DynamicBlockReferencePropertyCollection dbc = block.DynamicBlockReferencePropertyCollection;
                            foreach (DynamicBlockReferenceProperty dp in dbc)
                            {
                                if (dp.ReadOnly)
                                {
                                    continue;
                                }
                                if (updatePropertys.Keys.Contains(dp.PropertyName))
                                {
                                    try
                                    {
                                        if (!RefreshBlock.Contains(block.BlockTableRecord))
                                            RefreshBlock.Add(block.BlockTableRecord);
                                        dp.Value = updatePropertys[dp.PropertyName];
                                        IsModify = true;
                                    }
                                    catch (Autodesk.AutoCAD.Runtime.Exception ex)
                                    {

                                    }
                                }
                            }
                        }
                    }
                }
                if (IsModify)
                {
                    tr.Commit();
                }
            }
            if (RefreshBlock.Count > 0)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    foreach (ObjectId bid in RefreshBlock)
                    {
                        BlockTableRecord btrs = (BlockTableRecord)tr.GetObject(bid, OpenMode.ForRead);
                        foreach (ObjectId obd in btrs)
                        {
                            Entity ents = (Entity)tr.GetObject(obd, OpenMode.ForRead);
                            if (ents is Dimension)
                            {
                                Dimension dim = ents as Dimension;
                                dim.UpgradeOpen();
                            }
                        }
                    }
                    tr.Commit();
                }
            }