RenderLight iterator does not work?

I’ve done my due diligence before posting this question. For the life of me I cannot get an iterator to work for render lights. I am using the simple code below. Might I be missing something? The light, in question, does show up in a scene Dump(). I am attaching a Rhino v3 test file as an example.

--------------------------my_spot_light.3dm (2.4 KB)

ONX_ModelComponentIterator light_it( model, ON_ModelComponent::Type::RenderLight );

// const ON_ModelComponent* model_component = nullptr;
// model_component = light_it.FirstComponent(); 
// const ON_ModelGeometryComponent* model_geometry = ON_ModelGeometryComponent::Cast(model_component);
// const ON_Light *light2 = ON_Light::Cast(light_it.FirstComponent());	

for (const ON_Light *light = ON_Light::Cast(light_it.FirstComponent()); nullptr != light; light = ON_Light::Cast(light_it.NextComponent()) ) {
	ON_String light_name = "Light";

	const ON_ModelGeometryComponent* model_geometry = ON_ModelGeometryComponent::Cast(light);
	if (model_geometry) { 
		const ON_3dmObjectAttributes *m_attributes = model_geometry->Attributes(nullptr);
		if (m_attributes)
			light_name = m_attributes->Name();              	
	}

Hi @RCL,

Let me know if this helps.

ON_TextLog text_log;
ONX_ModelComponentIterator it(model, ON_ModelComponent::Type::RenderLight);
const ON_ModelComponent* model_component = nullptr;
for (model_component = it.FirstComponent(); nullptr != model_component; model_component = it.NextComponent())
{
  const ON_ModelGeometryComponent* model_geometry = ON_ModelGeometryComponent::Cast(model_component);
  if (nullptr != model_geometry)
  {
    const ON_Light* light = ON_Light::Cast(model_geometry->Geometry(nullptr));
    if (nullptr != light)
    {
      text_log.Print("Got light!\n");
    }
  }
}

– Dale

Thanks Dale for the amended iterator. It makes a lot more to cast to the light off the geometry node. This does work, as expected.