HostObjectUtils

HostObjectUtils

office
Enthusiast Enthusiast
1,083 Views
3 Replies
Message 1 of 4

HostObjectUtils

office
Enthusiast
Enthusiast

hi, i am trying to extract top faces of roofs in order to calculate their angles.

the code snippet is really short as  things should be easy:

 

faces = HostObjectUtils.GetBottomFaces(element)

after that i proceeded like:

face = doc.GetElement(faces[0])
		faceNormal = face.GetGeometryObjectFromReference(faces[0]).FaceNormal
		reference = XYZ(1,1,0)
		angle = reference.AngleTo(faceNormal)* (180 / math.pi)
		TaskDialog.Show("Revit", "angle = %s degrees" %(angle))

this is working perfectly if a roof has no tilting angle.

if it is tilted i receive as "face" a Autodesk.Revit.DB.FootPrintRoof not the topface!

 

what am i missing? or is there a more elegant way to extract a roofs tilting angle?

0 Likes
Accepted solutions (1)
1,084 Views
3 Replies
Replies (3)
Message 2 of 4

office
Enthusiast
Enthusiast

just found out that my math was a little rusty;-)

adopted my formula so now i receive correct angles.

but still i am exploring the object geometry instead of HostObjectUtils 

 

any suggestions?

0 Likes
Message 3 of 4

Anonymous
Not applicable
Accepted solution

One thing is that it seems you're variable names may not be helping:

 

faces = HostObjectUtils.GetBottomFaces(element)
face = doc.GetElement(faces[0])

Might help if it looked more like this:

//Because GetBottomFaces returns a list of References, not elements or faces
IList<Reference> bottomFaceReferences = HostObjectUtils.GetBottomFaces(element);

//GetElement Returns an element, (the element which contains the referenced geometry if you pass it a reference)) //hence this is from the department of redundancy department:
Element hostElement = doc.GetElement(bottomFaceReferences[0]);

//You could get the face from the reference you have and the element from which it came: Face face = hostElement.GetGeometryObjectFromReference(bottomFaceReferences[0]);

//Then you can get the normal XYZ FaceNormal = face.FaceNormal;

Element elementWhichContainsFaceReference = doc.GetElemetn(faces[0]);

because GetElement(Reference) returns an element (the element which owns the face reference you passed it).  I wouldn't expect GetElement to ever return a face so your question is a bit confusing:  are you actually getting a face from GetElement()?  In the future, try to not paraphrase your code because it makes it hard to follow.  Also, I would suggest that, in the case you're using "var" for these, use explicit typing so you can follow exactly what's going on.

 

As for the more elegant solution, if you're dealing with a footprint roof, each sketch line can have a different slope and is controlled by a parameter "defines slope".  Have a look at FootPrintRoof.SlopeAngle and FootPrintRoof.DefinesSlope parameters.  You can get the model curves of the footprint with FootPrintRoof.GetProfies().

 

Not sure If I answered your question but I hope I made it a little clearer

 

 

 

Message 4 of 4

office
Enthusiast
Enthusiast

ken thanks for both code and the more elegant solution!

0 Likes