NewRebar--Revit新钢筋创建方法
新钢筋创建方法——NewRebar——High
This sample will demonstrate how to create rebar via NewRebar (RebarShape rebarShape, RebarBarType rebarType, Element host, XYZ origin, XYZ xVec, XYZ yVec) and how to customize RebarShape (include straight segment and arc shape).
如何通过新的钢筋创建函数来创建钢筋以及如何定制钢筋的形状(RebarShape -包括直线段,弧线段)
效果图
1、Filter的组合
// Or 方式的filter
LogicalOrFilter stFilter = new LogicalOrFilter(
new ElementStructuralTypeFilter(StructuralType.Beam),
new ElementStructuralTypeFilter(StructuralType.Column));
// + StructuralMaterial
// and方式的filter
LogicalAndFilter hostFilter = new LogicalAndFilter(stFilter,
new StructuralMaterialTypeFilter(StructuralMaterialType.Concrete));
// Expected rebar host: it should be family instance
FilteredElementCollector collector = new FilteredElementCollector(m_rvtUIDoc.Document, selectedIds);
FamilyInstance rebarHost = collector.OfClass(typeof(FamilyInstance)).WherePasses(hostFilter).FirstElement() as FamilyInstance;
2、钢筋创建
|——Rebar.CreateFromRebarShape
param | description |
---|---|
doc | Document,Revit本身doc |
rebarShape | Autodesk.Revit.DB.Structure.RebarShape——钢筋形状 |
barType | Autodesk.Revit.DB.Structure.RebarBarType——8 HRB400 |
host | Autodesk.Revit.DB.Structure.RebarHostData中可以包含钢筋的宿主元素 |
origin | 包围盒左下角 |
xVec | 钢筋形状X轴方向 |
yVec | 钢筋形状Y轴方向 |
3、RebarShape的创建
|——parameter
|——RebarShapeDefinition.AddParameter() – 一般参数
|——RebarShapeDefinition.AddFormulaParameter()–公式
|——Constraint
|——RebarShapeDefinitionByArc
|——RebarShapeDefinitionBySegments
定义Segments Shape
定义LappedCircle
定义Arc Shape
定义Arc Shape2
public void Commit(Document rvtDoc, DefinitionGroup defGroup)
{
// Submit all the parameters.参数添加
foreach (RebarShapeParameter param in m_parameters)
{
param.Commit(rvtDoc, defGroup);
}
// Submit all the constraints.增加约束
foreach (ConstraintOnRebarShape constraint in m_constraints)
{
constraint.Commit();
}
// Submit the RebarShape.判断创建是否完成
if (m_rebarshapeDefinition.Complete)
{
m_rebarshapeDefinition.CheckDefaultParameterValues(0, 0);
}
else
{
throw new Exception("The Rebar shape definition is not completed.");
}
}
// Add a double parameter to RebarShapeDefinition 创建double类型的参数
public override void Commit(Autodesk.Revit.DB.Document doc, DefinitionGroup defGroup)
{
ExternalDefinition def = GetOrCreateDef(defGroup);
m_parameterId = Autodesk.Revit.DB.Structure.RebarShapeParameters.GetOrCreateElementIdForExternalDefinition(doc, def);
m_rebarShapeDef.RebarshapeDefinition.AddParameter(m_parameterId, m_value);
}
// Add a formula parameter to RebarShapeDefinition. 创建公式参数
public override void Commit(Autodesk.Revit.DB.Document doc, DefinitionGroup defGroup)
{
ExternalDefinition def = GetOrCreateDef(defGroup);
m_parameterId = Autodesk.Revit.DB.Structure.RebarShapeParameters.GetOrCreateElementIdForExternalDefinition(doc, def);
m_rebarShapeDef.RebarshapeDefinition.AddFormulaParameter(m_parameterId, m_formula);
}
// Add dimension to constrain the radius of arc.创建ARC类型的约束
public override void Commit()
{
GetRebarShapeDefinitionByArc.AddConstraintRadius(
RebarShapeParameter.Parameter, ArcReferenceType);
}
// Add Dimension to constrain the segment length.创建Segment类型的长度约束
public override void Commit()
{
GetRebarShapeDefinitionBySegments.AddConstraintParallelToSegment(
m_segment, m_parameter.Parameter, m_measureToOutsideOfBend0,
m_measureToOutsideOfBend1);
}
4、约束条件
RebarShapeDrivenAccessor rebarShapeDrivenAccessor = m_createdRebar.GetShapeDrivenAccessor();
if (arcDef != null && arcDef.Type == RebarShapeDefinitionByArcType.Spiral)
{
rebarShapeDrivenAccessor.ScaleToBoxFor3D(origin, xVec, yVec, 5.0);
rebarShapeDrivenAccessor.Height = m_geometryData.DrivingLength - 0.1;
rebarShapeDrivenAccessor.Pitch = 0.1;
rebarShapeDrivenAccessor.BaseFinishingTurns = 3;
rebarShapeDrivenAccessor.TopFinishingTurns = 3;
}
else
{
rebarShapeDrivenAccessor.ScaleToBox(origin, xVec, yVec);
double barSpacing = 0.1;
int barNum = (int)(m_geometryData.DrivingLength / barSpacing);
rebarShapeDrivenAccessor.SetLayoutAsNumberWithSpacing(
barNum, barSpacing, true, true, true);
}
BIM树洞
做一个静谧的树洞君
用建筑的语言描述IT事物;
用IT的思维解决建筑问题;
共建BIM桥梁,聚合团队。
本学习分享资料不得用于商业用途,仅做学习交流!!如有侵权立即删除!!
-
微信公众号: BIM树洞
-
知乎专栏:BIM树洞
-
气氛组博客:http://www.31bim.com
-
BIM应用及咨询,CAD,Revit, OpenGL,图形开发交流,加Q群1083064224