Export boundaries of Revit Rooms to SVG, and use them in PowerBi

I see you did this yourself but I went ahead and updated the below to include a few comments to help with getting svg from rooms instead of areas, heres a few highlights with full script below:

from Autodesk.Revit.DB.Architecture import RoomFilter

# alias areaFilter, for areas (not rooms) we will want to exclude
areaFilter = AreaFilter()
# change to room filter if you want svg of areas not rooms
#areaFilter = RoomFilter()

# min x value rounded up/down for +/-ve numbers for use in svg tag
if xmin < 0 : xminc = math.floor(xmin)
else : xminc = math.ceil(xmin)

# width of svg viewbox rounded up from, max - min
width = math.ceil(xmax - xminc)

# min y value rounded up/down for +/-ve numbers for use in svg tag
if ymin < 0 : yminc = math.floor(ymin)
else : yminc = math.ceil(ymin)

# height of svg viewbox rounded up from, max - min
height = math.ceil(ymax - yminc)
2 Likes

Hi @d.sellam.

i have same issue, try export polygon not line.
did you find out how to solve it?

Amir,

Did anyone manage to solve export room/area plans to svg, so that they can be used with Synoptic Design for Power BI?

Hi @klausvm Glad you find the SVG exporter useful, in answer to your mail…

Hi Adam

I find your python script for SVG export to Power BI very usefull. However, it does not seem to export inner boundaries. I have a room, with an atrium made with room seperation lines, but the inner boundary is not recognized and exported. Any idea how this can be done?

Thank you alot in advance,
Klaus

Your right it doesn’t export inner boundaries.

In order to include inner boundaries, if we assume not all rooms have inner boundaries, there would need to be some filtering for which rooms have no inner boundary and possibly for which rooms have more than a single inner boundary. To avoid having to do that filtering focusing on just the outer boundaries, GetBoundarySegments[0] is a bit of a workaround, but like you point out it does mean that inner boundaries get ignored

It is is possible to find the inner loop of room boundaries using GetBoundarySegments if you look at the comments on the python you can see that list index 0 is used to find the outer boundaries, through a bit of experimentation its possible to find index 1 is the first inner boundary then index 2 is the second inner boundary etc

Even once you collect the inner boundaries there is still an issue of how to display that as an svg. cutting a hole in svgs is can be done using path but its not something that svg can describe in a single line of code so a much more complicated svg generation would need to be scripted for

Perhaps a simpler method would be to split the room with an inner boundary so that it is 2 rooms with only an outer boundary, however you decide to proceed good luck !

Hi Adam,

I’ve been trying to make to work your python script but I don’t get it to work (see attached image and script)… What am I missing ?

Regards,

SVGExporter.dyn (23.1 KB)

I got it to work in another file, but the result is not the expected
https://raw.githubusercontent.com/amadeumagalhaes/dyn-scripts/master/roomSvgExporter.py/EML/00%20-%20rooms.svg

Hi, if you send me your rvt file I’ll see what’s happening…

its probably a units thing, maybe ft to mm, I can see all your svg lengths are less than 1…


Hi, I have tried the same script for svg export. I got the message as svg not updated. (Didn’t work)

If you send me your Revit file I could take a look when I get a moment

Project1_2018.rvt (3.2 MB)
Just 4 walls with one room.

That might be the problem perhaps… If there is only one instance of a room and it’s expecting a list, try two rooms perhaps

Hi @Nissal, this worked ok for me, so not sure what to suggest, other than perhaps giving it another go with the code from link below

<!--
Created with Chapman Taylor Dynamo SVG exporter
byabear@chapmantaylor.com

Revit Source File:
C:\Users\ABEAR\Downloads\Project1_2018.rvt

Date:
12/02/2020 12:33:02
-->

<svg xmlns="http://www.w3.org/2000/svg" class="gen-by-CTA-dyn-Synoptic-for-PowerBI" viewBox=" -21.0 -11.0 6.0 5.0 " transform="scale( 0.95 )">

<style>
polygon {
fill: gainsboro;
stroke: red;
stroke-width: 0.1px;
}
</style>

<polygon id="1" points="-0015.516,-0010.120,-0020.616,-0010.120,-0020.616,-0006.920,-0015.516,-0006.920" />

</svg>
1 Like

Hi @adam_bear1 thank you for sharing your node. I ran a few tests with it and have a few questions, if you don’t mind. I thought this was still along the discussion of the original thread so I am replying here, otherwise I am happy to start a new one.

My main (4) questions are:

  1. When exporting to SVG, what controls the “Canvas” size of the image? For example, if I were to open some tests in Power BI or Inkscape, all the shapes are there but some get cutoff by the extents of the canvas. Is this some scale issue? How does one focus everything to the center of the “Canvas” ensuring everything fits? I played around with the curvescale and svgscale parameters but they seemed to affect more of the coarse or crisp nature of the lines.
  2. On a tangent to this question, is it common to have to use another software after like Inkscape to “Clean up” and adjust the shapes before importing to Power Bi?
  3. I noticed the script has some trouble with curvature. What is the best way to handle and export curves?
  4. If I have a viewport that is rotated, is there an addition you can add to honor that orientation or would it be eaiser to post rotate the shapes in Inkscape?

Thank you.

Hi @RVT,

glad you like the python code, I’ll do my best to answer your questions:

  1. the ‘canvas’ is called a viewbox in SVG terminology, you can find my code that deals with the viewbox here

and some more info on SVG viewbox here

https://www.google.com/search?q=svg+viewbox

tricky to see whats happening if you dont provide some files but if you have a read of the above that should get you going at least. curveScale is used to change revit units into pixels I arbitrarily set this to 0.001, svgScale is used to scale slighty inside the viewbox so that room boundaries didn’t touch the edge of the screen which I found a bit annoying, again this is arbitrarily set to 0.95 but you could try other values if you like

  1. I’ve never used inkscape, I wanted to create a python script that would mean that you didn’t have to do any editing to the svg. A lot of other methods of creating SVGs that Ive seen discussed in relation to Power BI do use inkscape because they have not tried to use python to extract geometry, they usually rely on taking a pdf plan and then vectorising that in inkscape with some degree of manual work in tagging the svg which I was trying to avoid

  2. to be fair i didn’t test this script with ‘curved’ curves so I cant really comment, might be an interesting one to investigate

  3. I’m not going to update this python script to take into account the rotation of a particular viewport, if thats what you want to do I think you might be better off using inkscape

good luck, be good to hear how you get on

3 Likes

Thank you for clarifying the sections and terminology. It is only fair I do my part and research them a bit more. I will look into it further and let you know if I have any other questions.

Hi @adam_bear1,
Your code worked well in my case :smiling_face_with_three_hearts:. One request; is it possible to export the room name and their department also into SVG?
I need to color the room based on their department in Power BI. If you know any other solution to color the room based on their department please let me know.

I’ve not tested this, but you could try modifying the code so that it refers to ROOM_DEPARTMENT instead of ROOM_NUMBER you can look up other built in parameters at revitapidocs.com

https://www.revitapidocs.com/2016/fb011c91-be7e-f737-28c7-3f1e1917a0e0.htm

here’s a link to line 246

As I say I’ve not tested it, I’ve got a feeling that strictly speaking you shouldn’t have multiple svgs with the same id, that might cause problems, so you might want to concatenate the department with the room number or something…

1 Like

Hi @adam_bear1,
Thanks for your help. I arranged the fields like this in Power BI and it resolved my problem.
image

I would like to ask you one more doubt. My manager needs to display the Room number on the map. So I switch on the “Data Label” in Power BI. But the label size is very big and the maximum possible minimum text size can be provided is 8pt in Power BI.


Once I bring the same plan using synoptic designer the label size is properly scaled and readable and the text size is 9 pt only. as shown in the below image.


I prefer to use your code because the visual quality of the map is very high once I export it to SVG using your code. Do you believe that the label scaling can be controlled by your code or is it something related to Power BI?

Label scaling will be down to the synoptic panel visualisation in power bi, but you can achieve a lot by changing the size of your power bi canvas (and the visualisation placed on it) so that 9pt text is relatively large or small