Update Dynamic block hatch

Update Dynamic block hatch

CAD-Geek
Advocate Advocate
1,944 Views
4 Replies
Message 1 of 5

Update Dynamic block hatch

CAD-Geek
Advocate
Advocate

I use this solution (by @_gile )to edit dynamic block stretch via two points from the user. and that dynamic block has a hatch that also needs to stretch.

but the issue is that hatch not update properly. as the next image.

 test.JPG

but when I open that block in block editor and Zoom Extents. close block editor and save it looks fine and work well.

the dynamic block attached.

0 Likes
Accepted solutions (1)
1,945 Views
4 Replies
Replies (4)
Message 2 of 5

_gile
Consultant
Consultant
Accepted solution

Hi,

 

Simply try to remove the hatch from the stretch action selection (the associativity of the hatch is enough to make it dynamic).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 5

Anonymous
Not applicable

Sorry to resume an old topic, but I've been struggling with this problem since many years now... never got a final solution... sometimes the xhatch need to excluded, sometime needs to be included in the strech action.

Sometime the block instances need a strong action to rebuild the hatch correctly (like editing, doing nothing and saving the block), sometimes it's enough to get the dynamic grip, move it around and get back to the original position...

Is there something I can do programmatically to force a xhatch rebuild after I created the blockreference and assigned the correct values to the dynamic parameters?

 

This is what I tried, without success:

BlockTableRecord btr = tr.GetObject((br.BlockTableRecord), OpenMode.ForWrite, false) as BlockTableRecord;
if (btr != null)
{
    foreach (ObjectId o in btr)
    {
        DBObject dbo = tr.GetObject(o, OpenMode.ForRead, false);
        if (!dbo.IsErased && (dbo is Hatch))
        {
            Hatch hh = dbo as Hatch;
            hh.UpgradeOpen();
            hh.EvaluateHatch(false);
        }
    }
}
0 Likes
Message 4 of 5

SRSDS
Advisor
Advisor

Not sure if it's ok that it's ok that I'm bumping these posts but they are all facing the same issue.   

https://forums.autodesk.com/t5/net/dynamic-block-with-associative-hatch/td-p/10023207

 

Message 5 of 5

FRFR1426
Collaborator
Collaborator

Best I've found is to recreate the hatch:

 

 

static void ReCreateHatch(BlockReference blockReference)
{
    var blockTableRecord = (BlockTableRecord)blockReference.BlockTableRecord.GetObject(OpenMode.ForWrite)!;
    foreach (ObjectId id in blockTableRecord)
    {
        var hatch = id.GetObject(OpenMode.ForRead) as Hatch;
        if (hatch == null || !hatch.Associative) continue;
        var newHatch = new Hatch();
        blockTableRecord.AppendEntity(newHatch);
        blockTableRecord.Database!.TransactionManager!.AddNewlyCreatedDBObject(newHatch, add: true);
        newHatch.SetPropertiesFrom(hatch);
        newHatch.SetHatchPattern(HatchPatternType.PreDefined, hatch.PatternName!);
        ObjectIdCollection ids = hatch.GetAssociatedObjectIds()!;
        newHatch.AppendLoop(HatchLoopTypes.Outermost, ids);
        newHatch.EvaluateHatch(underEstimateNumLines: true);
        hatch.UpgradeOpen();
        hatch.Erase();
    }
}

 

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
0 Likes