Dynamic Block Hatch Not Updating to New Contour After Parameter Change

Dynamic Block Hatch Not Updating to New Contour After Parameter Change

M_Kocyigit
Enthusiast Enthusiast
79 Views
1 Reply
Message 1 of 2

Dynamic Block Hatch Not Updating to New Contour After Parameter Change

M_Kocyigit
Enthusiast
Enthusiast

I’m working with AutoCAD 2019 and insert dynamic blocks with visibility parameters via a .NET method, but the hatches do not automatically adjust to the new contour of the cross-section after parameter changes – is there a solution for this?

 

Hatch - Problem.JPG

0 Likes
Accepted solutions (1)
80 Views
1 Reply
Reply (1)
Message 2 of 2

M_Kocyigit
Enthusiast
Enthusiast
Accepted solution

After extensive research, I was finally able to solve the problem. The magic word is EvaluateHatch.

        /// <summary>
        /// 
        /// Re-evaluates all <see cref="Hatch"/> objects that belong to the block definition
        /// used by the given block reference, and marks the reference graphics as modified (regen).
        /// 
        /// </summary>
        /// 
        /// <param name="blockRefId">
        /// 
        /// ObjectId of the <see cref="BlockReference"/> to refresh.
        /// 
        /// </param>

        public static void 
        ReevaluateHatchesInBlock ( ObjectId blockRefId )
        {
            if ( blockRefId.IsNull || blockRefId.IsErased || !blockRefId.IsValid )
            {
                return;
            }

            var db = blockRefId.Database;

            using ( var tr = db.TransactionManager.StartTransaction() )
            {

                var br = tr.GetObject ( blockRefId, OpenMode.ForRead, false ) as BlockReference;

                if ( br == null || br.IsErased )
                {
                    tr.Abort();

                    return;
                }

                var btr = tr.GetObject(br.BlockTableRecord, OpenMode.ForRead, false) as BlockTableRecord;

                if ( btr != null && !btr.IsErased )
                {
                    foreach (ObjectId entId in btr)
                    {
                        var hatch = tr.GetObject(entId, OpenMode.ForRead, false) as Hatch;

                        if (hatch != null && !hatch.IsErased)
                        {

                            // Open in write mode to run EvaluateHatch

                            hatch.UpgradeOpen   ( );
                            hatch.EvaluateHatch ( true );
                        }
                    }
                }

                // Refresh the display of the BlockReference

                br.UpgradeOpen            ( );
                br.RecordGraphicsModified ( true );

             // br.Draw();

                tr.Commit();
            }
        }