Geometry from HostObjectUtils.GetTopFaces returns null

Geometry from HostObjectUtils.GetTopFaces returns null

Anonymous
Not applicable
1,192 Views
7 Replies
Message 1 of 8

Geometry from HostObjectUtils.GetTopFaces returns null

Anonymous
Not applicable

Hi everyone,

Last night I was trying to make a split roof function which creates different roofs for each top face.

At the moment it is working around half of the time because sometimes it can't find the geometry of the face reference. Most of the times the workaround is to draw the roof again and use the function again. But I can't figure out what causes the error.

 

The code looks kind of like this:

var host = _doc.GetElement(RoofReference) as HostObject;
var topReferences = HostObjectUtils.GetTopFaces(host);

foreach (var r in topReferences)
{
   var face = host.GetGeometryObjectFromReference(r) as PlanarFace;
   var curveLoop = face.GetEdgesAsCurveLoops().First();
}

 

The value of face can sometimes be null.

I don't know the cause of this.

 

Can somebody give me an explanation why this occurs.

Or maybe a different method I can use.

 

Thanks anyway,

Jens Slofstra

0 Likes
Accepted solutions (2)
1,193 Views
7 Replies
Replies (7)
Message 2 of 8

zrodgersTSSSU
Advocate
Advocate

Is it still functioning the way you want it to? Or is it not creating the second part of the roof? If its functioning the way you want it too you can just check to make sure the face isn't equal to null then it wouldn't give you that error.

0 Likes
Message 3 of 8

Anonymous
Not applicable

Thanks for the quick reply.

But it isn't generating the roof because it can't get the curveloops of the face with the value null.

An option is to check if the face is null and the skip it but I would rather not.

0 Likes
Message 4 of 8

RPTHOMAS108
Mentor
Mentor

Is the Face a Planarface?

Message 5 of 8

jens.slofstra!
Enthusiast
Enthusiast

Hi RPTHOMAS108,

Yes every face of a roof is a planar face.

0 Likes
Message 6 of 8

RPTHOMAS108
Mentor
Mentor

I take your response to mean that the roofs you are dealing with have only Planar faces.

 

If not already done so I would compare the references from HostObjectUtils.GetTopFaces to what you get from picking such faces (Selection.PickObject) in terms of the string representation from Reference.ConvertToStableRepresentation. This may give clues as to why geometry object is not returned from Element.GetGeometryObjectFromReference.

 

 

Message 7 of 8

jens.slofstra!
Enthusiast
Enthusiast
Accepted solution

Hi RPTHOMAS18,

I've tried your suggestion and this is the result.

 

HostObjectUtils.GetTopFaces(host) returns:

13cfd193-d686-402c-b3b8-105795423c1f-00327c00:13:SURFACE
13cfd193-d686-402c-b3b8-105795423c1f-00327c00:14:SURFACE
13cfd193-d686-402c-b3b8-105795423c1f-00327c00:15:SURFACE
**face** was null.

 

PickObject(ObjectType.Face) returns:

13cfd193-d686-402c-b3b8-105795423c1f-00327c00:13:SURFACE
13cfd193-d686-402c-b3b8-105795423c1f-00327c00:14:SURFACE
13cfd193-d686-402c-b3b8-105795423c1f-00327c00:16:SURFACE
13cfd193-d686-402c-b3b8-105795423c1f-00327c00:50:SURFACE

 

So two of the four are not the same when the face is picked.

But now I am stuck because how can I find the face which returned null and make it not return null?

0 Likes
Message 8 of 8

RPTHOMAS108
Mentor
Mentor
Accepted solution

That is strange I understand as follows:

13 & 14 are common to both methods

15 doesn't exist for the second method are you saying it returns a null face when used with GetGeometryObjectFromReference?

 

16 & 50 only exist for the second method.

 

Do you have an example file you can share for this?

0 Likes