private static int getCalculationElemSet(Document doc, string strDomain, ElementSet caculationOnElems, ElementSet elems)
        {
            if (doc == null)
            {
                return(0);
            }
            int nTotalCount = 0;

            foreach (Element elem in elems)
            {
                MEPSystem mepSys = elem as MEPSystem;
                if (mepSys == null)
                {
                    continue;
                }
                Category        category     = mepSys.Category;
                BuiltInCategory enumCategory = (BuiltInCategory)category.Id.IntegerValue;

                if ((strDomain == ReportResource.pipeDomain && enumCategory == BuiltInCategory.OST_PipingSystem) ||
                    (strDomain == ReportResource.ductDomain && enumCategory == BuiltInCategory.OST_DuctSystem))
                {
                    ++nTotalCount;
                    MEPSystemType sysType = doc.GetElement(mepSys.GetTypeId()) as MEPSystemType;
                    if (sysType != null && sysType.CalculationLevel == SystemCalculationLevel.All)
                    {
                        caculationOnElems.Insert(mepSys);
                    }
                }
            }
            return(nTotalCount);
        }
Example #2
0
        public bool isValidSystem(Document doc, MEPSystem mepSys, string strDomain)
        {
            if (mepSys == null || doc == null)
            {
                return(false);
            }

            if (mepSys.IsEmpty || !mepSys.IsValid)
            {
                return(false);
            }

            Category        category     = mepSys.Category;
            BuiltInCategory enumCategory = (BuiltInCategory)category.Id.IntegerValue;

            if (strDomain == ReportResource.pipeDomain && enumCategory != BuiltInCategory.OST_PipingSystem)
            {
                return(false);
            }

            if (strDomain == ReportResource.ductDomain && enumCategory != BuiltInCategory.OST_DuctSystem)
            {
                return(false);
            }

            MEPSystemType sysType = doc.GetElement(mepSys.GetTypeId()) as MEPSystemType;

            if (sysType == null)
            {
                return(false);
            }

            return(isValidSystemType(sysType));
        }
        public void getInfoDataTable(DataTable systemTB)
        {
            if (systemTB == null || system == null)
            {
                return;
            }

            systemTB.Columns.Add("SystemInfoName");
            systemTB.Columns.Add("SystemInfoValue");

            PressureLossReportHelper helper = PressureLossReportHelper.instance;

            if (helper == null)
            {
                return;
            }

            MEPSystemType sysType = helper.Doc.GetElement(system.GetTypeId()) as MEPSystemType;

            if (sysType != null)
            {
                systemTB.Rows.Add(LabelUtils.GetLabelFor(BuiltInParameter.RBS_SYSTEM_CLASSIFICATION_PARAM), system.get_Parameter(BuiltInParameter.RBS_SYSTEM_CLASSIFICATION_PARAM).AsString());

                if (helper.Domain == ReportResource.ductDomain)
                {
                    systemTB.Rows.Add(LabelUtils.GetLabelFor(BuiltInParameter.RBS_DUCT_SYSTEM_TYPE_PARAM), sysType.Name);
                }
                else
                {
                    systemTB.Rows.Add(LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM), sysType.Name);
                }
                systemTB.Rows.Add(LabelUtils.GetLabelFor(BuiltInParameter.RBS_SYSTEM_NAME_PARAM), system.Name);
                systemTB.Rows.Add(LabelUtils.GetLabelFor(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM), sysType.Abbreviation);

                if (helper.Domain == ReportResource.pipeDomain) // need to list fluid info
                {
                    //Fluid type is an element id
                    ElementId elemId       = sysType.get_Parameter(BuiltInParameter.RBS_PIPE_FLUID_TYPE_PARAM).AsElementId();
                    string    strFluidType = "";
                    if (elemId != null)
                    {
                        Element elem = helper.Doc.GetElement(elemId);
                        if (elem != null)
                        {
                            strFluidType = elem.Name;
                        }
                    }
                    systemTB.Rows.Add(sysType.get_Parameter(BuiltInParameter.RBS_PIPE_FLUID_TYPE_PARAM).Definition.Name, strFluidType);
                    helper.addParameterNameAndValueToTable(systemTB, sysType.get_Parameter(BuiltInParameter.RBS_PIPE_FLUID_TEMPERATURE_PARAM), false);
                    helper.addParameterNameAndValueToTable(systemTB, sysType.get_Parameter(BuiltInParameter.RBS_PIPE_FLUID_VISCOSITY_PARAM), false);
                    helper.addParameterNameAndValueToTable(systemTB, sysType.get_Parameter(BuiltInParameter.RBS_PIPE_FLUID_DENSITY_PARAM), false);
                }
            }

            return;
        }
        public MEPSystemInfo(MEPSystem systemElem)
        {
            system = systemElem;
             if (system == null)
            return;

             PressureLossReportHelper helper = PressureLossReportHelper.instance;
             if (helper == null)
            return;

             MEPSystemType sysType = helper.Doc.GetElement(system.GetTypeId()) as MEPSystemType;
             if (sysType != null)
            helper.SystemClassification = sysType.SystemClassification;
        }
Example #5
0
        public List <MEPSystemType> getSelectedSystemTypes(bool bOnlySelectedSystemType = false)
        {
            if (doc == null)
            {
                return(null);
            }

            if (selElems.Size > 0)
            {
                List <MEPSystemType> sysTypes = new List <MEPSystemType>();
                foreach (Element elem in selElems)
                {
                    if (elem == null)
                    {
                        continue;
                    }

                    MEPSystemType mepSysType = null;

                    if (!bOnlySelectedSystemType)
                    {
                        MEPSystem mepSys = elem as MEPSystem;
                        if (mepSys != null && isValidSystem(doc, mepSys, Domain))
                        {
                            mepSysType = doc.GetElement(mepSys.GetTypeId()) as MEPSystemType;
                        }
                    }

                    if (mepSysType == null)
                    {
                        mepSysType = elem as MEPSystemType;
                    }
                    if (mepSysType == null || !isValidSystemType(mepSysType))
                    {
                        continue;
                    }

                    if (!isSystemTypeInList(sysTypes, mepSysType))
                    {
                        sysTypes.Add(mepSysType);
                    }
                }

                return(sysTypes);
            }

            return(null);
        }
Example #6
0
 public static string MEPSystemAbbreviation(this Connector con, Document doc, bool ignoreMepSystemNull = false)
 {
     if (con.MEPSystem != null)
     {
         MEPSystem        ps  = con.MEPSystem;
         PipingSystemType pst = (PipingSystemType)doc.GetElement(ps.GetTypeId());
         return(pst.Abbreviation);
     }
     else if (ignoreMepSystemNull)
     {
         return("");
     }
     else
     {
         throw new Exception($"A connector at element {con.Owner.Id.IntegerValue} has MEPSystem = null!");
     }
 }
Example #7
0
        public bool isSelectInValidSystemType()
        {
            if (doc == null)
            {
                return(false);
            }

            if (selElems.Size > 0)
            {
                MEPSystemType mepSysType = null;
                foreach (Element elem in selElems)
                {
                    if (elem == null)
                    {
                        continue;
                    }

                    mepSysType = null;

                    MEPSystem mepSys = elem as MEPSystem;
                    if (mepSys != null && isValidSystem(doc, mepSys, Domain))
                    {
                        mepSysType = doc.GetElement(mepSys.GetTypeId()) as MEPSystemType;
                    }

                    if (mepSysType == null)
                    {
                        mepSysType = elem as MEPSystemType;
                    }
                    if (mepSysType == null)
                    {
                        continue;
                    }
                    if (!isValidSystemType(mepSysType))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public MEPSystemInfo(MEPSystem systemElem)
        {
            system = systemElem;
            if (system == null)
            {
                return;
            }

            PressureLossReportHelper helper = PressureLossReportHelper.instance;

            if (helper == null)
            {
                return;
            }

            MEPSystemType sysType = helper.Doc.GetElement(system.GetTypeId()) as MEPSystemType;

            if (sysType != null)
            {
                helper.SystemClassification = sysType.SystemClassification;
            }
        }
Example #9
0
        public MEPSystemType getSystemType(Document doc, MEPSystem mepSys)
        {
            MEPSystemType sysType = doc.GetElement(mepSys.GetTypeId()) as MEPSystemType;

            return(sysType);
        }
Example #10
0
    private void SplitPipe( Element segment, MEPSystem _system, UIDocument _activeDoc, ElementId _systemtype, PipeType _pipeType )
    {
      ElementId levelId = segment.get_Parameter( 
        BuiltInParameter.RBS_START_LEVEL_PARAM )
          .AsElementId();

      // system.LevelId;
      ElementId systemtype = _system.GetTypeId();

      // selecting one pipe and taking its location.
      Curve c1 = (segment.Location as LocationCurve).Curve; 

      //Pipe diameter
      double pipeDia = UnitUtils.ConvertFromInternalUnits( 
        segment.get_Parameter( BuiltInParameter.RBS_PIPE_DIAMETER_PARAM ).AsDouble(), 
        DisplayUnitType.DUT_MILLIMETERS );

      //Standard length
      double l = 6000;

      //Coupling length
      double fittinglength = (1.1 * pipeDia + 14.4);

      // finding the length of the selected pipe.
      double len = UnitUtils.ConvertFromInternalUnits( segment.get_Parameter( BuiltInParameter.CURVE_ELEM_LENGTH ).AsDouble(), DisplayUnitType.DUT_MILLIMETERS );

      if( len <= l )
        return;

      var startPoint = c1.GetEndPoint( 0 );
      var endPoint = c1.GetEndPoint( 1 );

      XYZ splitpoint = (endPoint - startPoint) * (l / len);

      var newpoint = startPoint + splitpoint;

      Pipe pp = segment as Pipe;

      // Find two connectors which pipe's two ends connector connected to. 
      Connector startConn = FindConnectedTo( pp, startPoint );
      Connector endConn = FindConnectedTo( pp, endPoint );

      // creating first pipe 
      Pipe pipe = null;
      if( null != _pipeType )
      {
        pipe = Pipe.Create( _activeDoc.Document, 
          _pipeType.Id, levelId, startConn, newpoint );
      }

      Connector conn1 = FindConnector( pipe, newpoint );

      //Check + fitting
      XYZ fittingend = (endPoint - startPoint) 
        * ((l + (fittinglength / 2)) / len);

      //New point after the fitting gap
      var endOfFitting = startPoint + fittingend;

      Pipe pipe1 = Pipe.Create( _activeDoc.Document, 
        systemtype, _pipeType.Id, levelId, endOfFitting, 
        endPoint );

      // Copy parameters from previous pipe to the following Pipe. 
      CopyParameters( pipe, pipe1 );
      Connector conn2 = FindConnector( pipe1, endOfFitting );
      _ = _activeDoc.Document.Create.NewUnionFitting( conn1, conn2 );

      if( null != endConn )
      {
        Connector pipeEndConn = FindConnector( pipe1, endPoint );
        pipeEndConn.ConnectTo( endConn );
      }

      ICollection<ElementId> deletedIdSet 
        = _activeDoc.Document.Delete( segment.Id );

      if( 0 == deletedIdSet.Count )
      {
        throw new Exception( "Deleting the selected elements in Revit failed." );
      }

      if( UnitUtils.ConvertFromInternalUnits( 
        pipe1.get_Parameter( BuiltInParameter.CURVE_ELEM_LENGTH ).AsDouble(), 
        DisplayUnitType.DUT_MILLIMETERS ) > l )
      {
        SplitPipe( pipe1, _system, _activeDoc, _systemtype, _pipeType );
      }
    }
Example #11
0
    // The main Execute method (inherited from IExternalCommand) must be public
    public Result Execute( ExternalCommandData revit,
        ref string message, ElementSet elements )
    {
      try
      {
        // Verify if the active document is null
        UIDocument activeDoc = revit.Application.ActiveUIDocument;
        if( activeDoc == null )
        {
          TaskDialog.Show( "No Active Document", "There's no active document in Revit.", TaskDialogCommonButtons.Ok );
          return Autodesk.Revit.UI.Result.Failed;
        }

        // Verify the number of selected elements
        ElementSet selElements = new ElementSet();
        foreach( ElementId elementId in activeDoc.Selection.GetElementIds() )
        {
          selElements.Insert( activeDoc.Document.GetElement( elementId ) );
        }
        if( selElements.Size != 1 )
        {
          message = "Please select ONLY one element from current project.";
          return Autodesk.Revit.UI.Result.Failed;
        }

        // Get the selected element
        Element selectedElement = null;
        foreach( Element element in selElements )
        {
          selectedElement = element;
          break;
        }


        MEPSystem system = ExtractMechanicalOrPipingSystem( selectedElement );
        if( system == null )
        {
          message = "Error! Check the system conectivity";
          return Autodesk.Revit.UI.Result.Failed;
        }

        List<Element> pipes = new List<Element>();
        FilteredElementCollector collector = new FilteredElementCollector( activeDoc.Document );
        collector.OfClass( typeof( PipeType ) );
        PipeType pipeType = collector.FirstElement() as PipeType;

        Selection sel = activeDoc.Selection;

        foreach( ElementId eId in sel.GetElementIds() )
        {
          Element e = activeDoc.Document.GetElement( eId );
          Pipe c = e as Pipe;
          pipeType = c.PipeType;

          if( null != c )
          {
            pipes.Add( c );
            if( 2 == pipes.Count )
            {
              break;
            }
          }
        }

        using( Transaction tx = new Transaction( activeDoc.Document ) )
        {
          tx.Start( "split pipe" );
          ElementId systemtype = system.GetTypeId();
          SplitPipe( pipes[ 0 ], system, activeDoc, systemtype, pipeType );
          tx.Commit();
        }
        return Autodesk.Revit.UI.Result.Succeeded;
      }
      catch( Exception ex )
      {
        message = ex.Message;
        return Autodesk.Revit.UI.Result.Failed;
      }
    }