Revit API cơ bản buổi 6 (31/07/2019)
Solid
- 1 element có thông tin hình học (geometry) và thông tin phi hình học. Nội dung bài này sẽ tìm hiểu về thông tin hình học mà cụ thể là Solid.
- Một dự án Revit được tạo thành từ nhiều elements và các elements này được Revit tổ chức theo các class con như:
	- Wall => class Wall
- Floor => class Floor
- Roof => class Roof
- … các element là System Element có class riêng của nó.
- Columns, Frames, Windows, Doors, … và các đối tượng được tạo từ family => class FamilyInstance.
 
=> Cách tổ chức khác nhau dẫn đến cách lấy Solid của các đối tượng cũng có sự thay đổi.
Code mẫu tham khảo
Reference reference1 = uidoc.Selection.PickObject(ObjectType.Element);
Element element = doc.GetElement(reference1);
Options options = new Options();
options.View = doc.ActiveView;
options.IncludeNonVisibleObjects = true;
GeometryElement geometryElement = element.get_Geometry(options);
IList<Solid> elementSolids = new List<Solid>();
foreach(GeometryObject geometryObject in geometryElement)
{
	Solid solid = geometryObject as Solid;
	if (solid != null)
	{
		if(solid.Volume > 1e-9)
		{
			elementSolids.Add(solid);
		}
	}
	else
	{
		GeometryInstance geometryInstance = geometryObject as GeometryInstance;
		if(geometryInstance != null)
		{
			GeometryElement geometryElement1 = geometryInstance.GetInstanceGeometry();
			foreach (GeometryObject geometryObject1 in geometryElement1)
			{
				Solid solid1 = geometryObject1 as Solid;
				if (solid1 != null)
				{
					if (solid1.Volume > 1e-9)
					{
						elementSolids.Add(solid1);
					}
				}
			}
		}
		
	}
}
Solid mergedSolid = null;
foreach(Solid solid in elementSolids)
{
	if(mergedSolid == null)
	{
		mergedSolid = solid;
	}
	else
	{
		mergedSolid = BooleanOperationsUtils.ExecuteBooleanOperation(mergedSolid, solid, 
			BooleanOperationsType.Union);
	}
}
MessageBox.Show("Volume: " + (mergedSolid.Volume).ToString());
Liên kết hữu ích
Reply 0
You need to Login to Reply!
