extract material from ReferenceWithContext

extract material from ReferenceWithContext

c_hanschen
Advocate Advocate
1,268 Views
6 Replies
Message 1 of 7

extract material from ReferenceWithContext

c_hanschen
Advocate
Advocate

Hello,

 

Short Story:

How can I find the material of the face found by ReferenceIntersector..??

 

Long Story:

I'm using a ray (ReferenceIntersector) to find intersecting elements, this works out great!

 

It returned a 'List(Of ReferenceWithContext)' that provides me information of intersection (.GetReference.GlobalPoint) and element (.GetReference.ElementId)

 

Even thru I used the .TargetType = FindReferenceTarget.Face, it's returns the ElementId's of the Revit elements, not the face.

An element (by example a Window) can contain many faces.

How can I find the material of the face found by ReferenceIntersector..??

 

This is one of the things I tryed: (type conversion from reference to face, because a face has a material)

 

If MyReferenceWithContext.GetReference.ElementReferenceType = ElementReferenceType.REFERENCE_TYPE_SURFACE Then

  Dim MyFace As Face = TryCast(MyReferenceWithContext.GetReference, Face)
  MsgBox(MyFace.MaterialElementId.IntegerValue.ToString)

End If

 

Thanks,

 

Chris Hanschen

The Netherlands

0 Likes
Accepted solutions (1)
1,269 Views
6 Replies
Replies (6)
Message 2 of 7

FAIR59
Advisor
Advisor
Accepted solution

You get the face from the Element using the GetGeometryObjectFromReference method.

 

            ReferenceWithContext context              
            Element el = doc.GetElement(context.GetReference().ElementId);
            GeometryObject geoObj = el.GetGeometryObjectFromReference(context.GetReference());
                Face _face = geoObj as Face;
                if (_face != null) TaskDialog.Show("debug", doc.GetElement( _face.MaterialElementId).Name);
            
Message 3 of 7

Revitalizer
Advisor
Advisor

Hi FAIR59,

 

the face may be part of an element inside a linked document,

so its material may not exist in the main document but in the linked one.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 4 of 7

c_hanschen
Advocate
Advocate

Thanks a lot...!!

 

I will try this later this week, but this seems to be what I am looking for..!!!

 

Chris

The Netherlands

0 Likes
Message 5 of 7

c_hanschen
Advocate
Advocate

Hello!

 

New question similar te the one in this topic.

 

Getting ReferenceWithContext by Ray is on of the most powerful functions in the Revit API, for me it is #1!

 

In de Aanswers in this Topic we can read how te get the Face and the Material of the Face.

 

Is there a way to get the (name of) the Subcategory of this Face?

 

Thanks!

 

Chris Hanschen

LKSVDD architecten 

The Netherlands

 

0 Likes
Message 6 of 7

RPTHOMAS108
Mentor
Mentor

You can get from the GraphicsStyleId if a subcategory is set for the solid in the family.

 

200705.PNG

Message 7 of 7

c_hanschen
Advocate
Advocate

New Question about getting info from ReferenceWithContext, in this topic we found .Face and .Material, but how to get the .Transform of/for the .Face ?

 

Thanks in Advance,

 

Chris Hanschen

LKSVDD architecten 

The Netherlands

0 Likes