I need to convert horizontal floor geometries from Revit rooms into a text file with the following format:
(x1 y1) (x2 y2) … (xn yn) where x and y is each vertices in clockwise order using python and wonder if anybody could get me started? Any help would be appreciated.
Rooms from Revit are stored as generic Speckle objects with the type: Objects.BuiltElements.Room
The boundaries are stored as Objects.Geometry.Polycurve
in each Room’s outline
property. The Polycurve will have a segments
property.
Each of those segments could be Lines
or Arcs. Let’s assume the typical case of them just being Lines, each has a start
and end
property each with x
, y
& z
properties.
traversing each Room then is as simple as retrieving :
outline.segments[].start.x
outline.segments[].start.y
outline.segments[].end.x
outline.segments[].end.y
I have to admit I don’t recall if the boundary segments are guaranteed to be ordered as a continuous loop or if they are clockwise, but this is the base case from which to start.
Did you need any more general guidance on using specklepy to retrieve Speckle Revit data?
If you want to make a narrow search for just that data to make traversal simpler, you could make a direct graphQL query with the specklepy client:
query getRoomBoundaries($roomQuery: [JSONObject!]) {
stream(id: "{{STREAM_ID") {
object(id: "{{COMMIT.REFERENCED_OBJECT_ID}}") {
children(
query: $roomQuery
select: ["name", "outline.segments", "speckle_type"]
) {
objects {
data
}
}
}
}
}
{
"roomQuery": [
{
"field": "speckle_type",
"value": "Objects.BuiltElements.Room",
"operator": "="
}
]
}
This will return the scope of data you need if this is your only task (snipped to just the relevant data properties
{
"data": {
"stream": {
"object": {
"children": {
"objects": [
{
"id": "___",
"data": {
"name": "WC",
"outline": {
"segments": [
{
"speckle_type": "Objects.Geometry.Line",
"start": {
"x": 20.054304701072414,
"y": 2.8802141771261254,
"z": 0.7500000569758418,
...
"end": {
"x": 18.802024934176746,
"y": 2.880214177126129,
"z": 0.7500000569758418,
...
},
...
},
...
},
...
Thanks a lot for the great help. I think this would make a great tutorial, rooms are interesting BIM objects for data visualization. I also would need to convert non prismatic rooms to OBJ-files using python but first I will solve the prismatic ones.
For my education, what are you referring to as Non-prismatic rooms?
Do you mean where the volumes reflect downstanding beams etc.??
I have two basic geometries. Both consists of planar surfaces creating watertight volumes.
- Prismatic volumes consisting of horizontal floor and vertical walls. The input is a series of corners (x,y), floor height and height of volume/walls. More info at Prism (geometry) - Wikipedia
- Non prismatic volumes that has a much more complex format including corners and surfaces similar to OBJ.
I have failed utterly getting room geometry using you script. I am not even able to access a stream using Python. I would really appreciate a little more help.