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 filepatternParams.PrimarySpacing = 1patternParams.SecondarySpacing = 1patternParams.PrimaryAngle = 45patternParams.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
From the picture and the code, it's not clear whether you want to add pattern (to place a cell repeatedly) or to hatch / crosshatch the grouped hole element.
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
salvatore montella said:patternParams.CellName = "A0A"; <- This field must contain the name of a model from the tmplate.cel library linked to the working file
I am not sure what does it mean "linked to working file".
When you want to use a cell for patterning, is the cell library attached?
Hi Jan,yes of course there is a cell library attached,about the image is just an example from the intended output.
What I would like to achieve is to add a pattern by repeatedly placing a cell.Indeed in istruction patternParams.CellName = "A0A";I indicate the name of the model present in a cell library attached to the work design
What is not clear to me is how to correctly set the parameters of the patternParams and dwgHatchDefLine objects
Hi Salvatore,
salvatore montella said: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.
salvatore montella said: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.
salvatore montella said: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.
salvatore montella said: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); } } } }
Answer Verified By: Robert Hook
Hi Jan, thanks for the help, your example works perfectly Thanks so much Salvio