[Microstation Connect] How to create a GroupedHole Element with a AreaPattern

Good morning,
I have a problem with creating PatternArea on an object of type GroupedHoleElement,
I would like to create a groupedHole like this:

the Microstation version is the following: Microstation CONNECT Edition Update 12 - Version 10.12.00.40.
Given that I have already searched for a solution or examples in the SDK example .. \ Elements \ ManagedToolsExample and I have not found anything about it, I report below the code I wrote in C #.

GroupedHoleElement groupedHoleElement = currElement as GroupedHoleElement;
PatternParams patternParams = new PatternParams ();
patternParams.CellName = "A0A"; <- This field must contain the name of a model from the tmplate.cel library linked to the working file
patternParams.PrimarySpacing = 1
patternParams.SecondarySpacing = 1
patternParams.PrimaryAngle = 45
patternParams.Scale = 1;

DwgHatchDefLine dwgHatchDefLine = new DwgHatchDefLine ();
dwgHatchDefLine.Angle = 45;

DwgHatchDefLine [] dwgHatchDefLines = new DwgHatchDefLine [1];
dwgHatchDefLines [0] = dwgHatchDefLine;

groupedHoleElement.AddPattern (patternParams, dwgHatchDefLines, 0);

The code is executed without errors, only that in the output the selected element has no pattern,
would you have a working example in c #?


Thanks so much,

best regards

Salvio

Parents Reply
  • Hi Salvatore,

    about the image is just an example from the intended output.

    Unfortunately it's confusing a bit, because you mentioned cell (patterning), but demonstrate it using hatched (filled by lines) element.

    What is not clear to me is how to correctly set the parameters of the patternParams and dwgHatchDefLine objects

    When you do not want to hatch, why you care how to se hatch def lines? Especially when, by its name, this parameter seems to be valid for DWG data only.

    The code is executed without errors, only that in the output the selected element has no pattern

    It's expected behavior, because you do not update the element in DGN model.

    What I would like to achieve is to add a pattern by repeatedly placing a cell.

    It's not very complicated, using a combination of C++ documentation and some thinking how NET API is implemented (even though the code is a bit dirty):

    // For a simplicity and testing purpose, element obtained using its ID
    long elementId = 827;
    using (Element element = Session.Instance.GetActiveDgnModel().FindElementById(new ElementId(ref elementId)))
    {
        if (element is GroupedHoleElement gh)
        {
            using (AreaFillPropertiesEdit areFillProperties = gh.AsAreaFillPropertiesEdit())
            {
                Session.Instance.EnqueueKeyin("rc=areapat.cel");
    
                PatternParams pp = new PatternParams
                {
                    CellName = "BATEN",
                    Scale = 0.1
                };
    
                bool addWasSuccessful = areFillProperties.AddPattern(pp, null, 0);
    
                if (addWasSuccessful)
                {
                    areFillProperties.ReplaceInModel(gh);
                }
            }
        }
    }

    Regards,

      Jan

    Answer Verified By: Robert Hook 

Children