[ORD 2021 R1 C#] ConsensusConnectionEdit class - clarification

Can we have more information about ConsensusConnectionEdit class which is I believe the backbone of creating any civil object in ORD

I have a few questions about this class.

  1. Is it safe to use multiple ConsensusConnectionEdit instances in more complex code or it is recommended to use one instance and pass it as parameter into another methods?
  2. There is no Commit() method therefore at what point in code the new civil element is added into the model?
  3. What is the function of two methods StartTransientMode() and PersistTransients()? In proved SDK example these two methods encircle for example AlignmentEdit.CreateByLinearElement. But even without these two methods civil element is created in model
  4.  Can we delete civil element by ConsensusConnectionEdit. Delete() method? It seems it doesn’t work. And I assume using Microstation Element.DeleteFromModel is not recommended for civil elements

Thank you,

Richard

  • Hi Richard,

    my personal (so subjective) experience with own code and what I see in SDK examples:

    Is it safe to use multiple ConsensusConnectionEdit instances in more complex code or it is recommended to use one instance and pass it as parameter into another methods?

    In my opinion ConsensusConnection is Disposable (so should be short-living) bridge between data model in DGN and GeometricModel class.

    I always create it only when required, usually because I need to access GeometricModel content, and close and dispose it asap. When a user tool is implemented, OnPostInstall is the place where the connection is opened and OnExitTool the place where to close / dispose it.

    There is no Commit() method therefore at what point in code the new civil element is added into the model?

    I guess it's PersistTransient method functionality.

    What is the function of two methods StartTransientMode() and PersistTransients()?

    I am not sure why it is done this way (and there is no equal method in native API), but it's the way how to add civil object to DGN file:

    1. Start ConsensusConnectionEdit transient mode
    2. Create object
    3. Call PersistTransient method to save it to DGN file
    Can we delete civil element by ConsensusConnectionEdit. Delete() method?

    I am not sure, so far I have had no request to delete any civil object ;-)

    Do you have any code / DGN file as an example? What do you pass as an argument? And maybe to use transient mode is necessary here?

    With regards,

      Jan

  • Hi Jan,

    Thank you and sorry for my late reply. I was unwell last week.

    I always create it only when required, usually because I need to access GeometricModel content, and close and dispose it asap. When a user tool is implemented, OnPostInstall is the place where the connection is opened and OnExitTool the place where to close / dispose it.

    This is great reminder that even with NET garbage collector we should not forget to clean up after yourself. Maybe topic for the future.

    I guess it's PersistTransient method functionality.

    I am still not sure with this. If I run below code with commented two lines, even then alignment is added into the model

            public AlignmentEdit CreateBaseLine()
            {
                DPoint3d startPoint = new DPoint3d(0, 0);
                DPoint3d endPoint = new DPoint3d(1, 1);
    
                Line line = Line.Create1(startPoint, endPoint);
    
                ConsensusConnectionEdit con = ConsensusConnectionEdit.GetActive();
                //con.StartTransientMode();
                AlignmentEdit al = AlignmentEdit.CreateByLinearElement(con, line, true);
                //con.PersistTransients();
    
                return al;
            }
    

    Do you have any code / DGN file as an example? What do you pass as an argument? And maybe to use transient mode is necessary here?

    I was only trying ConsensusConnectionEdit.Delete and as argument I passed Alignment object (inherited class CifNET.SDK.ConsensusItem)

    Thanks,

    Richard