[Microstation V8i MDL C++ API] Creating complex shape causing my subchildren to connect even though the element is closed.

Hello!

I´m trying to create a complex element consisting of multiple subelements :

  1. Line
  2. Complex chain consisting of N segments
  3. Line
  4. Complex chain consisting of N segments

For that I´m using C++ MDL API.  First I create complex header via mdlComplexChain_createHeader. Then I create my subelements. Lines are created within single mdlLine call, while Complex chains are in loops with multiple mdlLine calls and then appending them to the mother header(The complex chain). After I create them, i append them to the owner with mdlElmdscr_appendDscr() . However, even though my creation is closed element (all lines are connected), microstation keeps adding a line between my two single lines, like the shape wasnt closed or something. Im also attaching a picture describing my problem. The same behavior happens even if i dont add the complex chains...

Thanks for any tips.

Lubo

Parents
  • First I create complex header via mdlComplexChain_createHeader. Then I create my subelements. Lines are created within single mdlLine call, while Complex chains are in loops with multiple mdlLine calls and then appending them to the mother header(The complex chain). After I create them, i append them to the owner with mdlElmdscr_appendDscr()

    It's faster to post a code sample than to describe it.  Also, a code sample removes any ambiguity in our interpretation of what you're doing.

    MicroStation keeps adding a line between my two single lines

    The direction of lines is important.  In the closed shape you are creating, all components must be clockwise or counter-clockwise.

    I use MSVC

    Here's a table of Visual Studio and MicroStation SDK versions.

     
    Regards, Jon Summers
    LA Solutions

  • I tried to play around also with the directions of my lines, sometimes the "connection line"(the problematic one) changes direction too ( changes the vertices that its connecting), but I never got to get rid of it. I also tried to specify in mdlComplexChain_createHeader that I wanted to create complex chain instead of complex shape(in hope of this line disappearing), but didnt work as well. The problem is also that I cant access this problematic line from code, so cant hide it manually after creating my element. 

  • I tried to play around

    As Jon wrote: Post your code.

    To explain by words what your code does, does not provide any usable details and the problem cannot be analyzed.

    It's like to discuss a problem with playing on piano describing what finger to when put on what key, but to do not share music notation. I think you agree it would be time wasting useless discussion.

    Regards,

      Jan

  • It's like to discuss a problem with playing on piano describing what finger to when put on what key

    Good analogy!

     
    Regards, Jon Summers
    LA Solutions

  • MSElement elem;
    MSElementDescr *pDescr = NULL;
     
    mdlComplexChain_createHeader(&elem, true, 0); // Header for mother element
     
    mdlElmdscr_new(pDescr,NULL,&elem);
     
    /*
    CALCULATE POINT POSITIONS FOR LINES
    */
     
    //Create 1st line - same process goes for line 3 - the short lines
    MSElement line1;
    DPoint3D line1Data; //Calculated point
    MSElementDescr* line1 descr;
    line1_descr = mdlLine_create(&line1, NULL, &line1Data);
    
    mdlElmdscr_appendDscr(pDescr,line1_descr); //Add the created line to my header
    
    //Process for creating the complex chain is :
    MSElement chain1;
    mdlComplexChain_createHeader(&chain1, false, 0);
    
    MSElementDescr * chain1_descr = NULL;
    mdlElmdscr_new(chain1_descr,NULL,&chain1); //create descriptor for first chain
    
    
    //Now create the 2 lines that will be consisted in my complex chain.
    For each line, I use mdlLine_create with given points and also append it to my chain1_descr
    
    //After all the things are completed append created chain to my element:
    mdlElmdscr_appendDscr(pDescr,chain1_descr); //Add the created line to my header

    As the code is pretty robust and due to some privacy issues I cant share it entirely with you guys, I managed to do some "pseudo" idea of how I approached the problem. I know its not much but I hope that it will at least help to explain my approach.

  • I use mdlLine_create with given points

    And what are those points?  Are they supplied externally or from existing DGN elements?  As I wrote already, the direction of elements is important to your question MicroStation keeps adding a line between my two single lines.

    I suggest that, as a development exercise to enhance our understanding of your task, you create DGN elements separately rather than as a complex chain.  Then you can use MicroStation tools to examine those elements and attempt to create a complex chain.

     
    Regards, Jon Summers
    LA Solutions

Reply
  • I use mdlLine_create with given points

    And what are those points?  Are they supplied externally or from existing DGN elements?  As I wrote already, the direction of elements is important to your question MicroStation keeps adding a line between my two single lines.

    I suggest that, as a development exercise to enhance our understanding of your task, you create DGN elements separately rather than as a complex chain.  Then you can use MicroStation tools to examine those elements and attempt to create a complex chain.

     
    Regards, Jon Summers
    LA Solutions

Children
  • I´ve tried to do that even manually from UI. I created complex chains, then added my lines. Then I used Create complex shape tool, but it didnt let me create complex shape containing other complex element, but it allowed me to select lines one by one, so basically it created complex shape created from lines, not chains+lines.

  • I used Create complex shape tool, but it didnt let me create complex shape containing other complex element

    It worked for me, using MicroStation CONNECT Update 14.2.  Or, more accurately, the tool lets me create a complex shape from a complex string and some lines: the complex string is taken apart and its components are used in the new complex shape.

    Please post a DGN model that includes the lines and line-strings you want to assemble.

    Don't tell us that your data is confidential and can't be posted: prepare an example without confidential information.

     
    Regards, Jon Summers
    LA Solutions

  • Hi Lubo,

    I´ve tried to do that even manually from UI.

    It always recommended to try to simulate code manually, but I think Jon idea was to create (sub)elements by code, but do not join them into complex element, but write to DGN file instead of it. It should allow to check whether elements are created correctly in memory, e.g. their order (points sequence) is right.

    Then I used Create complex shape tool, but it didnt let me create complex shape containing other complex element

    It's not possible create complex shape or complex chain with nested complex elements manually. I guess it's the tool feature, not API or format limitation, because in general, I think DGN V8 format allows to nest complex elements (e.g. cell in cell is quite normal structure).

    But I guess it's not crucial question now, because the shape itself is not created right. So maybe in the first step it makes sense to do not use complex elements nesting and to create equal shape, but from simple elements only, to ensure the code is right.

    I know its not much

    I am missing two things in your code:

    • To check values returned from every used function. Is it in your original code?
    • What I mentioned above: DGN with elements, used as input for the final complex shape.

    With regards,

      Jan

  • One more comment or, better to say, question: Why you want to create complex shape with nested another complex strings (complex chains)?

    Even when MicroStation itself uses nested complex cells sometimes (e.g. TriForma shapes, or SmarSolids) and it's possible to create such structures (because it's allowed by DGN V8 format specification), they are in fact "from the past heritage", when it was the simplest workaround of complex requirements.

    When you will study a presentation from migration workshop (to CE platform):

    In most cases:
    - We found Complex elements to be WRONG during i-model platform optimization
    - Less need to use MSElement and MSElementDescr types (applause)
    - MSElement should only be used for Handlers Only
    
    Nesting = bad

    You can see that in CONNECT Edition, new elements (e.g. parametric modeling) are implemented using relationships, not nesting.

    For normal elements, one level nesting (flat structures inside shapes, chains and cells) is recommended, because it does not require recursion, which is treated as a threat in a code and should be avoided when not really necessary.

    With regards,

      Jan

  • I have it like this because i wanted a way to differentiate between parts of my element in VBA.  

    Then I want to apply my VBA macro, where I can simply determine which line am I working with by identifying if Im iterating inside a complex chain or just a simple line. I encapsulated these all lines and chains into another complex shape because in my macro I want to use getIntersectionPoints method from complex shape.

  • It is not valid to add a complex chain or shape as a child of another complex chain or shape
    I have it like this because i wanted a way to differentiate between parts of my element in VBA

     is a member of the core development team.  If he says: "Don't do it that way", then don't do it that way!

    But, rather than debating the merits of nested elements, raise the discussion to a higher level.  Put your problem to us and ask for tips.  For example: "How can I identify the origin or provenance of the components of a complex shape?"

    One way, for example, would be to attach some sort of data tag to those elements.  With MicroStation, you're spoiled for choice — or would be if you didn't want to interrogate the complex chain using VBA. Possibilities include...

    • User Attribute Data
    • DataBlock
    • XDatum

    With CONNECT you might additionally consider Item Types. There's a VBA API for all of those.

     
    Regards, Jon Summers
    LA Solutions

  • Hi Lubo,

    thanks for the explanation.

    i wanted a way to differentiate between parts of my element in VBA.

    A context is not provided, so it's not quite clear why you need to differentiate between parts (what they represent), but to use element types is not good idea ... and as Brien confirmed, to create nested complex chain / shape is not possible.

    The problem with element types is that it can be changed when specific tools are used (e.g. trim converts shape to line string). Depending on context it can cause serious troubles or can be fined (because cannot happened ;-).

    I think there are two solutions available:

    • To use a cell as a container. Cell is the only element that allows nested content, so you can you your approach, but it is not editable, which can be a problem, when it's expected e.g. Modify element tool will be used.
    • As Jon wrote, to tag element by custom data. In my opinion it's more elegant solution, in parallel with general recommendations and best practices. Data, that can be accessed both from native and VBA code is limited, but I think User Attribute Data is a good choice (XData were designed to be used with DWG, so it's not recommended to use them in DGN). If there is a vision of using the code for a long time, I would recommend EC data, but it's quite complicated in V8i (but possible).

    With regards,

      Jan

  • Thank you guys for your tips. I will try to come up with a suitable solution. 

    To use a cell as a container. Cell is the only element that allows nested content, so you can you your approach, but it is not editable, which can be a problem, when it's expected e.g. Modify element tool will be used.

    Could you please tell me more about saying it will be not editable? Like for example, if I decide to change linestyle for some of the lines of my element?  

  • Could you please tell me more about saying it will be not editable?

    Editable by a user, you can try it manually:

    • It's possible to modify complex chain or shape geometry using modify tool or selection arrow.
    • It's not possible do the same with cell content, because it's encapsulated by a cell. I guess the only content that can be edited by a user directly are texts and text nodes.
    Like for example, if I decide to change linestyle for some of the lines of my element?  

    You did not mentioned this requirement before and it's another thing that disqualify complex chain / shape to be used, because by definition, all content has to have the same symbology.

    Cell content can be any (every element can have different symbology in graphic cells) and can be modified when necessary, even when it's typically not good idea when user want to change some part of the cell.

    Regards,

      Jan

  • At first I didnt think that could be the problem, but maybe it was because I misunderstood some of the concepts, as Im still in learning process. 

    You did not mentioned this requirement before and it's another thing that disqualify complex chain / shape to be used, because by definition, all content has to have the same symbology.

    Actually this requirement is pretty important for me. To fully explain what I´ve tried to achieve was:

    • To have a complex shape containing complex chains(with multiple lines) and lines.
    • Sometimes I want to change linestyle for lines of my complex chains. I´ve tried this with VBA, but it didnt change the graphics for my lines "externally". When I looked at the element, everything was with the same linestyle, but when I selected one of the 4 subelements my element has(2 lines,2 complex chains), then my changed linestyles appeared. I used rewrite on these lines with new linestyle being applied. However, when I unselected the element, the changes were back to normal. I found out that by changing symbology also on one of these 4 base child elements causes the changes to appear normally, however, this is where the "connecting line" appears (As yesterday I managed to write code that manages the creation in OK order, but the "connecting line" was invisible when element was unselected. After I changed linestyle to one of the 4 subelements(or one of the 4 subelements was selected), it appeared again. By term "connecting line" I mean the weird line that made me start this question. 

    At first I thought it will be a good idea with this approach of using nested complex elements, even though I´m still learning a lot, but didn´t expect it to be that difficult to handle (or impossible), as in my head it looked like a good idea. 

    Here is also picture showing my progress of new behavior (that the line is not visible when entire element is selected, but when I select or change symbology for one of the sub elements it appears). The line is also reacting to whenever I hover over it with my mouse, as I hovered over the element, I can even click it when I see the element started to highlight.

    Or in CW order