-
Revit2016
二次开发笔记
1.
选中图元
1.1
事先选择某类图元
(
Wall
)
ication
revit = ation;
ElementSet
collection = new
ElementSet();
ElementSet
selWall = new
ElementSet();
foreach
(ElementId elementId in mentIds())
{
(ment(elementId));
//
选中的原件
}
foreach (Element ele in
sel)
{
Wall wall = ele as
Wall;
//
如果为墙
if (wall !=null)
{
(ele);
}
}
1.2.
通过交互方式
1.2.1
用矩形框选择图元
所用方法:
PickElementsByRectangle()
using c;
//
声明引用命名空间,
Ilist
UIDocument uidoc = UIDocument;
ElementSet collector = new
ElementSet();
IList
//
矩形框的应用
string info =
所选图元:
foreach
(Element elem in elemList)
{
(elem);
info +=
}
(
return ded;
1.2.2
用点击选择图元
所用方法:
PickObject(t)
using ion;
//
声明引用命名空间,
ObjectType
UIDocument uidoc = UIDocument;
Reference hasPickOne = ject(t);
Element elem = ment(tId);
string info =
所选图元:
info +=
(
还存在其它用法:
ject (ObjectType,
String)
//string
为提示
PickObjects (ObjectType)
//
允许选择多个元素
1.2.3
选择及过滤
UIDocument uidoc = UIDocument;
ISelectionFilter selFilter = new
MassSelectionFilter();
IList
string info =
选择了以下的墙:
foreach(Element
elem in eList)
{
info +=
}
(
return ded;
public class
MassSelectionFilter : ISelectionFilter
{
public bool
AllowElement(Element elem)
{
return elem is Wall;
//
选择了墙
}
public bool
AllowReference(Reference reference, XYZ position)
{
throw new
NotImplementedException();
//
第二个条件
}
}
2.
加载族并创建实例
UIApplication
m_application;
UIDocument
m_document;
m_application = ation;
m_document = m_UIDocument;
2.1.
加载族
1) m_document .milySymbol (
FullPath
, symbolName,
out
loadedfamilySymbol);
2) m_document .mily (
FullPath
,
out
loadedfamily);
第一种用来加载族类型,第二种用来加载族,返回的
loadfamily
和
loadfamily
symbol
可
以随后用来创建族实例
2.2
创建族实例
创建族实例将经过:
1
)选择一个平面,建立一个工作平面
2
)选择一个点放置族实例
2.1
选择平面
Reference
faceRef =
m_ject(
ObjectType
.Face,
new
PlanarFaceFilter
(m_nt),
ESC for cancel.
);
GeometryObject
geoObject = <
/p>
m_ment(faceRef).GetGeometryObjectFromRef
erence(faceRef);
PlanarFace
planarFace =
geoObject
as
PlanarFace
;
//
判断选择为平面的类
public
class
PlanarFaceFilter
:
ISelectionFilter
{
//
Revit document.
Document
m_doc =
null
;
///
Constructor the filter
and initialize the document.
public
PlanarFaceFilter(
Document
doc)
{
m_doc = doc;
}
///
Allow
all the element to be selected
public
bool
AllowElement(
Element
element)
{
return
true
;
}
///
Allow planar
face reference to be selected
public
bool
AllowReference(
Reference
refer,
XYZ
point)
{
}
}
GeometryObject
geoObject = <
/p>
m_ment(refer).GetGeometryObjectFromRefer
ence(refer);
return
geoObject !=
null
&&
geoObject
is
PlanarFace
;
2.2
创建工作平面
SketchPlane faceSketchPlane =
CreateSketchPlane(rmal, );
if
(faceSketchPlane !=
null
)
{
//
对模型进行操作必须新建
Transaction
事件
Transaction
changeSketchPlane =
new
Transaction
(m_nt,
Plane.
);
();
m_Plane =
faceSketchPlane;
m_tiveWorkPlane();
();
}
//
创建工作平面的子方法
internal
SketchPlane
CreateSketchPlane(.
XYZ
normal,
.
XYZ
origin)
{
// First create a
which need in NewSketchPlane() method
Plane
geometryPlane = m_ne(normal, origin);
// Then create a sketch plane using the
Geometry Plane
Transaction
createSketchPlane =
new
Transaction
(m_nt,
a sketch
plane.
);
();
SketchPlane
plane =
SketchPlane
.Create(m_nt,
geometryPlane);
();
return
plane;
}