HelloRevitApp 元素(圖元) 編輯 移動(dòng) 旋轉(zhuǎn) 鏡像 復(fù)制 刪除 組合 陣列
元素(圖元)
元素的幾個(gè)重要的屬性包括: Category(類(lèi)別),Location(位 置),Levelld(標(biāo) 高),Groupld(組),Id, UniqueId(唯一 Id)等等。 重要的方法:GetMaterials,GetAnalyticalModel。
Category、Family、FamilySymbol、FamilyInstance這四個(gè)概念之間的關(guān)系 類(lèi)別(Category)>族(Family)>族模型(FamilySymbol),這三者是子集關(guān)系,而你在視圖中實(shí)際繪制的墻就叫做族實(shí)例(FamilyInstance)
圖元屬性
1、元素的位置Location Element. Location屬性用來(lái)獲取元素的位置,Location可以轉(zhuǎn)型為L(zhǎng)ocationPoint 和LocationCurve,如果該元素的位置是點(diǎn),則轉(zhuǎn)型為L(zhǎng)ocationPoint,如果是直線(xiàn)或者曲線(xiàn),則使用LocationCurve。 △
2、獲取元素的材質(zhì) GetMaterials( bool)函數(shù)可以獲取元素的材質(zhì),bool為true的時(shí)候,獲取的是元素的油漆材質(zhì)(Painted Material)
3)獲取元素的分析模型 分析模型主要被用來(lái)做結(jié)構(gòu)分析,獲取分析模型可以使用Element. GetAnalyticalModel( )方法,然后調(diào)用分析模型的GetCurve, GetCurves 或GetPoint來(lái)獲取分析模型的幾何信息,此外,可通過(guò)IsSingleCurve( )和IsSinglePoint( )方法來(lái)輔助判斷需要調(diào)用哪個(gè)方法。
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的移動(dòng),旋轉(zhuǎn)和鏡像; 文檔類(lèi)Document的刪除; 創(chuàng)建方法Autodesk. Revit. Creation. ItemFactoryBase里的創(chuàng)建組合; 陣列類(lèi)型的創(chuàng)建; 族編輯的一-些基本類(lèi)和方法。
移動(dòng)
API提供了移動(dòng)元素的方法,可以把-一個(gè)或者幾個(gè)元素從一個(gè)地方移動(dòng)到另一個(gè)地方,從精確程度來(lái)說(shuō),和UI的移動(dòng)命令是一樣的。
方法描述 MoveElement(Document, Elementld, XYZ) 使用給定的平移變換移動(dòng)一個(gè)元素 MoveElements( Document, lCollction< Elementld>,XYZ) 使用給定的平移變換移動(dòng)元素集
MoveElement和MoveElements是常用的移動(dòng)方式,使用起來(lái)比較簡(jiǎn)單,但是有幾個(gè)需要注意的地方: ①移動(dòng)方法不能遠(yuǎn)離標(biāo)高向上或者向下移動(dòng)一個(gè)基于標(biāo)高的元素。也就是說(shuō),當(dāng)元素是基于標(biāo)高的,則不能改變Z軸坐標(biāo)值,但可以移動(dòng)元素到同–標(biāo)高內(nèi)的任意位置。例如,如果在坐標(biāo)點(diǎn)(0,0, 0)新創(chuàng)建了一個(gè)柱子,然后移動(dòng)它到新的坐標(biāo)點(diǎn)(10, 20, 30),這個(gè)柱子將會(huì)移動(dòng)到(10, 20, 0),而不是(10, 20, 30)。
②當(dāng)移動(dòng)一個(gè)元素的時(shí)候.其他的元素也許會(huì)跟著移動(dòng)。例如,如果一堵墻 上有窗戶(hù),這堵墻移動(dòng)了,窗戶(hù)也會(huì)跟著移動(dòng)。移動(dòng)元素集的方法也會(huì)出現(xiàn)這種情況。例如,當(dāng)移動(dòng)幾根柱子的時(shí)候,所有與柱子連接著的梁也會(huì)跟著被移動(dòng)或者會(huì)被改變長(zhǎng)度。
③如果元素被釘住,即Pinned屬性返回值是true, 則表明這個(gè)元素不能被移動(dòng)。如果仍然使用MoveElement方法來(lái)移動(dòng)這個(gè)元素,API就會(huì)拋出Invalid )perationException來(lái)提示用戶(hù)不能移動(dòng)被釘住的元素。
另外,還可以通過(guò)Location 類(lèi)來(lái)移動(dòng)一個(gè)元素。Location 類(lèi)提供了移動(dòng)和旋轉(zhuǎn)的方法,而且其子類(lèi)提供了更多的Location 信息和屬性控制,如LocationPoint 類(lèi)和LocationCurve類(lèi)。如果一個(gè)元素的Location 可以轉(zhuǎn)型為L(zhǎng)ocationCurve 或者LocationPoint,就可以直接移動(dòng)這根線(xiàn)或者點(diǎn)到新的坐標(biāo)點(diǎn)了。
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
) ;
}
如果使用上面這種方法移動(dòng)一個(gè)元素,那么請(qǐng)注意向量(10, 20, 0)并不是目標(biāo)坐標(biāo)值, 而是一個(gè)偏移向量。 另外,LocationCurve的Curve屬性或者LocationPoint的Point屬性也可以用來(lái)移動(dòng)一個(gè)元素。.
旋轉(zhuǎn)
方法描述 RotateElement(Document, Elermentld, Line, double) 使用給定的軸線(xiàn)和角度對(duì)- -個(gè)元素進(jìn)行旋轉(zhuǎn) RotateElements(Document, lCollction< Elementld>. Line, double) 使用給定的軸線(xiàn)和角度對(duì)元索集進(jìn)行旋轉(zhuǎn)
在旋轉(zhuǎn)方法中,旋轉(zhuǎn)角度是用弧度計(jì)量。正值是通過(guò)軸線(xiàn)做逆時(shí)針的旋轉(zhuǎn),對(duì)應(yīng)的負(fù)值就是做順時(shí)針旋轉(zhuǎn)
①當(dāng)旋轉(zhuǎn)–個(gè)元素時(shí),旋轉(zhuǎn)軸應(yīng)該是有限線(xiàn)段,如果是無(wú)限線(xiàn)作為旋轉(zhuǎn)軸線(xiàn),會(huì)導(dǎo)致旋轉(zhuǎn)失敗。 ②旋轉(zhuǎn)軸–般要求與元素LocationCurve所在的平面垂直,否則很可能會(huì)導(dǎo)致旋轉(zhuǎn)失敗。
鏡像
方法描述 MirrorElement(Document, Elementld, Plane) 使用給定的平面創(chuàng)建–個(gè)元素的鏡像拷貝 MirrorElements ( Document document, lCollection < Elementld>elementsToMirror, Plane plane) 使用給定的平面創(chuàng)建一-個(gè)元索集合的鏡像拷貝 CanMirrorFElement(Document. Elementld) 判斷元素是否可以進(jìn)行鏡像操作 CanMirrorElements( Document, lCollection< Elementld> ) 判斷元素集是否可以進(jìn)行鏡像操作
復(fù)制
ElementTransformUtils類(lèi)提供了幾個(gè)靜態(tài)方法,從某處復(fù)制一個(gè)或多個(gè)圖元到別處,,可以復(fù)制到同一文件或視圖內(nèi),也可以復(fù)制到其他文件或視圖內(nèi)。
方法描述 CopyElement (Document, Elementld, XYZ) 復(fù)制圖元并將其置于給定轉(zhuǎn)換所指定的位置 CopyElements ( Document, ICollection<Elementld>, XYZ) 復(fù)制–組圖元并將其置于給定轉(zhuǎn)換所指定的位置 CopyElements( Document, ICollction< Elementld>, Document,Transform, CopyPasteOptions ) 從源文件復(fù)制一組圖元到目標(biāo)文件 CopyElements (View, ICollection<Elementld>, View,Transform, CopyPasteOptions) 從源視圖復(fù)制一-組圖元到目標(biāo)視圖
刪除
方法描述 Delete( Elementld) 從文檔中將傳入Id的元素刪除 Delete( IOletion< ElementId> ) 從文檔中將傳入ld集合的元素集刪除
組合
在命名空間Autodesk. Revit. Creation 中,類(lèi)ItemFactoryBase 提供了NewGroup(ICollection< ElementId> )方法來(lái)選擇一個(gè)或者多個(gè)元素進(jìn)行組合,甚至可以選擇組合進(jìn)行再組合,這樣做可以使這些元素能在一個(gè)大的組合里面統(tǒng)一被修改。
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有三種類(lèi)型的組:模型組、詳圖組和附屬詳圖組。所有這些組都使用NewGroup() 方法來(lái)創(chuàng)建。所創(chuàng)建組的類(lèi)型取決于組內(nèi)圖元的類(lèi)型。 ●若無(wú)任何詳圖圖元,則創(chuàng)建的是個(gè)模型組。 如果所有的圖元都是詳圖圖元,那么創(chuàng)建的是個(gè)詳圖組。 ●如果這兩種類(lèi)型的圖元都包括在內(nèi),則創(chuàng)建一一個(gè)包含附屬詳圖組的模型組并返回。 注意:圖元成組后,可將圖元從項(xiàng)目中刪除。 ●①當(dāng)元素被組合起來(lái)了,它們?nèi)匀豢梢员粡奈臋n中刪除。在組合里面的元素被刪除 時(shí),這個(gè)元素在界面上仍然是可見(jiàn)的,但是這個(gè)元素實(shí)際上被刪除了,是不能再次被選中或 者被訪(fǎng)問(wèn)的。當(dāng)組合中最后一個(gè)元素被刪除或者是從組合里面移除了,這個(gè)組合的實(shí)體隨 后也將被刪除。
●當(dāng)項(xiàng)目中一組實(shí)例的最后-一個(gè)成員被刪除、剔除或移除時(shí),模型組實(shí)例也就被刪 除了。 圖元成組后,就不能移動(dòng)或旋轉(zhuǎn)。如果在已成組的圖元上執(zhí)行這些操作,盡管Move() 或Rotate( )方法返回true,但實(shí)際上圖元沒(méi)有發(fā)生任何變化。 如果參,照的圖元沒(méi)有成組,則無(wú)法將其尺寸和標(biāo)記成組。如果這樣做則API調(diào)用會(huì) 失敗。 開(kāi)發(fā)人員可以對(duì)參照某個(gè)模型組中模型圖元的那些尺寸和標(biāo)記進(jìn)行分組。這些尺寸和 標(biāo)記被添加到-一個(gè)附屬詳圖組。你無(wú)法單獨(dú)移動(dòng)、復(fù)制、旋轉(zhuǎn)、陣列或鏡像附屬詳圖組, 而不對(duì)其參照模型組執(zhí)行相同操作。
group . GroupType
. Name
= "MyGroup" ;
陣列
Revit API提供的陣列方法可以對(duì)一個(gè)或者多個(gè)元素創(chuàng)建線(xiàn)型的或者是徑向(圓弧型)的陣列。例如,可以選擇墻上的一.扇門(mén)或者一扇窗,陣列出多個(gè)門(mén)或窗的實(shí)體
Revit平臺(tái)API提供了兩個(gè)類(lèi),即LinearArray和RadialArray來(lái)陣列項(xiàng)目中的一個(gè)或多個(gè)圖元。這些類(lèi)提供靜態(tài)方法來(lái)創(chuàng)建一個(gè)或多個(gè)選定構(gòu)件的線(xiàn)性或徑向陣列。線(xiàn)性陣列表示從一個(gè)點(diǎn)順著一條線(xiàn)創(chuàng)建的陣列, 而徑向陣列表示沿弧線(xiàn)創(chuàng)建的陣列。 可以選擇同一面墻上的一扇門(mén)和一扇窗, 然后通過(guò)陣列創(chuàng)建門(mén)、墻、窗結(jié)構(gòu)布局的多個(gè)實(shí)例。LinearArray和RadialArray還提供了一些方法, 來(lái)陣列未被分組和關(guān)聯(lián)的一個(gè)或多個(gè)圖元1。雖然類(lèi)似于陣列圖元的Create( )方法,但每個(gè)目標(biāo)圖元都獨(dú)立于其他圖元,可對(duì)其操作而不影響其他圖元。
方法描述 LinearArray. Create ( Document,View, Elementld, int, XYZ,ArrayAnchorMember), 從傳人的元素中創(chuàng)建一個(gè)線(xiàn)型陣列 LinearArray. Create ( Document, View, ICollection < Elementld >,int. XYZ, ArrayAnchorMember) 從傳入的元素集中創(chuàng)建一個(gè)線(xiàn)型陣列 RadialArray. Create ( Document,View, Elementld, int, Line,double, ArrayAnchorMember) 從傳人的元素中創(chuàng)建一個(gè) 基于旋轉(zhuǎn)軸的圓弧型陣列 RadialArray. Create ( Document, View, lollction < Elementld>,int, Line, double, Array AnchorMember) 從傳 人的元素集中創(chuàng)建一個(gè)基于旋轉(zhuǎn)軸的圓弧型陣列
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én)\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 ( "元素不存在" , "沒(méi)有找到符合條件的墻" ) ; }
}
else
{ Autodesk
. Revit
. UI
. TaskDialog
. Show ( "族類(lèi)型不存在" , "沒(méi)有找到族類(lèi)型'" + doorTypeName
+ "'" ) ;
}
Document familyDoc
= RevitApp
. NewFamilyDocument ( @"C:\ProgramData\Autodesk\RVT 2014\Family Templates\Chinese\公制常規(guī)模型.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
;
}
總結(jié)
以上是生活随笔 為你收集整理的Revit二次开发——图元(元素)编辑 的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔 網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔 推薦給好友。