We discussed abstract volume computation of a convex hull or cloud of points last week. Revit can also compute certain volumes, of course, for instance the volume of rooms. However, this functionality is not automatically enabled. To switch it on you need to set a certain toggle called VolumeComputationEnable on the document settings volume calculation options. Unfortunately, there is a slight issue with the API documentation on this property ...
Question: When I try turn on the value of the VolumeComputationEnable property so I can export the volumes of rooms, the value doesn't change.
This is the code that I use for modify this property:
Dim revitapp As Autodesk.Revit.Application _ = revitCommandData.Application Dim activedoc As Autodesk.Revit.Document _ = revitapp.ActiveDocument activedoc.Settings.VolumeCalculationSetting _ .VolumeCalculationOptions.VolumeComputationEnable _ = True
Answer: The code sample on the VolumeCalculationOptions.VolumeComputationEnable property in the Revit API help file does not work. It says that one can set the property using
doc.Settings.VolumeCalculationSetting .VolumeCalculationOptions .VolumeComputationEnable = true;
This code snippet will not work, because VolumeCalculationOptions is a value class and just returns information about the current status. Therefore you need to write it back to the VolumeCalculationSetting property to turn on the computation. One has to use something like this instead:
VolumeCalculationOptions options = doc.Settings.VolumeCalculationSetting .VolumeCalculationOptions; options.VolumeComputationEnable = true; doc.Settings.VolumeCalculationSetting .VolumeCalculationOptions = options;
I copied the sample code from the API document and removed one line to create this little reporting method which does not modify anything:
public void GetRoomDimensions( Document doc, Room room ) { string roominfo = "\nRoom dimensions:"; roominfo += "\nVolume: " + room.Volume; roominfo += "\nArea: " + room.Area; roominfo += "\nPerimeter: " + room.Perimeter; roominfo += "\nUnbounded height: " + room.UnboundedHeight; Debug.Print( roominfo ); }
Then I implemented the following external command to test it and verify that it works fine now:
public IExternalCommand.Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements ) { Application app = commandData.Application; Document doc = app.ActiveDocument; ElementSet a = doc.Selection.Elements; Room room = null; foreach ( Element e in a ) { if ( e is Room ) { room = e as Room; break; } } if( null == room ) { message = "Please select a room."; } else { Debug.Print( "VolumeComputationEnable = {0}", (doc.Settings.VolumeCalculationSetting .VolumeCalculationOptions .VolumeComputationEnable ? "true" : "false") ); GetRoomDimensions( doc, room ); // turn on volume calculations: VolumeCalculationOptions options = doc.Settings.VolumeCalculationSetting .VolumeCalculationOptions; options.VolumeComputationEnable = true; doc.Settings.VolumeCalculationSetting .VolumeCalculationOptions = options; GetRoomDimensions( doc, room ); } return IExternalCommand.Result.Failed; }
Here is the log displayed in the debug output window after selecting a sample room and running this command:
VolumeComputationEnable = false Room dimensions: Volume: 0 Area: 73.6251472502946 Perimeter: 36.745406824147 Unbounded height: 13.1233595800525 Room dimensions: Volume: 966.209281499929 Area: 73.6251472502946 Perimeter: 36.745406824147 Unbounded height: 13.1233595800525
Hi Jeremy.
Do you know if it is possible to catch the last command or tool used?
By the way, is it the correct place to ask you some stuff wich are most of time nothing to see with the current post?
Cheers!
Posted by: Pierre NAVARRA | June 29, 2009 at 05:59
Dear Pierre,
Obviously, if you can find a blog post that is related to the topic you have a question on, then that would be the best place to submit it. Otherwise, I don't mind if you post it anywhere you like.
How to catch the last command or tool used? Hmm, well, it would be nice to tap into the Revit undo stack, wouldn't it? I do have one idea that you can realistically explore a little bit: if you look at the current journal file, it will tell you all the actions that have taken place in the active session. This includes calls to tools that were executed and the elements affected. For instance, I created a new wall, moved it, and then deleted it. Afterwards, I found the following information in the journal file:
Jrn.Command "Internal" , "Create a wall , ID_OBJECTS_WALL"
Jrn.Data "Transaction Successful", "Wall - Line"
' 0: Candidates (curIdx = 0): 137774 (-10.042006, +6.541914, +3.937008)
Jrn.Data "Selection action", "REPLACE", "SEL RESULT: Walls : Basic Wall : Generic - 200mm"
' 0: Candidates (curIdx = 0): 137793-33212 (-9.539976, +10.004571, +3.937531) 137774 (-10.042006, +6.541914, +3.937008)
Jrn.Data "Control", "WallFlipControl", 1.00000000000000
Jrn.Data "Transaction Successful", "Change wall's orientation"
' 0: Candidates (curIdx = 0): 137774 (-6.810193, +6.541914, +3.937008)
Jrn.MouseMove 1 , 672 , 403
Jrn.MouseMove 1 , 671 , 346
Jrn.LButtonUp 0 , 671 , 346
Jrn.Data "Transaction Successful", "Drag"
Jrn.Command "AccelKey" , "Delete the selection , ID_BUTTON_DELETE"
Jrn.Data "Transaction Successful", "Delete Selection"
Jrn.Command "SystemMenu" , "Quit the application; prompts to save projects , ID_APP_EXIT"
As you can see, with a bit of imagination, the journal file lists the tools used as well as the element ids of objects affected, although obviously this is totally undocumented, unsupported, purely to play with at your own risk.
You can also have a look at the post
http://thebuildingcoder.typepad.com/blog/2009/02/getting-the-journal-file-path.html
Cheers, Jeremy.
Posted by: Jeremy Tammik | June 29, 2009 at 09:22