不包含已单独写博客部分。
AllViews
创建图纸,并放置视图。
ViewSheet sheet = ViewSheet.Create(doc, m_titleBlock.Id);
double xDistance = 0;
double yDistance = 0;
CalculateDistance(sheet.Outline, views.Size, ref xDistance, ref yDistance);
Autodesk.Revit.DB.UV origin = GetOffSet(sheet.Outline, xDistance, yDistance);
double tempU = origin.U;
double tempV = origin.V;
int n = 1;
foreach (Autodesk.Revit.DB.View v in views) {
Autodesk.Revit.DB.UV location = new Autodesk.Revit.DB.UV(tempU, tempV);
Autodesk.Revit.DB.View view = v;
Rescale(view, xDistance, yDistance);
Viewport.Create(view.Document, sheet.Id, view.Id, new XYZ(location.U, location.V, 0));
if (0 != n++ % m_rows) {
tempU = tempU + xDistance * (1 - TITLEBAR);
} else {
tempU = origin.U;
tempV = tempV + yDistance;
}
AnalyticalSupportData_Info
获取 Support Type 的逻辑:
AnalyticalModel analyticalModel = element.GetAnalyticalModel();
string[] supportInformations = new string[2] { "", "" };
IList<AnalyticalModelSupport> supports = analyticalModel.GetAnalyticalModelSupports();
if (!analyticalModel.IsElementFullySupported()) {
if (0 == supports.Count) {
supportInformations[0] = "not supported";
} else {
foreach (AnalyticalModelSupport support in supports) {
supportInformations[0] = supportInformations[0] + support.GetSupportType().ToString() + ", ";
}
}
} else {
if (0 == supports.Count) {
supportInformations[1] = "supported but no more information";
} else {
foreach (AnalyticalModelSupport support in supports) {
supportInformations[0] = supportInformations[0] + support.GetSupportType().ToString() + ", ";
}
}
AreaReinCurve
AreaReinforcement
区域钢筋,参考官方文档。
下面是获取区域钢筋的曲线,其它都是设置参数 Parameter
。
AreaReinforcement m_areaRein = areaReinforcement;
CurveArray curves = new CurveArray();
List<AreaReinforcementCurve> m_areaReinCurves = new List<AreaReinforcementCurve>();
IList<ElementId> curveIds = m_areaRein.GetBoundaryCurveIds();
foreach (ElementId o in curveIds) {
AreaReinforcementCurve areaCurve = m_doc.GetElement(o) as AreaReinforcementCurve;
m_areaReinCurves.Add(areaCurve);
curves.Append(areaCurve.Curve);
}
AreaReinParameters
钢筋弯钩,参考文档。
namespace Autodesk.Revit.DB.Structure
{
public class RebarHookType : ElementType
{
public double StraightLineMultiplier { get; set; }
public double HookAngle { get; set; }
public RebarStyle Style { get; set; }
public static RebarHookType Create(Document doc, double angle, double multiplier);
public static ElementId CreateDefaultRebarHookType(Document ADoc);
public double GetDefaultHookExtension(double barDiameter);
public double GetHookExtensionLength(RebarBarType barType);
public bool IsOffsetLengthRequired();
}
}
namespace Autodesk.Revit.DB.Structure
{
public class RebarBarType : ElementType
{
public double MaximumBendRadius { get; set; }
public double StandardBendDiameter { get; set; }
public double StandardHookBendDiameter { get; set; }
public double StirrupTieBendDiameter { get; set; }
public double BarDiameter { get; set; }
public RebarDeformationType DeformationType { get; set; }
public static RebarBarType Create(Document ADoc);
public static ElementId CreateDefaultRebarBarType(Document ADoc);
public bool GetAutoCalcHookLengths(ElementId hookId);
public double GetHookLength(ElementId hookId);
public double GetHookOffsetLength(ElementId hookId);
public bool GetHookPermission(ElementId hookId);
public double GetHookTangentLength(ElementId hookId);
public RebarRoundingManager GetReinforcementRoundingManager();
public void SetAutoCalcHookLengths(ElementId hookId, bool autoCalculated);
public void SetBarTypeDiameters(BarTypeDiameterOptions diametersOptions);
public void SetHookLength(ElementId hookId, double hookLength);
public void SetHookOffsetLength(ElementId hookId, double newLength);
public void SetHookPermission(ElementId hookId, bool permission);
public void SetHookTangentLength(ElementId hookId, double newLength);
}
}
BeamAndSlabNewParameter
添加共享参数:
DefinitionFile informationFile = AccessOrCreateExternalSharedParameterFile();
DefinitionGroups informationCollections = informationFile.Groups;
DefinitionGroup informationCollection = null;
informationCollection = informationCollections.get_Item("MyParameters");
informationCollections.Create("MyParameters");
informationCollection = informationCollections.get_Item("MyParameters");
Definition information = informationCollection.Definitions.get_Item("Unique ID");
if (null == information) {
ExternalDefinitionCreationOptions ExternalDefinitionCreationOptions = new ExternalDefinitionCreationOptions("Unique ID", Autodesk.Revit.DB.ParameterType.Text);
informationCollection.Definitions.Create(ExternalDefinitionCreationOptions);
information = informationCollection.Definitions.get_Item("Unique ID");
}
CategorySet categories = m_revit.Application.Create.NewCategorySet();
Category structuralFramingCategorie = null;
Category floorsClassification = null;
// use category in instead of the string name to get category
structuralFramingCategorie = m_revit.ActiveUIDocument.Document.Settings.Categories.get_Item(BuiltInCategory.OST_StructuralFraming);
floorsClassification = m_revit.ActiveUIDocument.Document.Settings.Categories.get_Item(BuiltInCategory.OST_Floors);
categories.Insert(structuralFramingCategorie);
categories.Insert(floorsClassification);
InstanceBinding caseTying = m_revit.Application.Create.NewInstanceBinding(categories);
bool boundResult = m_revit.ActiveUIDocument.Document.ParameterBindings.Insert(information, caseTying);
CreateBeamsColumnsBraces
创建支撑 Brace - 关于支撑,参考官方文档。
STRUCTURALTYPE structuralType = Autodesk.Revit.DB.Structure.StructuralType.Brace;
Line line1 = Line.CreateBound(startPoint, middlePoint);
if (!braceType.IsActive)
braceType.Activate();
FamilyInstance firstBrace = m_revit.ActiveUIDocument.Document.Create.NewFamilyInstance(line1, braceType, baseLevel, structuralType);
创建梁 Beam:
Line line = Line.CreateBound(startPoint, endPoint);
STRUCTURALTYPE structuralType = Autodesk.Revit.DB.Structure.StructuralType.Beam;
if (!beamType.IsActive)
beamType.Activate();
m_revit.ActiveUIDocument.Document.Create.NewFamilyInstance(line, beamType, topLevel, structuralType);
CreateComplexAreaRein
ElementId areaReinforcementTypeId = AreaReinforcementType.CreateDefaultAreaReinforcementType(revit.Application.ActiveUIDocument.Document);
ElementId rebarBarTypeId = RebarBarType.CreateDefaultRebarBarType(revit.Application.ActiveUIDocument.Document);
ElementId rebarHookTypeId = RebarHookType.CreateDefaultRebarHookType(revit.Application.ActiveUIDocument.Document);
AreaReinforcement areaRein = AreaReinforcement.Create(revit.Application.ActiveUIDocument.Document, floor, curves, majorDirection, areaReinforcementTypeId, rebarBarTypeId, rebarHookTypeId);
private void ChangeAreaReinCurves(AreaReinforcement areaRein){
//interior 4 curves are listed in the back of the curves,
//this order is decided when we create it
IList<ElementId> curveIds = areaRein.GetBoundaryCurveIds();
for (int i = 4; i < 8; i++) {
AreaReinforcementCurve areaReinCurve = m_doc.GetElement(curveIds[i]) as AreaReinforcementCurve;
//remove hooks, set the hook the top 2 layers to 'up'
ParameterUtil.SetParaInt(areaReinCurve, BuiltInParameter.REBAR_SYSTEM_OVERRIDE, -1);
ParameterUtil.SetParaInt(areaReinCurve, BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_TOP_DIR_1, (int)HookOrientation.Up);
ParameterUtil.SetParaInt(areaReinCurve, BuiltInParameter.REBAR_SYSTEM_HOOK_ORIENT_TOP_DIR_2, (int)HookOrientation.Up);
}
}
CreateDimensions
Autodesk.Revit.UI.UIApplication app = m_revit.Application;
Document doc = app.ActiveUIDocument.Document;
Autodesk.Revit.DB.XYZ p1 = new XYZ(
newLine.GetEndPoint(0).X + 5,
newLine.GetEndPoint(0).Y + 5,
newLine.GetEndPoint(0).Z);
Autodesk.Revit.DB.XYZ p2 = new XYZ(
newLine.GetEndPoint(1).X + 5,
newLine.GetEndPoint(1).Y + 5,
newLine.GetEndPoint(1).Z);
Line newLine2 = Line.CreateBound(p1, p2);
Dimension newDimension = doc.Create.NewDimension( doc.ActiveView, newLine2, referenceArray);
CreateSimpleAreaRein
创建及设置对应参数。
CreateViewSection
namespace Autodesk.Revit.DB
{
public class ViewSection : View
{
public static View CreateCallout(Document document, ElementId parentViewId, ElementId viewFamilyTypeId, XYZ point1, XYZ point2);
public static ViewSection CreateDetail(Document document, ElementId viewFamilyTypeId, BoundingBoxXYZ sectionBox);
public static void CreateReferenceCallout(Document document, ElementId parentViewId, ElementId viewIdToReference, XYZ point1, XYZ point2);
public static void CreateReferenceSection(Document document, ElementId parentViewId, ElementId viewIdToReference, XYZ headPoint, XYZ tailPoint);
public static ViewSection CreateSection(Document document, ElementId viewFamilyTypeId, BoundingBoxXYZ sectionBox);
public static bool IsParentViewValidForCallout(Document document, ElementId parentViewId);
public static bool IsViewFamilyTypeValidForCallout(Document document, ElementId viewFamilyTypeId, ElementId parentViewId);
public bool IsSplitSection();
}
}
CreateWallinBeamProfile
CreateWallsUnderBeams
DeleteDimensions
DeleteObject
简单例子,后续补充,略。
DesignOptionReader
VB,略。
GenerateFloor
创建楼板:
doc.Create.NewFloor(data.Profile, data.FloorType, data.Level, data.Structural);
InPlaceMembers
内建图元 - In-Place Family,参考官方文档。
LevelsProperty
namespace Autodesk.Revit.DB
{
public class Level : DatumPlane
{
public double Elevation { get; set; }
public static Level Create(Document document, double elevation);
public ElementId FindAssociatedPlanViewId();
public Reference GetPlaneReference();
}
}
Loads
载荷,参考官方文档。
MaterialProperties
参考,Revit API: Material 材质
ObjectViewer
PhaseSample
SlabProperties
StructuralLayerFunction
通过参数查询例子,后续补充,略。
RotateFramingObjects
// if be familyInstance,judge the types of familyInstance
if (StructuralType.Beam == familyComponent.StructuralType
|| StructuralType.Brace == familyComponent.StructuralType)
{
// selection is a beam or Brace
ParameterSetIterator paraIterator = familyComponent.Parameters.ForwardIterator();
paraIterator.Reset();
while (paraIterator.MoveNext())
{
object para = paraIterator.Current;
Parameter objectAttribute = para as Parameter;
//set generic property named "Cross-Section Rotation"
if (objectAttribute.Definition.Name.Equals(AngleDefinitionName))
{
Double originDegree = objectAttribute.AsDouble();
double rotateDegree = m_receiveRotationTextBox * Math.PI / 180;
if (!m_isAbsoluteChecked)
{
// absolute rotation
rotateDegree += originDegree;
}
objectAttribute.Set(rotateDegree);
// relative rotation
}
}
}
else if (StructuralType.Column == familyComponent.StructuralType)
{
// rotate a column
Autodesk.Revit.DB.Location columnLocation = familyComponent.Location;
// get the location object
LocationPoint pointLocation = columnLocation as LocationPoint;
Autodesk.Revit.DB.XYZ insertPoint = pointLocation.Point;
// get the location point
double temp = pointLocation.Rotation;
//existing rotation
Autodesk.Revit.DB.XYZ directionPoint = new Autodesk.Revit.DB.XYZ(0, 0, 1);
// define the vector of axis
Line rotateAxis = Line.CreateUnbound(insertPoint, directionPoint);
double rotateDegree = m_receiveRotationTextBox * Math.PI / 180;
// rotate column by rotate method
if (m_isAbsoluteChecked)
{
rotateDegree -= temp;
}
bool rotateResult = pointLocation.Rotate(rotateAxis, rotateDegree);
if (rotateResult == false)
{
TaskDialog.Show("Revit", "Rotate Failed.");
}
}
VersionChecking
Application revitApplication = revit.Application.Application;
// get product name, version number and build number information
// via corresponding Properties of Autodesk.Revit.ApplicationServices.Application class
m_productName = revitApplication.VersionName;
m_version = revitApplication.VersionNumber;
m_buildNumber = revitApplication.VersionBuild;
BoundaryConditions
边界条件,参考官方文档介绍
// invoke Document.NewPointBoundaryConditions Method
Autodesk.Revit.DB.Structure.BoundaryConditions createdBC =
createDoc.NewPointBoundaryConditions(endReference, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
// invoke Document.NewLineBoundaryConditions Method
Autodesk.Revit.DB.Structure.BoundaryConditions createdBC =
createDoc.NewLineBoundaryConditions(hostElement.GetAnalyticalModel(), 0, 0, 0, 0, 0, 0, 0, 0);
// invoke Document.NewAreaBoundaryConditions Method
Autodesk.Revit.DB.Structure.BoundaryConditions createdBC =
createDoc.NewAreaBoundaryConditions(hostElement.GetAnalyticalModel(), 0, 0, 0, 0, 0, 0);
CreateBeamSystem
有关梁系统,参考官方文档。
public void CreateBeamSystem() {
Document document = m_data.CommandData.Application.ActiveUIDocument.Document;
// create curve array and insert Lines in order
IList<Curve> curves = new List<Curve>();
foreach (Line line in m_data.Lines) {
curves.Add(line);
}
// create beam system takes closed profile consist of lines
BeamSystem aBeamSystem = BeamSystem.Create(document, curves, document.ActiveView.SketchPlane, 0);
// set created beam system's layout rule and beam type property
aBeamSystem.LayoutRule = m_data.Param.Layout;
aBeamSystem.BeamType = m_data.Param.BeamType;
}
FoundationSlab
创建基础底板,参考官方文档。
FoundationSlab 是一种楼板,只是类型有区别。
Floor foundationSlab = m_revit.ActiveUIDocument.Document.Create.NewFoundationSlab(
slab.OctagonalProfile, m_foundationSlabType, m_levelList.Values[0],
true, normal);
判断楼板是否是基础底板:
public void GetInfo_FloorType(FloorType floorType)
{
string message;
// Get whether FloorType is a foundation slab
message = "If is foundation slab : " + floorType.IsFoundationSlab;
TaskDialog.Show("Revit",message);
}
FrameBuilder
创建由柱梁等组成的框架系统。
public void CreateFraming()
{
Transaction t = new Transaction(m_data.CommandData.Application.ActiveUIDocument.Document, Guid.NewGuid().GetHashCode().ToString());
t.Start();
m_data.UpdateLevels();
List<FamilyInstance> frameElems = new List<FamilyInstance>();
Autodesk.Revit.DB.UV[,] matrixUV = CreateMatrix(m_data.XNumber, m_data.YNumber, m_data.Distance);
// iterate levels from lower one to higher one by one according to FloorNumber
for (int ii = 0; ii < m_data.FloorNumber; ii++)
{
Level baseLevel = m_data.Levels.Values[ii];
Level topLevel = m_data.Levels.Values[ii + 1];
int matrixXSize = matrixUV.GetLength(0); //length of matrix's x range
int matrixYSize = matrixUV.GetLength(1); //length of matrix's y range
// insert columns in an array format according to the calculated matrix
foreach (Autodesk.Revit.DB.UV point2D in matrixUV)
{
frameElems.Add(NewColumn(point2D, baseLevel, topLevel));
}
// insert beams between the tops of each adjacent column in the X and Y direction
for (int j = 0; j < matrixYSize; j++)
{
for (int i = 0; i < matrixXSize; i++)
{
//create beams in x direction
if (i != (matrixXSize - 1))
{
frameElems.Add(NewBeam(matrixUV[i, j], matrixUV[i + 1, j], topLevel));
}
//create beams in y direction
if (j != (matrixYSize - 1))
{
frameElems.Add(NewBeam(matrixUV[i, j], matrixUV[i, j + 1], topLevel));
}
}
}
// insert braces between the mid point of each column
// and the mid point of each adjoining beam
for (int j = 0; j < matrixYSize; j++)
{
for (int i = 0; i < matrixXSize; i++)
{
//create braces in x direction
if (i != (matrixXSize - 1))
{
frameElems.AddRange(
NewBraces(matrixUV[i, j], matrixUV[i + 1, j], baseLevel, topLevel));
}
//create braces in y direction
if (j != (matrixYSize - 1))
{
frameElems.AddRange(
NewBraces(matrixUV[i, j], matrixUV[i, j + 1], baseLevel, topLevel));
}
}
}
}
MoveRotateFrame(frameElems);
t.Commit();
}
Journaling
日志,记录和回放插件运行情况。
void WriteJournalData(ExternalCommandData commandData)
{
// Get the StringStringMap class which can write data into.
IDictionary<String, String> dataMap = commandData.JournalData;
dataMap.Clear();
// Begin to add the support data
dataMap.Add("Name", "Autodesk.Revit");
dataMap.Add("Information", "This is an example.");
dataMap.Add("Greeting", "Hello Everyone.");
}
///
/// This sample shows how to get data from journal file.
///
void ReadJournalData(ExternalCommandData commandData)
{
// Get the StringStringMap class which can write data into.
IDictionary<String, String> dataMap = commandData.JournalData;
// Begin to get the support data.
String prompt = "Name: " + dataMap["Name"];
prompt += "\nInformation: " + dataMap["Information"];
prompt += "\nGreeting: " + dataMap["Greeting"];
TaskDialog.Show("Revit",prompt);
}
Openings
获取洞口的信息。
ReferencePlane
参照平面。
Reinforcement
钢筋,参考官方文档。
Rooms
获取房间的信息。
SharedCoordinateSystem
namespace Autodesk.Revit.DB
{
public class SiteLocation : ElementType
{
public string GeoCoordinateSystemDefinition { get; }
public string GeoCoordinateSystemId { get; }
public double Elevation { get; }
public string WeatherStationName { get; }
public string PlaceName { get; set; }
public double TimeZone { get; set; }
public double Longitude { get; set; }
public double Latitude { get; set; }
public DateTime ConvertFromProjectTime(DateTime projectTime);
public DateTime ConvertToProjectTime(DateTime inputTime);
public bool IsCompatibleWith(SiteLocation otherSiteLocation);
public void SetGeoCoordinateSystem(string coordSystem);
}
}