Exemplo n.º 1
0
            //
            // Copied from Revit SDK TraverseSystem example
            //
            // (C) Copyright 2003-2010 by Autodesk, Inc.
            //
            /// <summary>
            /// Get the mechanical or piping system
            /// from the connectors of selected element.
            /// </summary>
            /// <param name="connectors">Connectors of selected element</param>
            /// <returns>The found mechanical or piping system</returns>
            static public MEPSystem ExtractSystemFromConnectors(ConnectorSet connectors)
            {
                MEPSystem system = null;

                if (connectors == null || connectors.Size == 0)
                {
                    return(null);
                }

                // Get well-connected mechanical or
                // piping systems from each connector

                List <MEPSystem> systems = new List <MEPSystem>();

                foreach (Connector connector in connectors)
                {
                    MEPSystem tmpSystem = connector.MEPSystem;
                    if (tmpSystem == null)
                    {
                        continue;
                    }

                    MechanicalSystem ms = tmpSystem as MechanicalSystem;
                    if (ms != null)
                    {
                        if (ms.IsWellConnected)
                        {
                            systems.Add(tmpSystem);
                        }
                    }
                    else
                    {
                        PipingSystem ps = tmpSystem as PipingSystem;
                        if (ps != null && ps.IsWellConnected)
                        {
                            systems.Add(tmpSystem);
                        }
                    }
                }

                // If more than one system is found,
                // get the system contains the most elements

                int countOfSystem = systems.Count;

                if (countOfSystem != 0)
                {
                    int countOfElements = 0;
                    foreach (MEPSystem sys in systems)
                    {
                        if (sys.Elements.Size > countOfElements)
                        {
                            system          = sys;
                            countOfElements = sys.Elements.Size;
                        }
                    }
                }
                return(system);
            }
Exemplo n.º 2
0
        private MEPSystem ExtractSystemFromConnectors(ConnectorSet connectors, Element selectEle)
        {
            MEPSystem system = null;

            if (connectors == null || connectors.Size == 0)
            {
                return(null);
            }

            List <MEPSystem> systems = new List <MEPSystem>();

            foreach (Connector connector in connectors)
            {
                MEPSystem tmpSystem = connector.MEPSystem;
                if (tmpSystem == null)
                {
                    continue;
                }

                MechanicalSystem ms = tmpSystem as MechanicalSystem;
                if (ms != null)
                {
                    systems.Add(tmpSystem);
                }
                else
                {
                    PipingSystem ps = tmpSystem as PipingSystem;
                    systems.Add(tmpSystem);
                }
            }
            //if there is more than one system is found, get system contain the selected element;
            foreach (MEPSystem sys in systems)
            {
                if (sys.GetParameters(selectEle.Name) != null)
                {
                    system = sys;
                }
            }
            return(system);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            //// Select all pipes in the entire model.

            //List<Pipe> pipes = new List<Pipe>(
            //  new FilteredElementCollector( doc )
            //    .OfClass( typeof( Pipe ) )
            //    .ToElements()
            //    .Cast<Pipe>() );

            //int n = pipes.Count;

            //// If there are less than two,
            //// there is nothing we can do.

            //if( 2 > n )
            //{
            //  message = _prompt;
            //  return Result.Failed;
            //}

            //// If there are exactly two, pick those.

            //if( 2 < n )
            //{
            //  // Else, check for a pre-selection.

            //  pipes.Clear();

            //  Selection sel = uidoc.Selection;

            //  //n = sel.Elements.Size; // 2014

            //  ICollection<ElementId> ids
            //    = sel.GetElementIds(); // 2015

            //  n = ids.Count; // 2015

            //  Debug.Print( "{0} pre-selected elements.",
            //    n );

            //  // If two or more model pipes were pre-
            //  // selected, use the first two encountered.

            //  if( 1 < n )
            //  {
            //    //foreach( Element e in sel.Elements ) // 2014

            //    foreach( ElementId id in ids ) // 2015
            //    {
            //      Pipe c = doc.GetElement( id ) as Pipe;

            //      if( null != c )
            //      {
            //        pipes.Add( c );

            //        if( 2 == pipes.Count )
            //        {
            //          Debug.Print( "Found two model pipes, "
            //            + "ignoring everything else." );

            //          break;
            //        }
            //      }
            //    }
            //  }

            //  // Else, prompt for an
            //  // interactive post-selection.

            //  if( 2 != pipes.Count )
            //  {
            //    pipes.Clear();

            //    try
            //    {
            //      Reference r = sel.PickObject(
            //        ObjectType.Element,
            //        new PipeElementSelectionFilter(),
            //        "Please pick first pipe." );

            //      pipes.Add( doc.GetElement( r.ElementId )
            //        as Pipe );
            //    }
            //    catch( Autodesk.Revit.Exceptions
            //      .OperationCanceledException )
            //    {
            //      return Result.Cancelled;
            //    }

            //    try
            //    {
            //      Reference r = sel.PickObject(
            //        ObjectType.Element,
            //        new PipeElementSelectionFilter(),
            //        "Please pick second pipe." );

            //      pipes.Add( doc.GetElement( r.ElementId )
            //        as Pipe );
            //    }
            //    catch( Autodesk.Revit.Exceptions
            //      .OperationCanceledException )
            //    {
            //      return Result.Cancelled;
            //    }
            //  }
            //}

            JtPairPicker <Pipe> picker
                = new JtPairPicker <Pipe>(uidoc);

            Result rc = picker.Pick();

            if (Result.Failed == rc)
            {
                message = _prompt;
            }

            if (Result.Succeeded != rc)
            {
                return(rc);
            }

            IList <Pipe> pipes = picker.Selected;

            // Check for same pipe system type.

            ElementId systemTypeId
                = pipes[0].MEPSystem.GetTypeId();

            Debug.Assert(pipes[1].MEPSystem.GetTypeId()
                         .IntegerValue.Equals(
                             systemTypeId.IntegerValue),
                         "expected two similar pipes");

            // Check for same pipe level.

            ElementId levelId = pipes[0].LevelId;

            Debug.Assert(
                pipes[1].LevelId.IntegerValue.Equals(
                    levelId.IntegerValue),
                "expected two pipes on same level");

            // Extract data from the two selected pipes.

            double wall_thickness = GetWallThickness(pipes[0]);

            Debug.Print("{0} has wall thickness {1}",
                        Util.ElementDescription(pipes[0]),
                        Util.RealString(wall_thickness));

            Curve c0 = pipes[0].GetCurve();
            Curve c1 = pipes[1].GetCurve();

            if (!(c0 is Line) || !(c1 is Line))
            {
                message = _prompt
                          + " Expected straight pipes.";

                return(Result.Failed);
            }

            XYZ p00 = c0.GetEndPoint(0);
            XYZ p01 = c0.GetEndPoint(1);

            XYZ p10 = c1.GetEndPoint(0);
            XYZ p11 = c1.GetEndPoint(1);

            XYZ v0 = p01 - p00;
            XYZ v1 = p11 - p10;

            if (!Util.IsParallel(v0, v1))
            {
                message = _prompt
                          + " Expected parallel pipes.";

                return(Result.Failed);
            }

            // Select the two pipe endpoints
            // that are farthest apart.

            XYZ p0 = p00.DistanceTo(p10) > p01.DistanceTo(p10)
        ? p00
        : p01;

            XYZ p1 = p10.DistanceTo(p0) > p11.DistanceTo(p0)
        ? p10
        : p11;

            XYZ pm = 0.5 * (p0 + p1);

            XYZ v = p1 - p0;

            if (Util.IsParallel(v, v0))
            {
                message = "The selected pipes are colinear.";
                return(Result.Failed);
            }

            // Normal vector of the plane defined by the
            // two parallel and offset pipes, which is
            // the plane hosting the rolling offset

            XYZ z = v.CrossProduct(v1);

            // Vector perpendicular to v0 and v0 and
            // z, i.e. vector pointing from the first pipe
            // to the second in the cross sectional view.

            XYZ w = z.CrossProduct(v1).Normalize();

            // Offset distance perpendicular to pipe direction

            double distanceAcross = Math.Abs(
                v.DotProduct(w));

            // Distance between endpoints parallel
            // to pipe direction

            double distanceAlong = Math.Abs(
                v.DotProduct(v1.Normalize()));

            Debug.Assert(Util.IsEqual(v.GetLength(),
                                      Math.Sqrt(distanceAcross * distanceAcross
                                                + distanceAlong * distanceAlong)),
                         "expected Pythagorean equality here");

            // The required offset pipe angle.

            double angle = 45 * Math.PI / 180.0;

            // The angle on the other side.

            double angle2 = 0.5 * Math.PI - angle;

            double length = distanceAcross * Math.Tan(angle2);

            double halfLength = 0.5 * length;

            // How long should the pipe stubs become?

            double remainingPipeLength
                = 0.5 * (distanceAlong - length);

            if (0 > v1.DotProduct(v))
            {
                v1.Negate();
            }

            v1 = v1.Normalize();

            XYZ q0 = p0 + remainingPipeLength * v1;

            XYZ q1 = p1 - remainingPipeLength * v1;

            using (Transaction tx = new Transaction(doc))
            {
                // Determine pipe diameter for creating
                // matching pipes and fittings

                Pipe pipe = pipes[0];

                double diameter = pipe
                                  .get_Parameter(bipDiameter) // "Diameter"
                                  .AsDouble();

                // Pipe type for calls to doc.Create.NewPipe

                PipeType pipe_type_standard
                    = new FilteredElementCollector(doc)
                      .OfClass(typeof(PipeType))
                      .Cast <PipeType>()
                      .Where <PipeType>(e
                                        => e.Name.Equals("Standard"))
                      .FirstOrDefault <PipeType>();

                Debug.Assert(
                    pipe_type_standard.Id.IntegerValue.Equals(
                        pipe.PipeType.Id.IntegerValue),
                    "expected all pipes in this simple "
                    + "model to use the same pipe type");

                tx.Start("Rolling Offset");

                if (_place_model_line)
                {
                    // Trim or extend existing pipes

                    (pipes[0].Location as LocationCurve).Curve
                        = Line.CreateBound(p0, q0);

                    (pipes[1].Location as LocationCurve).Curve
                        = Line.CreateBound(p1, q1);

                    // Add a model line for the rolling offset pipe

                    Creator creator = new Creator(doc);

                    Line line = Line.CreateBound(q0, q1);

                    creator.CreateModelCurve(line);

                    pipe = null;
                }
                else if (_place_fittings)
                {
                    // Set active work plane to the rolling
                    // offset plane... removed again, since
                    // this has no effect at all on the
                    // fitting placement or rotation.
                    //
                    //Plane plane = new Plane( z, q0 );
                    //
                    //SketchPlane sp = SketchPlane.Create(
                    //  doc, plane );
                    //
                    //uidoc.ActiveView.SketchPlane = sp;
                    //uidoc.ActiveView.ShowActiveWorkPlane();

                    FamilySymbol symbol
                        = new FilteredElementCollector(doc)
                          .OfClass(typeof(FamilySymbol))
                          .OfCategory(BuiltInCategory.OST_PipeFitting)
                          .Cast <FamilySymbol>()
                          .Where <FamilySymbol>(e
                                                => e.Family.Name.Contains("Elbow - Generic"))
                          .FirstOrDefault <FamilySymbol>();

                    // Set up first 45 degree elbow fitting

                    FamilyInstance fitting0 = doc.Create
                                              .NewFamilyInstance(q0, symbol,
                                                                 StructuralType.NonStructural);

                    fitting0.LookupParameter("Angle").Set(
                        45.0 * Math.PI / 180.0);

                    //fitting0.get_Parameter( bipDiameter ) // does not exist
                    //  .Set( diameter );

                    fitting0.LookupParameter("Nominal Radius")
                    .Set(0.5 * diameter);

                    Line axis = Line.CreateBound(p0, q0);
                    angle = z.AngleTo(XYZ.BasisZ);

                    ElementTransformUtils.RotateElement(
                        doc, fitting0.Id, axis, Math.PI - angle);

                    Connector con0 = Util.GetConnectorClosestTo(
                        fitting0, p0);

                    // Trim or extend existing pipe

                    (pipes[0].Location as LocationCurve).Curve
                        = Line.CreateBound(p0, con0.Origin);

                    // Connect pipe to fitting

                    Util.Connect(con0.Origin, pipe, fitting0);

                    // Set up second 45 degree elbow fitting

                    FamilyInstance fitting1 = doc.Create
                                              .NewFamilyInstance(q1, symbol,
                                                                 StructuralType.NonStructural);

                    //fitting1.get_Parameter( "Angle" ).Set( 45.0 * Math.PI / 180.0 ); // 2014
                    //fitting1.get_Parameter( "Nominal Radius" ).Set( 0.5 * diameter ); // 2014

                    fitting1.LookupParameter("Angle").Set(45.0 * Math.PI / 180.0);  // 2015
                    fitting1.LookupParameter("Nominal Radius").Set(0.5 * diameter); // 2015

                    axis = Line.CreateBound(
                        q1, q1 + XYZ.BasisZ);

                    ElementTransformUtils.RotateElement(
                        doc, fitting1.Id, axis, Math.PI);

                    axis = Line.CreateBound(q1, p1);

                    ElementTransformUtils.RotateElement(
                        doc, fitting1.Id, axis, Math.PI - angle);

                    Connector con1 = Util.GetConnectorClosestTo(
                        fitting1, p1);

                    (pipes[1].Location as LocationCurve).Curve
                        = Line.CreateBound(con1.Origin, p1);

                    Util.Connect(con1.Origin, fitting1, pipes[1]);

                    con0 = Util.GetConnectorClosestTo(
                        fitting0, pm);

                    con1 = Util.GetConnectorClosestTo(
                        fitting1, pm);

                    // Connecting one fitting to the other does
                    // not insert a pipe in between. If the
                    // system is edited later, however, the two
                    // fittings snap together.
                    //
                    //con0.ConnectTo( con1 );

                    // Create rolling offset pipe segment

                    //pipe = doc.Create.NewPipe( con0.Origin, // 2014
                    //  con1.Origin, pipe_type_standard );

                    pipe = Pipe.Create(doc,
                                       pipe_type_standard.Id, levelId, con0, con1); // 2015

                    pipe.get_Parameter(bipDiameter)
                    .Set(diameter);

                    // Connect rolling offset pipe segment
                    // with elbow fittings at each end

                    Util.Connect(con0.Origin, fitting0, pipe);
                    Util.Connect(con1.Origin, pipe, fitting1);
                }
                else
                {
                    if (_use_static_pipe_create)
                    {
                        // Element id arguments to Pipe.Create.

                        ElementId idSystem;
                        ElementId idType;
                        ElementId idLevel;

                        // All these values are invalid for idSystem:

                        ElementId idSystem1 = pipe.MEPSystem.Id;
                        ElementId idSystem2 = ElementId.InvalidElementId;
                        ElementId idSystem3 = PipingSystem.Create(
                            doc, pipe.MEPSystem.GetTypeId(), "Tbc")
                                              .Id;

                        // This throws an argument exception saying
                        // The systemTypeId is not valid piping system type.
                        // Parameter name: systemTypeId

                        //pipe = Pipe.Create( doc, idSystem,
                        //  idType, idLevel, q0, q1 );

                        // Retrieve pipe system type, e.g.
                        // hydronic supply.

                        PipingSystemType pipingSystemType
                            = new FilteredElementCollector(doc)
                              .OfClass(typeof(PipingSystemType))
                              .OfType <PipingSystemType>()
                              .FirstOrDefault(st
                                              => st.SystemClassification
                                              == MEPSystemClassification
                                              .SupplyHydronic);

                        if (null == pipingSystemType)
                        {
                            message = "Could not find hydronic supply piping system type";
                            return(Result.Failed);
                        }

                        idSystem = pipingSystemType.Id;

                        Debug.Assert(pipe.get_Parameter(
                                         BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM)
                                     .AsElementId().IntegerValue.Equals(
                                         idSystem.IntegerValue),
                                     "expected same piping system element id");

                        // Retrieve the PipeType.

                        PipeType pipeType =
                            new FilteredElementCollector(doc)
                            .OfClass(typeof(PipeType))
                            .OfType <PipeType>()
                            .FirstOrDefault();

                        if (null == pipeType)
                        {
                            message = "Could not find pipe type";
                            return(Result.Failed);
                        }

                        idType = pipeType.Id;

                        Debug.Assert(pipe.get_Parameter(
                                         BuiltInParameter.ELEM_TYPE_PARAM)
                                     .AsElementId().IntegerValue.Equals(
                                         idType.IntegerValue),
                                     "expected same pipe type element id");

                        Debug.Assert(pipe.PipeType.Id.IntegerValue
                                     .Equals(idType.IntegerValue),
                                     "expected same pipe type element id");

                        // Retrieve the reference level.
                        // pipe.LevelId is not the correct source!

                        idLevel = pipe.get_Parameter(
                            BuiltInParameter.RBS_START_LEVEL_PARAM)
                                  .AsElementId();

                        // Create the rolling offset pipe.

                        pipe = Pipe.Create(doc,
                                           idSystem, idType, idLevel, q0, q1);
                    }
                    else
                    {
                        //pipe = doc.Create.NewPipe( q0, q1, pipe_type_standard ); // 2014

                        pipe = Pipe.Create(doc, systemTypeId,
                                           pipe_type_standard.Id, levelId, q0, q1); // 2015
                    }

                    pipe.get_Parameter(bipDiameter)
                    .Set(diameter);

                    // Connect rolling offset pipe segment
                    // directly with the neighbouring original
                    // pipes
                    //
                    //Util.Connect( q0, pipes[0], pipe );
                    //Util.Connect( q1, pipe, pipes[1] );

                    // NewElbowFitting performs the following:
                    // - select appropriate fitting family and type
                    // - place and orient a family instance
                    // - set its parameters appropriately
                    // - connect it with its neighbours

                    Connector con0 = Util.GetConnectorClosestTo(
                        pipes[0], q0);

                    Connector con = Util.GetConnectorClosestTo(
                        pipe, q0);

                    doc.Create.NewElbowFitting(con0, con);

                    Connector con1 = Util.GetConnectorClosestTo(
                        pipes[1], q1);

                    con = Util.GetConnectorClosestTo(
                        pipe, q1);

                    doc.Create.NewElbowFitting(con, con1);
                }

                tx.Commit();
            }
            return(Result.Succeeded);
        }
Exemplo n.º 4
0
        private void Stream( ArrayList data, PipingSystem pipingSys )
        {
            data.Add( new Snoop.Data.ClassSeparator( typeof( PipingSystem ) ) );

              data.Add( new Snoop.Data.Object( "Base equipment connector", pipingSys.BaseEquipmentConnector ) );
              data.Add( new Snoop.Data.Double( "Flow", pipingSys.Flow ) );
              data.Add( new Snoop.Data.Bool( "Is well connected", pipingSys.IsWellConnected ) );
              data.Add( new Snoop.Data.ElementSet( "Piping network", pipingSys.PipingNetwork ) );
              try
              {
            data.Add( new Snoop.Data.Double( "Static pressure", pipingSys.StaticPressure ) );
              }
              catch( Exception ex )
              {
            data.Add( new Snoop.Data.Exception( "Static Pressure", ex ) );
              }
              data.Add( new Snoop.Data.String( "System type", pipingSys.SystemType.ToString() ) );
        }
Exemplo n.º 5
0
        /// <summary>
        /// Write basic information of the MEP system into the XML file
        /// </summary>
        /// <param name="writer">XMLWriter object</param>
        private void WriteBasicInfo(XmlWriter writer)
        {
            MechanicalSystem ms = null;
            PipingSystem     ps = null;

            if (m_isMechanicalSystem)
            {
                ms = m_system as MechanicalSystem;
            }
            else
            {
                ps = m_system as PipingSystem;
            }

            // Write basic information of the system
            writer.WriteStartElement("BasicInformation");

            // Write Name property
            writer.WriteStartElement("Name");
            writer.WriteString(m_system.Name);
            writer.WriteEndElement();

            // Write Id property
            writer.WriteStartElement("Id");
            writer.WriteValue(m_system.Id.IntegerValue);
            writer.WriteEndElement();

            // Write UniqueId property
            writer.WriteStartElement("UniqueId");
            writer.WriteString(m_system.UniqueId);
            writer.WriteEndElement();

            // Write SystemType property
            writer.WriteStartElement("SystemType");
            if (m_isMechanicalSystem)
            {
                writer.WriteString(ms.SystemType.ToString());
            }
            else
            {
                writer.WriteString(ps.SystemType.ToString());
            }
            writer.WriteEndElement();

            // Write Category property
            writer.WriteStartElement("Category");
            writer.WriteAttributeString("Id", m_system.Category.Id.IntegerValue.ToString());
            writer.WriteAttributeString("Name", m_system.Category.Name);
            writer.WriteEndElement();

            // Write IsWellConnected property
            writer.WriteStartElement("IsWellConnected");
            if (m_isMechanicalSystem)
            {
                writer.WriteValue(ms.IsWellConnected);
            }
            else
            {
                writer.WriteValue(ps.IsWellConnected);
            }
            writer.WriteEndElement();

            // Write IsDefaultSystem property
            writer.WriteStartElement("IsDefaultSystem");
            writer.WriteValue(m_system.IsDefaultSystem);
            writer.WriteEndElement();

            // Write HasBaseEquipment property
            writer.WriteStartElement("HasBaseEquipment");
            bool hasBaseEquipment = ((m_system.BaseEquipment == null) ? false : true);

            writer.WriteValue(hasBaseEquipment);
            writer.WriteEndElement();

            // Write TerminalElementsCount property
            writer.WriteStartElement("TerminalElementsCount");
            writer.WriteValue(m_system.Elements.Size);
            writer.WriteEndElement();

            // Write Flow property
            writer.WriteStartElement("Flow");
            if (m_isMechanicalSystem)
            {
                writer.WriteValue(ms.Flow);
            }
            else
            {
                writer.WriteValue(ps.Flow);
            }
            writer.WriteEndElement();

            // Close basic information
            writer.WriteEndElement();
        }
Exemplo n.º 6
0
            public static bool Recognization(Pipe pipe)
            {
                _pipe = pipe;
                try
                {
                    _diameter = pipe.Diameter * 12;
                }
                catch
                {
                    _abandonWriter.WriteAbandonment(pipe, AbandonmentTable.Pipe_NonCircular);
                    return(false);
                }
                _length = pipe.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble();
                _level  = _doc.GetElement(pipe.get_Parameter(BuiltInParameter.RBS_START_LEVEL_PARAM).AsElementId()) as Level;
                _offset = pipe.get_Parameter(BuiltInParameter.RBS_START_OFFSET_PARAM).AsDouble();
                bool isFound;

                _floor = _myLevel.GetFloor(out isFound, _level, _offset) - 1;
                if (_floor == MyLevel.GetLevelNum() || _floor < 0)
                {
                    _abandonWriter.WriteAbandonment(pipe, AbandonmentTable.LevelOutOfRoof);
                    return(false);
                }
                SDC sdc = _addiInfo.sdc;

                _material = ((Material)_doc.GetElement(pipe.get_Parameter(BuiltInParameter.RBS_PIPE_MATERIAL_PARAM).AsElementId())).MaterialCategory;
                _pipeType = PipeType.Unknown;
                try
                {
                    PipingSystem     pipingSys     = pipe.MEPSystem as PipingSystem;
                    PipingSystemType pipingSysType = _doc.GetElement(pipingSys.GetTypeId()) as PipingSystemType;
                    FluidType        fluidType     = _doc.GetElement(pipingSysType.FluidType) as FluidType;
                    String           pstName       = pipingSysType.Name;

                    if (pstName.Contains("冷水"))
                    {
                        _pipeType = PipeType.ColdWater;
                    }
                    if (pstName.Contains("热水"))
                    {
                        _pipeType = PipeType.HotWater;
                    }
                    if (pstName.Contains("卫生"))
                    {
                        _pipeType = PipeType.SanitaryWater;
                    }
                    if (pstName.Contains("冷却"))
                    {
                        _pipeType = PipeType.ChilledWater;
                    }
                    if (pstName.Contains("蒸汽"))
                    {
                        _pipeType = PipeType.Steam;
                    }
                    if (pstName.Contains("消防"))
                    {
                        _pipeType = PipeType.FireSprinkler;
                    }

                    if (_pipeType == PipeType.Unknown)
                    {
                        double temperature = pipingSysType.FluidTemperature - 273.15;
                        if (5 < temperature && temperature < 15)
                        {
                            _pipeType = PipeType.ColdWater;
                        }
                        else if (30 < temperature && temperature < 100)
                        {
                            _pipeType = PipeType.HotWater;
                        }
                        else if (temperature <= 5)
                        {
                            _pipeType = PipeType.ChilledWater;
                        }
                        else if (100 <= temperature)
                        {
                            _pipeType = PipeType.Steam;
                        }
                        else
                        {
                            _abandonWriter.WriteAbandonment(pipe, AbandonmentTable.Pipe_TypeUnknown);
                            return(false);
                        }
                    }
                }
                catch
                {
                    _abandonWriter.WriteAbandonment(pipe, AbandonmentTable.Pipe_TypeUnknown);
                    return(false);
                }
                if (_pipeType != PipeType.ColdWater && !IsValidMaterial(_material))
                {
                    _abandonWriter.WriteAbandonment(_pipe, AbandonmentTable.Pipe_MatlOOR);
                    return(false);
                }

                return(true);
            }
Exemplo n.º 7
0
        //  Document doc;
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
        {
            //  doc = revit.Application.ActiveUIDocument.Document;
            // bg.DoWork += Bg_DoWork;

            //// TaskDialog.Show("Revit", "Hello World");
            // string value= UnitFormatUtils.Format(doc.GetUnits(), UnitType.UT_Piping_Slope, 0.0041, false, false);
            // revit.Application.ActiveUIDocument.Application.DialogBoxShowing += Application_DialogBoxShowing;
            // revit.Application.ActiveUIDocument.Application.ViewActivating += Application_ViewActivating;
            // if (value!=null)
            // {


            // }
            //  bg.RunWorkerAsync();


            // Form1 frm = new Form1(revit);
            // frm.Show();

            //var engine = Python.CreateEngine();
            //var paths = engine.GetSearchPaths();
            //List<string> src_path_list = new List<string>();
            //// src_path_list.Add(@"C:\Program Files (x86)\IronPython 2.7\Platforms\Net40\IronPython.Wpf.dll'");
            //paths.Add(@"D:\Revit-project\Api\DemoAddin\DemoAddin\Lib");
            //paths.Add(@"D:\Revit-project\Api\DemoAddin\DemoAddin\bin\Debug");
            //paths.Add(@"C:\Users\User\Downloads\pyRevit-4.7.4-final\pyRevit-4.7.4-final\pyrevitlib");
            //engine.SetSearchPaths(paths);
            // var source1 = engine.CreateScriptSourceFromFile(@"C:\Users\User\Downloads\pyRevit-4.7.4-final\pyRevit-4.7.4-final\bin\engines\pyRevitLoader.py");

            //  var scope1 = engine.CreateScope();
            //executing script in scope
            //  source1.Execute(scope1);
            // var builtin = IronPython.Hosting.Python.GetBuiltinModule(engine);
            // builtin.SetVariable("__revit__", revit.Application);
            // var source2 = engine.CreateScriptSourceFromFile(@"C:\Users\User\Downloads\pyRevit-4.7.4-final\pyRevit-4.7.4-final\extensions\pyRevitTools.extension\pyRevit.tab\Modify.panel\edit1.stack\Patterns.splitpushbutton\Make Pattern.pushbutton\patmaker.py");
            // // engine.ImportModule("framework");
            //// engine.SetSearchPaths(src_path_list);
            // var scope2 = engine.CreateScope();

            // //executing script in scope
            // source2.Execute(scope2);


            //var executor = new PyRevitLoader.ScriptExecutor(revit.Application); // uiControlledApplication);
            //Autodesk.Revit.UI.Result res = executor.ExecuteScript(@"C:\Users\User\Downloads\pyRevit-4.7.4-final\pyRevit-4.7.4-final\bin\engines\pyRevitLoader.py");


            //Autodesk.Revit.UI.Result res1 = executor.ExecuteScript(@"C:\Users\User\Downloads\pyRevit-4.7.4-final\pyRevit-4.7.4-final\extensions\pyRevitTools.extension\pyRevit.tab\Modify.panel\edit1.stack\Patterns.splitpushbutton\Make Pattern.pushbutton\patmaker.py");
            // PatTry(revit);

            Document       doc       = revit.Application.ActiveUIDocument.Document;
            Selection      s         = revit.Application.ActiveUIDocument.Selection;
            List <Element> elem_list = new List <Element>();

            if (s.GetElementIds().Count > 0)
            {
                FamilyInstance fi = doc.GetElement((s.GetElementIds().Cast <ElementId>().ToList().FirstOrDefault())) as FamilyInstance;
                foreach (Connector con in  fi.MEPModel.ConnectorManager.Connectors)
                {
                    if (con.MEPSystem != null)
                    {
                        if ((con.MEPSystem as PipingSystem) != null)
                        {
                            PipingSystem ps = (con.MEPSystem as PipingSystem);
                            foreach (Element elem in ps.PipingNetwork)
                            {
                                elem_list.Add(elem);
                            }
                        }
                        else if ((con.MEPSystem as MechanicalSystem) != null)
                        {
                            MechanicalSystem ms = (con.MEPSystem as MechanicalSystem);
                            foreach (Element elem in ms.DuctNetwork)
                            {
                                elem_list.Add(elem);
                            }
                        }
                    }
                }
            }
            if (elem_list.Count > 0)
            {
            }
            return(Result.Succeeded);
        }