Drop element Line String

I use microstation 08.11.09.578, DGN 2D V7 Upgrade V8

I use C# language

I want to break the LineString association into separate LineStrings as shown below

ElementScanCriteria _MSesc = new ElementScanCriteriaClass();
_MSesc.ExcludeAllTypes();
_MSesc.IncludeType(MsdElementType.LineString);

ElementEnumerator oEnumeration = app.ActiveModelReference.Scan(_MSesc);

while (oEnumeration.MoveNext())
{
    oEnumeration.Current.AsLineElement().AsDroppableElement().Drop();

}

I tried but it gives error "Specified cast is not valid"

  • I use microstation 08.11.09.578, DGN 2D V7 Upgrade V8

    What do you mean by 'DGN 2D V7 Upgrade V8'?

    MicroStation's native file format is a DGN file.  A file contains DGN models.  A model can be 2D or 3D.  A DGN file is neither 2D nor 3D.

    A previous version of MicroStation used a different file format that is referred to as V7.  See the History of MicroStation.

    Upgrade V8 is meaningless.

    I use C# language

    When you write C# code for MicroStation V8i then you are calling the VBA COM interface.  Prefer to develop your prototype using just VBA. 

    That way you...

    1. Avoid incompatibilities in programming languages
    2. Enable us to test code fragments directly when you post them here
    3. Port your code to C# once it works correctly
    I want to break the LineString association into separate LineStrings

    A VBA LineElement implements the VertexList interface.  Get that list and create a new LineElement for each pair of vertices in that list.

     
    Regards, Jon Summers
    LA Solutions

  • A VBA LineElement implements the VertexList interface.  Get that list and create a new LineElement for each pair of vertices in that list.

    Good idea, thanks

  • Hi,

    I want to break the LineString association

    It's not clear what you mean by "LineString association". The term "association" has exact meaning in MicroStation and API: Elements, like dimensions for example, can be associative to another elements. It does not make sense to use it in the discussed context.

    I want to break the LineString association into separate LineStrings as shown below

    There are several issues in your code. I am not sure they are a result of not understanding how COM API works or you did not read API documentation carefully:

    • Drop() method can be used only with elements, that are "droppable". It's exactly defined (and described) what elements support this method.
    • Because "droppable" is not implemented using inheritance or as interface, every graphical element offers IsDroppable propperty, that can be used to check whether it is possible to drop it. But the discussed code such test is not necessary, because you scan for line string only, and this element type is not droppable.
    • Even when the element would be droppable, your code does not work: As described in the documentation, Drop() does not modify the original element, but returns ElementEnumerator with "dropped representation" of the original element.

    Another issue, but it's subjective one, is "an ugliness": You mixed old VB style (using names like oEnumeration does not make any sense today and is treated as bad practice generally) with C style (using _ for, probably, instance or local variables). When C# was released, naming best practices were defined by Microsoft, so when you decided to use C#, you also should follow the "C# code and naming style".

    into separate LineStrings

    The solution recommended by Jon is the simplest and elegant one.

    With regards,

      Jan