程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> Revit API改變風管及管件尺寸

Revit API改變風管及管件尺寸

編輯:C#入門知識

start
 System;
 System.Collections.Generic;
 System.Linq;
 System.Text;

 WinForm = System.Windows.Forms;

 Autodesk.Revit.UI;
 Autodesk.Revit.DB;
 Autodesk.Revit.Attributes;

 Autodesk.Revit.DB.Mechanical;
 Autodesk.Revit.UI.Selection;
 Autodesk.Revit.ApplicationServices;

 Autodesk.Revit.DB.Structure;
 Autodesk.Revit.DB.ExtensibleStorage;
 Autodesk.Revit.DB.Plumbing;
 Autodesk.Revit.DB.Architecture;

 System.Xml;
 SelSet = HongYe.Revit.Public.SelectSet;
 Autodesk.Revit.DB.Electrical;
 System.Diagnostics;
 System.Security.Cryptography;
 System.IO;

 RevitCodes
{
                  RevitTool
    {
                                           IsConnectToDuct(FamilyInstance fi)
        {
             bResult = ;
            ConnectorSetIterator csi = fi.MEPModel.ConnectorManager.Connectors.ForwardIterator();
             (csi.MoveNext())
            {
                Connector conn = csi.Current  Connector;
                 (conn.IsConnected == )                {
                    ConnectorSet connectorSet = conn.AllRefs;                    ConnectorSetIterator csiChild = connectorSet.ForwardIterator();
                     (csiChild.MoveNext())
                    {
                        Connector connected = csiChild.Current  Connector;
                         ( != connected && connected.Owner.UniqueId != conn.Owner.UniqueId)
                        {
                                                                                     (connected.ConnectorType == ConnectorType.End ||
                                connected.ConnectorType == ConnectorType.Curve ||
                                connected.ConnectorType == ConnectorType.Physical)
                            {
                                                                 (connected.Owner  Duct)
                                {
                                    Duct duct = connected.Owner  Duct;
                                    Parameter pWidth = duct.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM);
                                    Parameter pHeight = duct.get_Parameter(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM);
                                                                    }
                                
                                {
                                    bResult = ;
                                    ;
                                }
                            }
                        }
                    }
                }
            }
             bResult;
        }
                                                           ChangeDuctSize(Duct duct,  sWidth,  sHeight)
        {
            Parameter pWidth = duct.get_Parameter(BuiltInParameter.RBS_CURVE_WIDTH_PARAM);
            Parameter pHeight = duct.get_Parameter(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM);
            pWidth.SetValueString(sWidth);
            pHeight.SetValueString(sHeight);
        }
                                                           ChangeFittingSize(FamilyInstance fi,  dWidth,  dHeight)
        {
            ConnectorSetIterator csi = fi.MEPModel.ConnectorManager.Connectors.ForwardIterator();
             (csi.MoveNext())
            {
                Connector conn = csi.Current  Connector;
                conn.Width = dWidth / ;
                conn.Height = dHeight / ;
            }
        }

                                                   isChange(FamilyInstance fi)
        {
             bChange = ;            XYZ xyzFace = GetFittingSolid(fi).Normal;
                         (xyzFace.AngleTo( XYZ(, , )) <  || xyzFace.AngleTo( XYZ(, , -)) < )
            {
                bChange = ;
            }
             bChange;
        }
                                                  PlanarFace GetFittingSolid(FamilyInstance fi)
        {
                         dWidth = , dHeight = ;
            ConnectorSetIterator csi = fi.MEPModel.ConnectorManager.Connectors.ForwardIterator();
             (csi.MoveNext())
            {
                Connector conn = csi.Current  Connector;
                dWidth = conn.Width;
                dHeight = conn.Height;
            }
                        PlanarFace resultFace = ;
            Solid resultSolid = ;
                        Options opt =  Options();
            opt.ComputeReferences = ;
            opt.DetailLevel = Autodesk.Revit.DB.DetailLevels.Medium;
                        GeometryElement e = fi.get_Geometry(opt);
             (GeometryObject obj  e.Objects)
            {
                GeometryInstance gi = obj  GeometryInstance;
                 (gi != )
                {
                    GeometryElement ge = gi.GetInstanceGeometry();
                     (GeometryObject go  ge.Objects)
                    {
                        Solid solid = go  Solid;
                         (solid !=  && solid.Faces.Size > )
                        {
                             isSolid = ;
                             (Face face  solid.Faces)
                            {
                                PlanarFace pf = face  PlanarFace;
                                 (pf != )
                                {
                                     (pf.Area < )                                    {
                                        isSolid = ;
                                    }
                                }
                            }
                             (isSolid)
                            {
                                resultSolid = solid;
                            }
                        }
                    }
                }
            }
                         dArea = dWidth * dHeight;
            PlanarFace sectionFace = ;
             (Face face  resultSolid.Faces)
            {
                 (Math.Abs(face.Area - dArea) < )                {
                    sectionFace = face  PlanarFace;
                    ;
                }
            }
                         (Face face  resultSolid.Faces)
            {
                PlanarFace pFace = face  PlanarFace;
                 (pFace != )
                {
                                         (Math.Abs(face.Area - dArea) < )                    {
                        ;
                    }
                    
                    {
                         dAngle = pFace.Normal.AngleTo(sectionFace.Normal);
                         (Math.Abs(dAngle - Math.PI / ) < )                        {
                            resultFace = pFace;
                        }
                    }
                }
            }
                         resultFace;
        }

                                                  List<Duct> GetDuctsFromElements(IList<Element> listElement)
        {
            List<Duct> listDuct =  List<Duct>();
             (Element el  listElement)
            {
                 (el  Duct)
                {
                    Duct duct = el  Duct;
                    listDuct.Add(duct);
                }
            }
             listDuct;
        }
                                                  List<FamilyInstance> GetFittingsFromElements(IList<Element> listElement)
        {
            List<FamilyInstance> listFitting =  List<FamilyInstance>();
             (Element el  listElement)
            {
                 (el  FamilyInstance)
                {
                    FamilyInstance fi = el  FamilyInstance;
                    listFitting.Add(fi);
                }
            }
             listFitting;
        }
    }
        [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
      cmdChangeSize1 : IExternalCommand
    {
         Result Execute(ExternalCommandData commandData,   messages, ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document doc = app.ActiveUIDocument.Document;
            Selection sel = app.ActiveUIDocument.Selection;

            Transaction ts =  Transaction(doc, );
                         dWidth = ;
             dHeight = ;
            IList<Element> listElement = sel.PickElementsByRectangle();
            List<Duct> listDuct = RevitTool.GetDuctsFromElements(listElement);
            List<FamilyInstance> listFi = RevitTool.GetFittingsFromElements(listElement);
                        ts.Start();
             (FamilyInstance fi  listFi)
            {
                RevitTool.ChangeFittingSize(fi, dWidth, dHeight);
            }
            ts.Commit();
                        ts.Start();
             (Duct duct  listDuct)
            {
                RevitTool.ChangeDuctSize(duct, dWidth.ToString(), dHeight.ToString());
            }
            ts.Commit();
                        ts.Start();
             (FamilyInstance fi  listFi)
            {
                 (!RevitTool.IsConnectToDuct(fi))                {
                     (Duct duct  listDuct)
                    {
                        RevitTool.ChangeDuctSize(duct, dHeight.ToString(), dWidth.ToString());
                    }
                }
            }
            ts.Commit();
            
             Result.Succeeded;
        }
    }

        [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
      cmdChangeSize2 : IExternalCommand
    {
         Result Execute(ExternalCommandData commandData,   messages, ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document doc = app.ActiveUIDocument.Document;
            Selection sel = app.ActiveUIDocument.Selection;

            Transaction ts =  Transaction(doc, );
            ts.Start();
                         dWidth = ;
             dHeight = ;
            IList<Element> listElement = sel.PickElementsByRectangle();
            List<Duct> listDuct = RevitTool.GetDuctsFromElements(listElement);
            List<FamilyInstance> listFi = RevitTool.GetFittingsFromElements(listElement);
                         (FamilyInstance fi  listFi)
            {
                RevitTool.ChangeFittingSize(fi, dWidth, dHeight);
                 (RevitTool.isChange(fi))
                {
                     (Duct duct  listDuct)
                    {
                        RevitTool.ChangeDuctSize(duct, dHeight.ToString(), dWidth.ToString());
                    }
                }
                
                {
                     (Duct duct  listDuct)
                    {
                        RevitTool.ChangeDuctSize(duct, dWidth.ToString(), dHeight.ToString());
                    }
                }
            }
            ts.Commit();

             Result.Succeeded;
        }

    }
}url:http://greatverve.cnblogs.com/p/duct-fitting-change-size.html

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved