There are two problems with calculations that involve division by a value that could be zero:
1. As previously noted, division by zero produces an undefined result, and therefore an error in VBScript.
2. Even if you try to use a conditional statement (such as If statement) to test for a zero value and only perform the division if the value is non-zero, VBScript evaluates the entire statement, not just the parts on the logical path, so if division by zero exists, even in the section that should not be evaluated, an error condition will still occur.
Fortunately, it is possible to write a formula that works around this limitation, as can be seen in the attached sample file. There are, no doubt, many ways to have ACA help in the calculation of occupant loads and I know others have done far more with this than is shown in the sample file here, but this should get you past the issues with division by zero in a formula property. The file was created in ACA 2011, so anyone using ACA 2010 or later should be able to take a look at the file.
I chose to create new Property Set Definitions [PSDs] for the newly created properties, rather than add them to the out-of-the-box [OOTB] PSDs, on the theory that that would make migrating to future releases easier, by keeping my customizations separate. You could just as easily add them to the OOTB PSDs if you want. I also chose to make the Occupant_Load property part of a style-based PSD. This assumes that you make use of different Space Styles for different space types/uses, and that each Space Style would always have the same occupant load factor. This allows you to enter the occupant load factor in the Space Style once, rather than for each instance. If you do not use different Space Styles for different space types, you could add the Occupant_Load property to an object-based Property Set Definition and enter the load factor for each Space you create. (Choose an appropriate default value for that property if you go that route.) The Space Styles used here are all OOTB ACA 2011 styles, with the custom SpaceStylesCalc PSD attached and a value for the Occupant_Load property entered. Spaces that have no occupant load (non-simultaneous occupancy areas) are set to 0.
If you want to use a style-based property, but want the ability to occasionally override that value on an individual Space, that can also be done; if you cannot figure out how to do so, post back and I will try to find time to add that to the sample file.
The SpaceObjectsCalc PSD is object-based and contains the Occupants formula property. This property uses the OOTB SpaceStyles:BaseArea property as the area on which the occupancy load calculation will take place. The example file does not attempt to allow for the fact that, depending upon the applicable code, some occupancy load factors will be based on gross square feet and others on net square feet. The calculation involves dividing the SpaceStyles:BaseArea property by the custom SpaceStylesCalc:Occupant_Load property value.
occLoad = [SpaceStylesCalcs:Occupant_Load]
If occLoad = 0 Then
doCalc = 0
occLoad = 1
Else
doCalc = 1
End If
If doCalc = 1 Then
RESULT = [SpaceStyles:BaseArea] / occLoad
Else
RESULT = 0
End If
The formula property starts off by setting a variable called occLoad to the value of SpaceStylesCalc:Occupant_Load. It gets around the division by zero issue by using two If statements. The first tests the value of occLoad. If occLoad is zero, then the variable doCalc is set to 0 and occLoad is reset to 1. [Any non-zero value would do, since the formula property will not return a calculated value when SpaceStylesCalc:Occupant_Load is set to 0. If occLoad contains a non-zero value, doCalc is set to 1 and the value of occLoad is not changed.
At this point, we now have a variable that tells us whether or not a calculation should take place (doCalc) and a variable for the divisor that will not be equal to zero. The second If statement tests the value of doCalc. If it is set to 1, then formula property returns result of dividing the value of the SpaceStyles:BaseArea property by the value in occLoad (the original value from SpaceStylesCalc:Occupant_Load). If doCalc is set to 0, then the formula property returns a value of 0.
Notes:
1. In the Enter Sample Values area of the formula property definition, the Format for the SpaceStyles:BaseArea property has been changed from the default Area, which rounds to two decimal places adds " SF" (imperial units version) to the area value, to a custom Property Data Format called Standard-8, which is a copy of the OOTB Standard Property Data Format with the precision increased to the maximum eight decimal places. The text suffix of the Area Property Data Format will cause math calculations to fail. The increase in precision is probably overkill, givent the calculation at hand. If you have large drawings with many Spaces, you might see an improvement in performance by using the OOTB Standard Property Data Format (three decimal place precision), or a custom one with less precision.
2. I created a custom Property Data Format called Occupants, which I applied to the formula property. This does two things - it adds a text suffix to the result (" OCC"). If you plan to use this value for further calculations, you will want to change the applied format to one that is only numeric in the formula property definition, as was done for the SpaceStyles:BaseArea property in the SpaceObjectsCalc:Occupants formula, as indicated in "Note 1" above. The other thing is does is round the calculated value up to the next whole number. When doing occupant load calculations, I always round any fractional amount up to the next whole person. If you choose to do your rounding this way, be certain to set the Round Off value to 1, as well as set the rounding to Up. Leaving the value set to 0 can have unexpected results. I did a series of articles on rounding in ACA properties (ADT properties at the time) back in August and September of 2005. I have not tested rounding much since then, but expect that things probably still work the same in more recent versions. If you are having problems with rounding using a Property Data Format, there are ways to calculate the desired rounding as part of the formula property. Those articles from 2005 and the referenced sample files show how.
http://architects-desktop.blogspot.com/2005/08/rounding-up-property-data-values.html
http://architects-desktop.blogspot.com/2005/08/rounding-revisited.html
http://architects-desktop.blogspot.com/2005/09/rounding-redux.html
http://architects-desktop.blogspot.com/2005/09/rounding-to-death.html
3. I added a Schedule Table into the sample file to display the pertinent property values associated with the Spaces in the sample file.
David Koch
AutoCAD Architecture and Revit User
Blog | LinkedIn
