Revit二次开发——图元(元素)编辑

元素(图元)

元素的几个重要的属性包括: Category(类别),Location(位 置),Levelld(标 高),Groupld(组),Id, UniqueId(唯一 Id)等等。
重要的方法:GetMaterials,GetAnalyticalModel。

Category、Family、FamilySymbol、FamilyInstance这四个概念之间的关系
类别(Category)>族(Family)>族模型(FamilySymbol),这三者是子集关系,而你在视图中实际绘制的墙就叫做族实例(FamilyInstance)

图元属性

1、元素的位置Location
Element. Location属性用来获取元素的位置,Location可以转型为LocationPoint 和LocationCurve,如果该元素的位置是点,则转型为LocationPoint,如果是直线或者曲线,则使用LocationCurve。

2、获取元素的材质
GetMaterials( bool)函数可以获取元素的材质,bool为true的时候,获取的是元素的油漆材质(Painted Material)

3)获取元素的分析模型
分析模型主要被用来做结构分析,获取分析模型可以使用Element. GetAnalyticalModel( )方法,然后调用分析模型的GetCurve, GetCurves 或GetPoint来获取分析模型的几何信息,此外,可通过IsSingleCurve( )和IsSinglePoint( )方法来辅助判断需要调用哪个方法。

Element element = RevitDoc .GetElement(new ElementId(183554));
if (element = = null) return;
AnalyticalModel analyticalModel = element . GetAnalyticalModel( );
if(analyticalModel .IsSingleCurve( ))
Curve curve = analyticalModel . GetCurve( );
// work with curve
else if(analyticalModel.IsSinglePoint( ))
XYZp= analyticalModel .GetPoint( );
// work with point
else
IList< Curve> curves = analyticalModel.GetCurves(AnalyticalCurveType .ActiveCurves);
// work with curves

获取图元

编辑

Autodesk. Revit. DB. ElementTransformUtils的移动,旋转和镜像;
文档类Document的删除;
创建方法Autodesk. Revit. Creation. ItemFactoryBase里的创建组合;
阵列类型的创建;
族编辑的一-些基本类和方法。

移动

API提供了移动元素的方法,可以把-一个或者几个元素从一个地方移动到另一个地方,从精确程度来说,和UI的移动命令是一样的。

方法描述
MoveElement(Document, Elementld, XYZ)使用给定的平移变换移动一个元素
MoveElements( Document, lCollction< Elementld>,XYZ)使用给定的平移变换移动元素集

MoveElement和MoveElements是常用的移动方式,使用起来比较简单,但是有几个需要注意的地方:
①移动方法不能远离标高向上或者向下移动一个基于标高的元素。也就是说,当元素是基于标高的,则不能改变Z轴坐标值,但可以移动元素到同–标高内的任意位置。例如,如果在坐标点(0,0, 0)新创建了一个柱子,然后移动它到新的坐标点(10, 20, 30),这个柱子将会移动到(10, 20, 0),而不是(10, 20, 30)。

②当移动一个元素的时候.其他的元素也许会跟着移动。例如,如果一堵墙 上有窗户,这堵墙移动了,窗户也会跟着移动。移动元素集的方法也会出现这种情况。例如,当移动几根柱子的时候,所有与柱子连接着的梁也会跟着被移动或者会被改变长度。

③如果元素被钉住,即Pinned属性返回值是true, 则表明这个元素不能被移动。如果仍然使用MoveElement方法来移动这个元素,API就会抛出Invalid )perationException来提示用户不能移动被钉住的元素。

另外,还可以通过Location 类来移动一个元素。Location 类提供了移动和旋转的方法,而且其子类提供了更多的Location 信息和属性控制,如LocationPoint 类和LocationCurve类。如果一个元素的Location 可以转型为LocationCurve 或者LocationPoint,就可以直接移动这根线或者点到新的坐标点了。

            Document projectDoc = ActiveUIDocument.Document;
            using (Transaction moveColumnTran = new Transaction(projectDoc, "Move a new column to the new place" ))
            {
                moveColumnTran.Start( );
                //获取Revit文档的创建句柄
                Autodesk.Revit.Creation.Document creater = projectDoc.Create;
                //创建一根柱子:使用给定的位置(坐标原点),柱子类型和标高(高度为0) 
                XYZ origin = new XYZ(0, 0, 0);
                Level level = GetALevel(projectDoc);
                FamilySymbol columnType = GetAColumnType(projectDoc);
                FamilyInstance column = creater.NewF amilyInstance(origin, columnType, level,
                Autodesk.Revit.DB.Structure.StructuralType.Column);
                // 把柱子移动到新的位置
                XYZ newPlace = new XYZ(10, 20, 30);
                ElementTransformUtils.MoveElement(projectDoc, column.Id, newPlace);
                moveColumnTran.Commit();
             }
Wall wall = element as Wall;
if (null ! = wall)
{
	LocationCurve wallLine = wall. Location as LocationCurve;
	XYZ newPlace= new XYZ(10, 20, 0); 
	wallLine .Move(newPlace);
}

如果使用上面这种方法移动一个元素,那么请注意向量(10, 20, 0)并不是目标坐标值, 而是一个偏移向量。
另外,LocationCurve的Curve属性或者LocationPoint的Point属性也可以用来移动一个元素。.

旋转

方法描述
RotateElement(Document, Elermentld, Line, double)使用给定的轴线和角度对- -个元素进行旋转
RotateElements(Document, lCollction< Elementld>. Line, double)使用给定的轴线和角度对元索集进行旋转

在旋转方法中,旋转角度是用弧度计量。正值是通过轴线做逆时针的旋转,对应的负值就是做顺时针旋转

①当旋转–个元素时,旋转轴应该是有限线段,如果是无限线作为旋转轴线,会导致旋转失败。
②旋转轴–般要求与元素LocationCurve所在的平面垂直,否则很可能会导致旋转失败。

镜像

方法描述
MirrorElement(Document, Elementld, Plane)使用给定的平面创建–个元素的镜像拷贝
MirrorElements ( Document document, lCollection < Elementld>elementsToMirror, Plane plane)使用给定的平面创建一-个元索集合的镜像拷贝
CanMirrorFElement(Document. Elementld)判断元素是否可以进行镜像操作
CanMirrorElements( Document, lCollection< Elementld> )判断元素集是否可以进行镜像操作

复制

ElementTransformUtils类提供了几个静态方法,从某处复制一个或多个图元到别处,,可以复制到同一文件或视图内,也可以复制到其他文件或视图内。

方法描述
CopyElement (Document, Elementld, XYZ)复制图元并将其置于给定转换所指定的位置
CopyElements ( Document, ICollection<Elementld>, XYZ)复制–组图元并将其置于给定转换所指定的位置
CopyElements( Document, ICollction< Elementld>, Document,Transform, CopyPasteOptions )从源文件复制一组图元到目标文件
CopyElements (View, ICollection<Elementld>, View,Transform, CopyPasteOptions)从源视图复制一-组图元到目标视图

删除

方法描述
Delete( Elementld)从文档中将传入Id的元素删除
Delete( IOletion< ElementId> )从文档中将传入ld集合的元素集删除

组合

在命名空间Autodesk. Revit. Creation 中,类ItemFactoryBase 提供了NewGroup(ICollection< ElementId> )方法来选择一个或者多个元素进行组合,甚至可以选择组合进行再组合,这样做可以使这些元素能在一个大的组合里面统一被修改。

            Document projectDoc = ActiveUIDocument.Document;
            List<ElementId> elementsToGroup = new List<ElementId>();
            using (Transaction tran = new Transaction(projectDoc,” Group the selected elements.' ))
            {
				tran.Start( );
                foreach (Element elem in ActiveUIDocument.Selection.Elements){
                    elementsToGroup.Add(elem.Id);
                 }
                 Group group = projectDoc.Create.NewGroup(elementsToGroup);
            	tran.Commit();
            }

Revit有三种类型的组:模型组、详图组和附属详图组。所有这些组都使用NewGroup()
方法来创建。所创建组的类型取决于组内图元的类型。
●若无任何详图图元,则创建的是个模型组。
如果所有的图元都是详图图元,那么创建的是个详图组。
●如果这两种类型的图元都包括在内,则创建一一个包含附属详图组的模型组并返回。
注意:图元成组后,可将图元从项目中删除。
●①当元素被组合起来了,它们仍然可以被从文档中删除。在组合里面的元素被删除
时,这个元素在界面上仍然是可见的,但是这个元素实际上被删除了,是不能再次被选中或
者被访问的。当组合中最后一个元素被删除或者是从组合里面移除了,这个组合的实体随
后也将被删除。

●当项目中一组实例的最后-一个成员被删除、剔除或移除时,模型组实例也就被删
除了。
图元成组后,就不能移动或旋转。如果在已成组的图元上执行这些操作,尽管Move()
或Rotate( )方法返回true,但实际上图元没有发生任何变化。
如果参,照的图元没有成组,则无法将其尺寸和标记成组。如果这样做则API调用会
失败。
开发人员可以对参照某个模型组中模型图元的那些尺寸和标记进行分组。这些尺寸和
标记被添加到-一个附属详图组。你无法单独移动、复制、旋转、阵列或镜像附属详图组,
而不对其参照模型组执行相同操作。

//把默认的组合名字改成新的名字:“MyGroup”
group.GroupType.Name="MyGroup";

阵列

Revit API提供的阵列方法可以对一个或者多个元素创建线型的或者是径向(圆弧型)的阵列。例如,可以选择墙上的一.扇门或者一扇窗,阵列出多个门或窗的实体

Revit平台API提供了两个类,即LinearArray和RadialArray来阵列项目中的一个或多个图元。这些类提供静态方法来创建一个或多个选定构件的线性或径向阵列。线性阵列表示从一个点顺着一条线创建的阵列, 而径向阵列表示沿弧线创建的阵列。
可以选择同一面墙上的一扇门和一扇窗, 然后通过阵列创建门、墙、窗结构布局的多个实例。LinearArray和RadialArray还提供了一些方法, 来阵列未被分组和关联的一个或多个图元1。虽然类似于阵列图元的Create( )方法,但每个目标图元都独立于其他图元,可对其操作而不影响其他图元。

方法描述
LinearArray. Create ( Document,View, Elementld, int, XYZ,ArrayAnchorMember),从传人的元素中创建一个线型阵列
LinearArray. Create ( Document, View, ICollection < Elementld >,int. XYZ, ArrayAnchorMember)从传入的元素集中创建一个线型阵列
RadialArray. Create ( Document,View, Elementld, int, Line,double, ArrayAnchorMember)从传人的元素中创建一个 基于旋转轴的圆弧型阵列
RadialArray. Create ( Document, View, lollction < Elementld>,int, Line, double, Array AnchorMember)从传 人的元素集中创建一个基于旋转轴的圆弧型阵列

//============代码片段3-12 放置类型为"0762 x 2032 mm"的门============
string doorTypeName = "0762 x 2032 mm";
FamilySymbol doorType = null;

// 在文档中找到名字为"0762 x 2032 mm"的门类型
ElementFilter doorCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors);
ElementFilter familySymbolFilter = new ElementClassFilter(typeof(FamilySymbol));
LogicalAndFilter andFilter = new LogicalAndFilter(doorCategoryFilter, familySymbolFilter);
FilteredElementCollector doorSymbols = new FilteredElementCollector(RevitDoc);
doorSymbols = doorSymbols.WherePasses(andFilter);
bool symbolFound = false;
foreach (FamilySymbol element in doorSymbols)
{
   if (element.Name == doorTypeName)
   {
      symbolFound = true;
      doorType = element;
      break;
   }
}

// 如果没有找到,就加载一个族文件
if (!symbolFound)
{
   string file = @"C:\ProgramData\Autodesk\RVT 2014\Libraries\Chinese_INTL\门\M_单-嵌板 4.rfa";
   Family family;
   bool loadSuccess = RevitDoc.LoadFamily(file, out family);
   if (loadSuccess)
   {
      foreach (ElementId doorTypeId in family.GetValidTypes())
      {
         doorType = RevitDoc.GetElement(doorTypeId) as FamilySymbol;
         if (doorType != null)
         {
            if (doorType.Name == doorTypeName)
            {
               break;
            }
         }
      }
   }
   else
   {
      Autodesk.Revit.UI.TaskDialog.Show("Load family failed", "Could not load family file '" + file + "'");
   }
}

// 使用族类型创建门
if (doorType != null)
{
   // 首先找到线形的墙
   ElementFilter wallFilter = new ElementClassFilter(typeof(Wall));
   FilteredElementCollector filteredElements = new FilteredElementCollector(RevitDoc);
   filteredElements = filteredElements.WherePasses(wallFilter);
   Wall wall = null;
   Line line = null;
   foreach (Wall element in filteredElements)
   {
      LocationCurve locationCurve = element.Location as LocationCurve;
      if (locationCurve != null)
      {
         line = locationCurve.Curve as Line;
         if (line != null)
         {
            wall = element;
            break;
         }
      }
   }

   // 在墙的中心位置创建一个门
   if (wall != null)
   {
      XYZ midPoint = (line.get_EndPoint(0) + line.get_EndPoint(1)) / 2;
      Level wallLevel = RevitDoc.GetElement(wall.LevelId) as Level;
      //创建门:传入标高参数,作为门的默认标高
      FamilyInstance door = RevitDoc.Create.NewFamilyInstance(midPoint, doorType, wall, wallLevel, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
      Autodesk.Revit.UI.TaskDialog.Show("Succeed", door.Id.ToString());
      Trace.WriteLine("Door created: " + door.Id.ToString());
   }
   else
   {
      Autodesk.Revit.UI.TaskDialog.Show("元素不存在", "没有找到符合条件的墙");
   }
}
else
{
   Autodesk.Revit.UI.TaskDialog.Show("族类型不存在", "没有找到族类型'" + doorTypeName + "'");
}

//============代码片段3-13 创建拉伸实体族============
//创建族文档
Document familyDoc = RevitApp.NewFamilyDocument(@"C:\ProgramData\Autodesk\RVT 2014\Family Templates\Chinese\公制常规模型.rft");
using (Transaction transaction = new Transaction(familyDoc))
{
   transaction.Start("Create family");
   CurveArray curveArray = new CurveArray();
   curveArray.Append(Line.CreateBound(new XYZ(0, 0, 0), new XYZ(5, 0, 0)));
   curveArray.Append(Line.CreateBound(new XYZ(5, 0, 0), new XYZ(5, 5, 0)));
   curveArray.Append(Line.CreateBound(new XYZ(5, 5, 0), new XYZ(0, 5, 0)));
   curveArray.Append(Line.CreateBound(new XYZ(0, 5, 0), new XYZ(0, 0, 0)));
   CurveArrArray curveArrArray = new CurveArrArray();
   curveArrArray.Append(curveArray);
   //创建一个拉伸实体
   familyDoc.FamilyCreate.NewExtrusion(true, curveArrArray, SketchPlane.Create(familyDoc, RevitApp.Create.NewPlane(new XYZ(0, 0, 1), XYZ.Zero)), 10);
   //创建一个族类型
   familyDoc.FamilyManager.NewType("MyNewType");
   transaction.Commit();
   familyDoc.SaveAs("MyNewFamily.rfa");
   familyDoc.Close();
}

//============代码片段3-14 复制墙类型============
Wall wall = RevitDoc.GetElement(new ElementId(185521)) as Wall;
WallType wallType = wall.WallType;
ElementType duplicatedWallType = wallType.Duplicate(wallType.Name + " (duplicated)");

//============代码片段3-15:元素编辑============
Document projectDoc = ActiveUIDocument.Document;
           
using(Transaction moveColumnTran = new Transaction(projectDoc, "Move a new column to the new place"))
{
 moveColumnTran.Start();
               
 // 获取Revit文档的创建句柄
 Autodesk.Revit.Creation.Document creater = projectDoc.Create;
 // 创建一根柱子:使用给定的位置(坐标原点),柱子类型和标高(高度为0)
 XYZ origin = new XYZ(0, 0, 0);
 Level level = GetALevel(projectDoc);
 FamilySymbol columnType = GetAColumnType(projectDoc);
 FamilyInstance column = creater.NewFamilyInstance(origin, columnType, level, Autodesk.Revit.DB.Structure.StructuralType.Column);
 // 把柱子移动到新的位置
 XYZ newPlace = new XYZ(10, 20, 30);
 ElementTransformUtils.MoveElement(projectDoc, column.Id, newPlace);
           
 moveColumnTran.Commit();       
}

//============代码片段3-16:元素编辑============
Wall wall = element as Wall;
if (null != wall)
{
    LocationCurve wallLine = wall.Location as LocationCurve;
    XYZ newPlace = new XYZ(10, 20, 0);
    wallLine.Move(newPlace);
}

//============代码片段3-17:元素编辑============
using(Transaction tran = new Transaction(projectDoc, "Change the wall's curve with a new location line."))
{
 tran.Start();
               
 LocationCurve wallLine = wall.Location as LocationCurve;
 XYZ p1 = XYZ.Zero;
 XYZ p2 = new XYZ(10, 20, 0);
 Line newWallLine = Line.CreateBound(p1, p2);
 // 把墙的位置线换成新的线
 wallLine.Curve = newWallLine;
            
 tran.Commit();
}

//============代码片段3-18:元素编辑============
FamilyInstance column = element as FamilyInstance;
if (null != column)
{
    LocationPoint columnPoint = column.Location as LocationPoint;
    XYZ newLocation = new XYZ(10, 20, 0);
    // 移动柱子到新的位置(10,20,0)
    columnPoint.Point = newLocation;
}

//============代码片段3-19:元素编辑============
using(Transaction tran = new Transaction(projectDoc, "Rotate the wall."))
{
  tran.Start();
  LocationCurve wallLine = wall.Location as LocationCurve;
  XYZ p1 = wallLine.Curve.GetEndPoint(0);
  XYZ p2 = new XYZ(p1.X, p1.Y, 30);
  Line axis = Line.CreateBound(p1, p2);
  ElementTransformUtils.RotateElement(projectDoc, wall.Id, axis, Math.PI / 3.0);
  tran.Commit();
}

//============代码片段3-20:元素编辑============
Document projectDoc = ActiveUIDocument.Document;
            
using(Transaction tran = new Transaction(projectDoc, "Rotate the wall and the column."))
{
   tran.Start();
                
   Wall wall = projectDoc.GetElement(new ElementId(184163)) as Wall;
                
   XYZ aa = XYZ.Zero;
   XYZ cc = XYZ.Zero;
   // 通过元素的位置线来旋转元素
   LocationCurve curve = wall.Location as LocationCurve;
   if (null != curve)
   {
       Curve line = curve.Curve;
       aa = line.GetEndPoint(0);
       cc = new XYZ(aa.X, aa.Y, aa.Z + 10);
       Line axis = Line.CreateBound(aa, cc);
       curve.Rotate(axis, Math.PI / 2.0);
   }
                
   FamilyInstance column = projectDoc.GetElement(new ElementId(184150)) as FamilyInstance;
                
   // 通过元素的位置点来旋转元素
   LocationPoint point = column.Location as LocationPoint;
   if (null != point)
   {
        aa = point.Point;
        cc = new XYZ(aa.X, aa.Y, aa.Z + 10);
        Line axis = Line.CreateBound(aa, cc);
        point.Rotate(axis, Math.PI / 3.0);
   }
   tran.Commit();
}

//============代码片段3-21:元素编辑============
using(Transaction tran = new Transaction(projectDoc, "Mirror the column."))
{
  tran.Start();
                
  FamilyInstance column = projectDoc.GetElement(new ElementId(184150)) as FamilyInstance;
  if (null != column)
  {
     Plane plane = new Plane(XYZ.BasisX, XYZ.Zero);
     if(ElementTransformUtils.CanMirrorElement(projectDoc, column.Id))
     {
        ElementTransformUtils.MirrorElement(projectDoc, column.Id, plane);
     }
  }
  tran.Commit();
}

//============代码片段3-22:元素编辑============
Document projectDoc = ActiveUIDocument.Document;
Wall wall = projectDoc.GetElement(new ElementId(184163)) as Wall;
using(Transaction tran = new Transaction(projectDoc, "Delete the wall."))
{
    tran.Start();
    // 删除选择的元素:墙
    ICollection<ElementId> deletedElements = projectDoc.Delete(wall.Id);
    tran.Commit();
}

//============代码片段3-23:元素编辑============
Document projectDoc = ActiveUIDocument.Document;

List<ElementId> elementsToDelete = new List<ElementId>();            
 using(Transaction tran = new Transaction(projectDoc, "Delete the selected elements."))
 {
     tran.Start();
     foreach (Element elem in ActiveUIDocument.Selection.Elements)
     {
         elementsToDelete.Add(elem.Id);
     }

      ICollection<ElementId> deletedElements = projectDoc.Delete(elementsToDelete);
      tran.Commit();
 }

//============代码片段3-24:元素编辑============
Document projectDoc = ActiveUIDocument.Document;
List<ElementId> elementsToGroup = new List<ElementId>();
using(Transaction tran = new Transaction(projectDoc, "Group the selected elements."))
{
tran.Start();
foreach (Element elem in ActiveUIDocument.Selection.Elements)
{
   elementsToGroup.Add(elem.Id);
}

Group group = projectDoc.Create.NewGroup(elementsToGroup);
tran.Commit();
}

//============代码片段3-25:元素编辑============
         // 把默认的组合名字改成新的名字:“MyGroup”
  group.GroupType.Name = "MyGroup";

//============代码片段3-26:元素编辑============
 public void ArraryElements()
 {
    Document projectDoc = ActiveUIDocument.Document;
    Wall wall = projectDoc.GetElement(new ElementId(2307)) as Wall;
    using(Transaction tran = new Transaction(projectDoc, "LinearArray the wall."))
    {
       tran.Start();
       XYZ translation = new XYZ(0,10,0);
       LinearArray.Create(projectDoc, projectDoc.ActiveView, wall.Id, 3, translation, ArrayAnchorMember.Second);
       tran.Commit();
     }
 }

//============代码片段3-27:元素编辑============
class projectFamLoadOption : IFamilyLoadOptions
{
    bool IFamilyLoadOptions.OnFamilyFound(bool familyInUse, out bool overwriteParameterValues)
    {
        overwriteParameterValues = true;
        return true;
    }
    bool IFamilyLoadOptions.OnSharedFamilyFound(Family sharedFamily, bool familyInUse, out FamilySource source, out bool overwriteParameterValues)
    {
        source = FamilySource.Project;
        overwriteParameterValues = true;
        return true;
    }
};

//============代码片段3-28:元素编辑============
       Document projectDoc = ActiveUIDocument.Document;
// 这里是自定义族实例,比如门,窗,桌子…
         FamilyInstance famInst = elem as FamilyInstance;
// 编辑族,拿到族文档
Document familyDoc = projectDoc.EditFamily(famInst.Symbol.Family);
// 在族文档中添加一个新的参数
using(Transaction tran = new Transaction(projectDoc, "Edit family Document."))
{
  tran.Start();
  string paramName = "MyParam ";
  familyDoc.FamilyManager.AddParameter(paramName, BuiltInParameterGroup.PG_TEXT, ParameterType.Text, false);
  tran.Commit();
}
// 将这些修改重新载入到工程文档中
Family loadedFamily = familyDoc.LoadFamily(RevitDoc, new projectFamLoadOption());

//============代码片段3-29:元素编辑============
public void CreatReferencePlane()
{
   Document doc = this.ActiveUIDocument.Document;    
   if(!doc.IsFamilyDocument)
      return;
            
   using(Transaction transaction = new Transaction(doc, "Editing Family"))
   {
      transaction.Start();
      XYZ bubbleEnd = new XYZ(0,5,5);
      XYZ freeEnd = new XYZ(5, 5, 5);
      XYZ cutVector = XYZ.BasisY;
      View view = doc.ActiveView;
      ReferencePlane referencePlane = doc.FamilyCreate.NewReferencePlane(bubbleEnd, freeEnd, cutVector, view);
      referencePlane.Name = "MyReferencePlane";
      transaction.Commit();                
   }
}

//============代码片段3-30:元素编辑============
public void ChangeModelCurveToReferenceLine()
{            
    Document doc = this.ActiveUIDocument.Document;    
    ModelCurve modelCurve = doc.GetElement(new ElementId(2910)) as ModelCurve;
    using(Transaction transaction = new Transaction(doc, "Change model curve to reference line."))
    {
        transaction.Start();
        modelCurve.ChangeToReferenceLine();
        transaction.Commit();                
    }            
}

//============代码片段3-31:元素编辑============
public void CreateModelCurve()
{
   Document doc = this.ActiveUIDocument.Document;    
   // 在族文档中找到名字为"Ref. Level"的标高
   FilteredElementCollector collector = new FilteredElementCollector(doc);
   collector = collector.OfCategory(BuiltInCategory.OST_Levels);
   var levelElements = from element in collector where element.Name == "Ref. Level" select element;  
   List<Autodesk.Revit.DB.Element> levels = levelElements.ToList<Autodesk.Revit.DB.Element>();        
   if(levels.Count <= 0)
      return;            
   Level refLevel = levels[0] as Level;
            
   // 创建一条几何直线,一个基于标高的草图平面,然后在这个草图平面上创建一条模型线.
   using(Transaction trans = new Transaction(doc, "Create model line."))
   {
      trans.Start();    
      Line line = Line.CreateBound(XYZ.Zero, new XYZ(10,10,0));
      SketchPlane sketchPlane = SketchPlane.Create(doc, refLevel.Id);        
      ModelCurve modelLine = doc.FamilyCreate.NewModelCurve(line, sketchPlane);
     trans.Commit();
   }
}

//============代码片段3-32:元素编辑============
public void CreateSketchPlaneByPlane()
{
   Document doc = this.ActiveUIDocument.Document;    
   using(Transaction trans = new Transaction(doc, "Create model arc."))
   {
     trans.Start();    
     Plane plane = this.Application.Create.NewPlane(XYZ.BasisZ, XYZ.Zero);
     SketchPlane sketchPlane = SketchPlane.Create(doc, plane);
            
     Arc arc = Arc.Create(plane, 5, 0, Math.PI * 2);
     ModelCurve modelCircle = doc.FamilyCreate.NewModelCurve(arc, sketchPlane);
     trans.Commit();
   }
}

//============代码片段3-33:元素编辑============
public void GetSketchFromExtrusion()
{
    Document doc = this.ActiveUIDocument.Document;
    Extrusion extrusion = doc.GetElement(new ElementId(3388)) as Extrusion;
    SketchPlane sketchPlane = extrusion.Sketch.SketchPlane;
    CurveArrArray sketchProfile = extrusion.Sketch.Profile;
}

  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孤影墨客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值