Revit API 中的關聯式分析模型

在分析塑型的環境中探索新開發的 API。

此專案是 Revit 更廣泛的「分析驅動塑型」計畫的一部分,此計畫對分析塑型引入一個創新的方法,以增強其整體結構塑型功能。分析模型是 BIM 資料的重要部分,受工程團隊內及各專案團隊間協同合作工作流程的規範,因此,Revit 的新功能和行為讓工程師能夠:

具有新 API 的 Revit 元素

新的 API 類別

AnalyticalElement - 代表所有分析物件的基礎類別。取代了 AnalyticalModel。

AnalyticalMember - 代表結構分析模型中的線性元素。取代了 AnalyticalModelStick 和 AnalyticalModelColumn。

AnalyticalPanel - 代表結構分析模型中的表面。取代了 AnalyticalModelSurface。
  • AnalyticalPanel Create(Document aDoc, CurveLoop curveLoop) - Method which creates a new instance of an Analytical Panel within the project.
  • CurveLoop GetOuterContour() - Returns the Curve Loop that defines the geometry of the Analytical Surface element.
  • bool IsCurveLoopValid(CurveLoop profile) - Checks if curve loop is valid for Analytical Panel.
    • 若要修改「分析嵌板」幾何圖形,使用者應使用 SketchEditScope 架構。此功能已使用新方法增強:
      •  void StartWithNewSketch(ElementId elementId) - Starts a sketch edit mode for an element which, at this moment, doesn't have a sketch.
    • 編輯幾何圖形的另一種方式是:
      • void SetOuterContour(CurveLoop outerContour) - Sets the Curve Loop that defines the geometry of the Analytical Surface element.


      • 與 AnalyticalMember 類似,設定分析嵌板的輪廓線會切斷與其他分析元素的連接。如果使用者要移動轉角並保持連接,還有其他方法可以達成,例如 ElementTransformUtils.moveElements。

  •  ISet<ElementId> GetAnalyticalOpeningsIds() - Returns the Analytical Openings Ids of the Analytical Panel.
  • ElementId SketchId - Sketch associated to this Revit element.
    
  • AnalyticalStructuralRole StructuralRole - Structural role assigned to the Analytical Panel.
AnalyticalOpening - 代表「分析嵌板」中開口的元素。這是 Revit API 中的新物件 (在此版本之前,分析開口沒有單獨的元素)。
  • AnalyticalOpening Create(Document doc, CurveLoop curveLoop, ElementId panelId) - Method which creates a new instance of an Analytical Opening within the project.
  • CurveLoop GetOuterContour () - Returns the Curve Loop that defines the geometry of the Analytical Surface element.
    
  •  bool IsCurveLoopValidForAnalyticalOpening(CurveLoop loop, Document aDoc, ElementId panelId) - Checks if curve loop is valid for Analytical Opening.
    • 若要修改「分析開口」幾何圖形,請使用 SketchEditScope 架構。
    • 修改「分析開口」幾何圖形的另一種方式是:
      •  void SetOuterContour(CurveLoop outerContour) - Sets the Curve Loop that defines the geometry of the Analytical Surface element.
  • ElementId PanelId - ElementId of the host Analytical Panel.
    
  •  ElementId SketchId - Sketch associated to this Revit element.

AnalyticalToPhysicalAssociationManager - 管理分析元素與實體元素之間的關聯。先前,元素本身彼此互相了解,使用者無法控制元素 (無法修改關聯)。使用此新方法可以編輯關聯。支援 1 對 1 關聯,元素不能同時是多個關聯的一部分。

AnalyticalNodeData - 保留分析節點連接狀態的相關資訊。
  • AnalyticalNodeData GetAnalyticalNodeData ( Element element) - Returns AnalyticalNodeData associated with this element, if it exists.
    
  • AnalyticalNodeConnectionStatus GetConnectionStatus () - Returns the Connections Status for an
    Analytical Node.

AnalyticalLink、BoundaryCondition 和 Load 已移轉為與新元素搭配運作。在大多數情況下,與它們相關的 API 會保持不變。Load 已做了一些增強。

Load
  •  LineLoad.Create(Document aDoc,ElementId hostElemId, XYZ forceVector1, XYZmomentVector1, LineLoadType symbol).
  •  LineLoad.Create(Document aDoc,ElementId hostElemId, int curveIndex, XYZ forceVector1, XYZ momentVector1, Structure.LineLoadType symbol).
  •  LineLoad.IsValidHostId(Document doc, ElementId hostElemId).
  •  AreaLoad.IsValidHostId(Document doc, ElementId hostElemId).
  •  AreaLoad.Create(Document doc, ElementId hostElemId, XYZ forceVector1, AreaLoadType symbol).
  •  PointLoad.Create(Document doc, ElementId hostElemId, AnalyticalElementSelector selector, XYZ forceVector, XYZ momentVector, AreaLoadTyp 
    symbol).
  • PointLoad.IsValidHostId(Document doc, ElementId hostElemId).

範例

建立分析構件

      using (Transaction transaction = new Transaction(document, "Create Analytical Member"))
               {
                  transaction.Start();
                  //create curve which will be assigned to the analytical member
                  Line line = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(5, 0, 0));
                  //create the AnalyticalMember
                  AnalyticalMember analyticalMember = AnalyticalMember.Create(document, line);
                  analyticalMember.StructuralRole = AnalyticalStructuralRole.StructuralRoleBeam;
                  transaction.Commit();
                }

建立分析嵌板

 using (Transaction transaction = new Transaction(revitDoc, "Create Analytical Panel"))
         {
            transaction.Start();
            //create the curveLoop for the AnalyticalPanel element
            CurveLoop profileloop = new CurveLoop();
            profileloop.Append(Line.CreateBound(new XYZ(1, 1, 0), new XYZ(2, 1, 0)));
            profileloop.Append(Line.CreateBound(new XYZ(2, 1, 0), new XYZ(2, 2, 0)));
            profileloop.Append(Line.CreateBound(new XYZ(2, 2, 0), new XYZ(1, 2, 0)));
            profileloop.Append(Line.CreateBound(new XYZ(1, 2, 0), new XYZ(1, 1, 0)));
            //create the AnalyticalPanel 
            analyticalPanel = AnalyticalPanel .Create(revitDoc, profileloop);
            transaction.Commit();
          }

在實體元素與分析元素之間加入新關聯

using (Transaction trans = new Transaction(doc, "AddAssociationBetweenPhysicalAndAnalyticalElements"))
 {
            trans.Start();
            ElementId analyticalElementId = ContextualAnalyticalModel.Utilities.GetSelectedObject(activeDoc, "Please select analytical element");
            ElementId physicalElementId = ContextualAnalyticalModel.Utilities.GetSelectedObject(activeDoc, "Please select physical element");
            //gets the AnalyticalToPhysicalAssociationManager for the current document
            AnalyticalToPhysicalAssociationManager analyticalToPhysicalManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(doc);
            if (analyticalToPhysicalManager == null)
               return Result.Failed;
            //creates a new association between physical and analytical elements
            analyticalToPhysicalManager.AddAssociation(analyticalElementId, physicalElementId);
            trans.Commit();
  }

使用 SketchEditScope 架構編輯分析嵌板的邊界



             // Start a sketch edit scope
             SketchEditScope sketchEditScope = new SketchEditScope(document, "Replace line with an arc");
               sketchEditScope.StartWithNewSketch(analyticalPanel.Id);
               using (Transaction transaction = new Transaction(document, "Modify sketch"))
               {
                  transaction.Start();
                  //replace a boundary line with an arc
                  Line line = null;
                  Sketch sketch = document.GetElement(analyticalPanel.SketchId) as Sketch;
                  if (sketch != null)
                  {
                     //find first line in the sketch profile
                    …..
                  }
  	              // Create arc
                  XYZ normal = line.Direction.CrossProduct(XYZ.BasisZ).Normalize().Negate();
                  XYZ middle = line.GetEndPoint(0).Add(line.Direction.Multiply(line.Length / 2));
                  Curve arc = Arc.Create(line.GetEndPoint(0), line.GetEndPoint(1), middle.Add(normal.Multiply(20)));
                  // Remove element referenced by the found line. 
                  document.Delete(line.Reference.ElementId);
                  // Model curve creation automatically puts the curve into the sketch, if sketch edit scope is running.
                  document.Create.NewModelCurve(arc, sketch.SketchPlane);
                  transaction.Commit();
               }
               sketchEditScope.Commit(new FailurePreproccessor());

移動分析節點並保持連接



            // Create Analytical Panel
            AnalyticalPanel analyticalPanel = CreateAnalyticalPanel.CreateAMPanel(document);
            // Create the connected Analytical Member
            AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document);
            // Select the node
            Reference eRef = activeDoc.Selection.PickObject(ObjectType.PointOnElement , "Select an Analytical Node");
          
            // Move the Analytical Node using ElementTransformUtils
            using (Transaction transaction = new Transaction(document, "Move node with ElementTransformUtils"))
            {
               transaction.Start();
               ElementTransformUtils.MoveElement(document, eRef.ElementId, new XYZ(-5, -5, 0));
               transaction.Commit();
            }

取得分析表面輪廓線點

使用先前的解決方案:
    
      private List<XYZ> GetSurfaceContourPoints( Document doc, ElementId elementId )
      {
         	// Create point list, get list of curves from analytical model
         	List<XYZ> contourPoints = new List<XYZ>();
         	AnalyticalModel analyticalModel = (doc.GetElement(elementId) as AnalyticalModel);
         	IList<Curve> curves = analyticalModel.GetCurves(AnalyticalCurveType.RawCurves);
         
         	// Iterate over curves and make the desired processing   
         …...	
        	return contourPoints;
      }
使用新的解決方案:
     
      private List<XYZ> GetSurfaceContourPoints( Document doc, ElementId elementId )
      {
         	// Create point list, get list of curves from analytical model
         	List<XYZ> contourPoints = new List<XYZ>();
         	AnalyticalPanel analyticalPanel = (doc.GetElement(elementId) as AnalyticalPanel);
          CurveLoop outerContour = analyticalPanel.GetOuterContour();
         
         	// Iterate over curves and make the desired processing 
          …...	
        	return contourPoints;
      }

為實體分析元素取得關聯的分析元素

     
      AnalyticalElement GetAnalyticalElement(Element physicalElement)
      {
         AnalyticalElement analyticalElement = null;
         Document document = element.Document;
         AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document);
         if (assocManager != null)
         {
            ElementId associatedElementId = assocManager.GetAssociatedElementId(physicalElement.Id);
            if (associatedElementId != ElementId.InvalidElementId)
            {
               Element associatedElement = document.GetElement(associatedElementId);
               if (associatedElement != null && associatedElement is AnalyticalElement)
               {
                  analyticalElement = associatedElement as AnalyticalElement;
               }
            }
         }
         return analyticalElement;
      }

建立線邊界條件

使用先前的解決方案:

       
        private BoundaryConditions CreateLineBC(Element hostElement)
        {
										    Document createDoc = hostElement.Document.Create;
 
             	// use Document.NewLineBoundaryConditions Method
              BoundaryConditions createdBC = 
                    createDoc.NewLineBoundaryConditions(hostElement.GetAnalyticalModel(), 0, 0, 0, 0, 0, 0, 0, 0);
 
            return createdBC;
        }

使用新的解決方案:

      private BoundaryConditions CreateLineBC(Element hostElement)
      {
         Document createDoc = hostElement.Document.Create;

         // use Document.NewLineBoundaryConditions Method
         AnalyticalElement analyticalElement = GetAnalyticalElement(hostElement);
         BoundaryConditions createdBC =
                    createDoc.NewLineBoundaryConditions(analyticalElement, 0, 0, 0, 0, 0, 0, 0, 0);
         return createdBC;
      }