HelloRevitApp
元素(圖元)
元素的幾個重要的屬性包括: 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 ( ) ;
else if ( analyticalModel
. IsSinglePoint ( ) )
XYZp
= analyticalModel
. GetPoint ( ) ;
else
IList< Curve> curves
= analyticalModel
. GetCurves ( AnalyticalCurveType
. ActiveCurves
) ;
獲取圖元
編輯
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 ( ) ; Autodesk. Revit. Creation. Document creater
= projectDoc
. Create
; 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調用會 失敗。 開發人員可以對參照某個模型組中模型圖元的那些尺寸和標記進行分組。這些尺寸和 標記被添加到-一個附屬詳圖組。你無法單獨移動、復制、旋轉、陣列或鏡像附屬詳圖組, 而不對其參照模型組執行相同操作。
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) 從傳 人的元素集中創建一個基于旋轉軸的圓弧型陣列
string doorTypeName
= "0762 x 2032 mm" ;
FamilySymbol doorType
= null ;
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
+ "'" ) ;
}
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 ( ) ;
}
Wall wall
= RevitDoc
. GetElement ( new ElementId ( 185521 ) ) as Wall ;
WallType wallType
= wall
. WallType
;
ElementType duplicatedWallType
= wallType
. Duplicate ( wallType
. Name
+ " (duplicated)" ) ;
Document projectDoc
= ActiveUIDocument
. Document
; using ( Transaction moveColumnTran
= new Transaction ( projectDoc
, "Move a new column to the new place" ) )
{ moveColumnTran
. Start ( ) ; Autodesk. Revit. Creation. Document creater
= projectDoc
. Create
; 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 ( ) ;
}
Wall wall
= element
as Wall ;
if ( null != wall
)
{ LocationCurve wallLine
= wall
. Location
as LocationCurve ; XYZ newPlace
= new XYZ ( 10 , 20 , 0 ) ; wallLine
. Move ( newPlace
) ;
}
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 ( ) ;
}
FamilyInstance column
= element
as FamilyInstance ;
if ( null != column
)
{ LocationPoint columnPoint
= column
. Location
as LocationPoint ; XYZ newLocation
= new XYZ ( 10 , 20 , 0 ) ; columnPoint
. Point
= newLocation
;
}
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 ( ) ;
}
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 ( ) ;
}
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 ( ) ;
}
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 ( ) ;
}
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 ( ) ; }
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 ( ) ;
} group . GroupType
. Name
= "MyGroup" ; 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 ( ) ; } }
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 ; }
} ; 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 ( ) ) ;
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 ( ) ; }
}
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 ( ) ; }
}
public void CreateModelCurve ( )
{ Document doc
= this . ActiveUIDocument
. Document
; 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 ( ) ; }
}
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 ( ) ; }
}
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
;
}
總結
以上是生活随笔 為你收集整理的Revit二次开发——图元(元素)编辑 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。