Message 1 of 10
Calculate distance from object to level 0

Not applicable
11-30-2020
11:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello!
I want to find distance from every object of given category to level 0 in document. And then I'm setting this value like "Object Height" parameter.
I'm trying to get it in this way:
using (Transaction tx = new Transaction(doc))
{
tx.Start("Set Parameter");
foreach (Element elem in allElements)
{
double z = 0.0;
Parameter p = elem.LookupParameter("Object Height");
LocationPoint loc = elem.Location as LocationPoint;
LocationCurve lc = elem.Location as LocationCurve;
if (loc != null)
{
z = loc.Point.Z;
}
else
{
z = lc.Curve.GetEndPoint(0).Z;
}
z = (Math.Round(z / 10) )* 10;
p.Set(z);
}
tx.Commit();
}
but I get strange values after rounding. I feel like I'm doing something wrong. Maybe there's another way to get current object height from level 0?