revit api族示例坐标和全局坐标转换
在制作族的时候,族文件中的几何体具有自己的坐标系。当加载族文件到Revit模型文件中,插入改族实例到模型后,族实例中的几何体具有自己的坐标。从族实例获取几何体的几何信息由两种方法:
FamilyInstance.GetOriginalGeometry() 方法: 获取这个族实例在被剪切,合并等操作之前的几何数据GeometryElement。其数字是相对于Revit的模型坐标系。
FamilyInstance.Geometry 属性: 可以获得这个族实例经过后期处理(剪切,合并等)之后的几何数据(GeometryElement)。
现在我们了解下上面方法返回的几何体的坐标值与族文件中的几何体的坐标值之间的关系。Revit API在这点上作了非常好的工作它提供了一个属性GeometryInstance.Transform,我们可以获得转换矩阵Transform。这个转换矩阵可以把族文件中几何实体的坐标信息直接转成成族实例在模型文件坐标系中的坐标。
GeometryInstance 对象可以从GeometryElement) 中获得。
请看下面示例,获取柱子族定义中的坐标转成成柱子在模型坐标系下的转换矩阵。然后将柱子族中的原点(0,0,0)点转成到模型坐标系下的坐标。
Selection sel = this.ActiveUIDocument.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element,"Please a column");
//For simplicity, ignore the code to check if the picked element is column.
FamilyInstance col = doc.GetElement(ref1) as FamilyInstance;
Options opt = new Options();
opt.ComputeReferences = false;
opt.View = doc.ActiveView;
GeometryElement geoElement = col.get_Geometry(opt);
Transform trans = null;
foreach(GeometryObject geoObj in geoElement)
{
if(geoObj is GeometryInstance)
{
GeometryInstance geoInst = geoObj as GeometryInstance;
trans = geoInst.Transform;
break;
}
}
if(trans !=null)
{
XYZ ptFamilyOrigin = new XYZ(0,0,0);
XYZ ptInModel = trans.OfPoint(ptFamilyOrigin);
//compare with the column's position in the model.
XYZ ptColumnPos = (col.Location as LocationPoint).Point;
string result = "The transformed family origin in model is:("
+ ptInModel.X.ToString() + "," + ptInModel.Y.ToString() + "," + ptInModel.Z.ToString() +")"
+ "\r\nThe column's position in model is:("
+ ptColumnPos.X.ToString() + "," + ptColumnPos.Y.ToString() + "," + ptColumnPos.Z.ToString() + ")";
TaskDialog.Show("Result",result);
}
posted on 2025-11-01 01:17 sswsswssw1996 阅读(1) 评论(0) 收藏 举报
浙公网安备 33010602011771号