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)
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_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:
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.
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?
I noticed the script has some trouble with curvature. What is the best way to handle and export curves?
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?
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
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
to be fair i didn’t test this script with ‘curved’ curves so I cant really comment, might be an interesting one to investigate
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
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 . 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
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…
Hi @adam_bear1,
Thanks for your help. I arranged the fields like this in Power BI and it resolved my problem.
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