RVTDocs.com

LightType.GetLightTypeFromInstance

Method
Description:
Creates a light type object from the given document and element ID
Syntax
public static LightType GetLightTypeFromInstance(
	Document document,
	ElementId instanceId
)
Examples
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);
}
Parameters
Parameter Type Description
document Document The document the instanceId is from
instanceId ElementId The ID of the light fixture instance
Return Value
Type Description
LightType The newly created LightType object
Exceptions
Exception Condition
ArgumentException The ElementId is the argument that is being validated The ElementId is not valid because it is not for a light element.
ArgumentNullException A non-optional argument was null