Creates a light type object from the given document and element ID
Namespace: Autodesk.Revit.DB.Lighting
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)
Since: 2013
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Parameters
- document
- Type: Autodesk.Revit.DBDocument
The document the instanceId is from
- instanceId
- Type: Autodesk.Revit.DBElementId
The ID of the light fixture instance
Return Value
The newly created LightType objectExamples

public LightType GetLightTypeFromLightInstance(Document document)
{
if(document.IsFamilyDocument) // not used in family document
return null;
// In order to get the light infromation, please get a light fixture instance first
FilteredElementCollector collector = new FilteredElementCollector(document);
collector.OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_LightingFixtures);
FamilyInstance lightFixture = collector.Cast<FamilyInstance>().First<FamilyInstance>();
if (lightFixture == null) // check null reference
return null;
// Get the LightType for given light fixture
return LightType.GetLightTypeFromInstance(document, lightFixture.Id);
}

Public Function GetLightTypeFromLightInstance(document As Document) As LightType
If document.IsFamilyDocument Then
' not used in family document
Return Nothing
End If
' In order to get the light infromation, please get a light fixture instance first
Dim collector As New FilteredElementCollector(document)
collector.OfClass(GetType(FamilyInstance)).OfCategory(BuiltInCategory.OST_LightingFixtures)
Dim lightFixture As FamilyInstance = collector.Cast(Of FamilyInstance)().First()
If lightFixture Is Nothing Then
' check null reference
Return Nothing
End If
' Get the LightType for given light fixture
Return LightType.GetLightTypeFromInstance(document, lightFixture.Id)
End Function
Exceptions
Exception | Condition |
---|---|
Autodesk.Revit.ExceptionsArgumentException | The ElementId is the argument that is being validated The ElementId is not valid because it is not for a light element. |
Autodesk.Revit.ExceptionsArgumentNullException | A non-optional argument was null |