Tuesday, June 16, 2015

Reset Logical Topology Map3D Industry Model

 /// <summary>
        /// Reset the topology of the industry model currently connected to.
        /// </summary>
        public static void ResetTopology()
        {
            var application = Application.Active;
            var connection = application.Documents.Active.Connection;

            using (var ma = new Topobase.LogicalTopology.Maintainance(connection))
            {
                connection.Open();
                //Make sure there are topologies to clear
                if (connection.Topologies != null)
                {
                    for (int i = 0; i < connection.Topologies.Count; i++)
                    {
                        //Check the type of the topologies before clearing them.
                        //Make sure they are logical topologies and not area
   var topology =     
   connection.Topologies.Get(connection.Topologies[i].Name);
                        var logicalToplogy = topology as LogicalTopology;
                        //Clear topology attached to the industry model
                        ma.ClearTopology(logicalToplogy, null);
                        //Initialize topolgy of the current industy model
                        ma.InitializeTopology(logicalToplogy, null);
                    }
                }
            }
        }