With C# i am trying to create a grouped hole with a pattern in Microstation Connect v10 update 14. So far with no success.
Because a grouped hole does not have the ClosedElement interface i cannot use the SetPattern method.
Creating a grouped hole without a pattern is succesful:
// Create some complex elements: outermost and holes. All have property NotFilled and are on the same level var outermost = Application.CreateComplexStringElement1(ref elementArray); var holes[] = new Element[] { Application.CreateComplexStringElement1(ref elementArray) };
foreach (var hole in holes) mdlElmdscr_initOrAddToChain(&outEdPP2, hole.MdlElementDescrP());
mdlElmdscr_createShapeWithHoles(&outEdPP2, outermost.MdlElementDescrP(), holeEdP);
// Create element var groupedHole = Application.MdlCreateElementFromElementDescrP(outEdPP);
// Add to the designfile Application.ActiveModelReference.AddElement(groupedHole);
// Create pattern params e.g. var patternParams = new PatternParams(); patternParams.PrimaryAngle = Math.PI/4; patternParams.PrimarySpacing = 20.0; patternParams.Modifiers = PatternParamsModifierFlags.Angle1 | PatternParamsModifierFlags.Space1;
var result = mdlPattern_addAssociative(&outEdPP2, -1, -1, ref patternParams, 0, 0, 0, MicroStationGlobals.Instance.Application.ActiveModelReference.MdlModelRefP());
result is 0 (SUCCESS). outEdPP2 will have another value.
A grouped hole does appear in the designfile, but it has no pattern.
In MicroStation the property 'Pattern' says 'None', but I can create it manualy.
Any help would be appreciated.
leonardk said:With C#...
Your code is a fascinating mix of C#, C++ and VBA. Which is your preferred language?
Here's an article about Grouped Holes and VBA. It shows how to create a grouped hole, how to measure the area of a grouped hole...
... and how to pattern a grouped hole...
Regards, Jon Summers LA Solutions
Hi Jon,
I prefer C#, but I had to thicken the code because of the length of it and therefor used kind of pseudo code.
Anyway i did not formulate my question well enough: i would like to have an associated pattern. The mdlPattern_crossHatch method works fine, but it creates the pattern in seperate elements.
In v8i ss4 there also were issues with mdlPattern_addAssociative, e.g. https://communities.bentley.com/products/programming/microstation_programming/f/microstation-programming---forum/124555/v8i---mdl-cpp-bug-in-mdlpattern_addassociative-in-v8i-ss4-8-11-09-832/383794#383794
Any ideas?
leonardk said:i would like to have an associated pattern
As Jan Šlegr often recommends, it's a good idea to read the MicroStationAPI documentation, even if you don't plan to use C++. Frequently, the .NET classes are wrappers around C++ classes, and the C++ classes are better documented (sometimes, there are even examples!).
In this case of associative patterning, I see that there is an AssocRegionCellHeaderHandler: The Associative Region cell can represent one or more planar regions that can be a shape, ellipse, complex shape, or grouped hole. The region boundaries can be visible or invisible and associated to other persistent elements such that they will update when changes are made to the boundary roots. The AssocRegionCellHeaderHandler supports area properties like fill, and hatching.
AssocRegionCellHeaderHandler
With that knowledge, I looked again in the DgnPlatformNet help doc and found the AssocRegionCellHeaderElement class. It has some useful methods, including AddPattern().
AssocRegionCellHeaderElement
AddPattern()
Let us know if that proves useful.
leonardk said: mdlElmdscr_createShapeWithHoles(&outEdPP2, outermost.MdlElementDescrP(), holeEdP); // Create element var groupedHole = Application.MdlCreateElementFromElementDescrP(outEdPP); // Add to the designfile Application.ActiveModelReference.AddElement(groupedHole);
Try adding the pattern attribute to outEdPP2 before calling AddElement (like right after createShapeWithHoles)?
leonardk said:i am trying to create a grouped hole
Why not use the .NET GroupedHoleElement? See DgnPlatformNet help doc.
GroupedHoleElement
leonardk said:Because a grouped hole does not have the ClosedElement interface i cannot use the SetPattern method
What about GroupedHoleElement.AddPattern?
GroupedHoleElement.AddPattern
See SDK example ..\Elements\ManagedToolsExample.
..\Elements\ManagedToolsExample
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
salvatore montella said:patternParams.PrimarySpacing = 1patternParams.SecondarySpacing = 1patternParams.PrimaryAngle = 45
With C# and C++, dimensions are expressed in Units of Resolution (UORs). Angles are expressed in radians. The current dimensions for your pattern are too small to see.
Multiple your dimensions by UORs-per-Master Unit, which you can obtain from a DgnModelRef or DgnModel. Convert degrees to radians using Application.Radians().
DgnModelRef
DgnModel
Application.Radians()
salvatore montella said:groupedHoleElement.AddPattern
When you change an element, use its ReplaceInModel() method to persist it.
ReplaceInModel()
Hi Jon, Thanks for answering me,I modified the code following your instructions,but unfortunately it fails on the statement groupedHoleElement.ReplaceInModel (groupedHoleElement);
Here is the error message and stack:
Bad StatusInt: 32768
at Bentley.DgnPlatformNET.StatusHandler.ThrowStatusException(String statusType, Int32 status) at Bentley.DgnPlatformNET.StatusHandler.HandleStatus(Int32 status) at Bentley.DgnPlatformNET.Elements.Element.ReplaceInModel(Element toReplace) at Ides.Plugin.ThematicPlan.Controllers.PatternController.SetPatternOnSpace(Element element, IDgnECInstance item) in C:\V8i Projects\IDES_2.0\Ides.Plugin.ThematicPlan\Controllers\PatternController.cs:line 266
Do you have any idea what "Bad StatusInt: 32768" means?
Thank you
Hi Salvatore,
I think it's seriously bad idea to ask twice about the same issue: Here, where you steal 2 years old discussion and start to discuss a similar, but not the same, topic. And you also posted this new question. Really, how anybody can understand what discussion is "active one" now and to invest time to reading ans answering?
Also, please respect the best practices and to use Insert > Insert code tool when you want to share a code snippet. To read code, posted as plain, not formatted properly, text, is annoying.
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hi Jan,forgive me, it won't happen again in the future.GreetingsSalvio