Iterate light objects in cpp

I would like to export information about all the lights in my model. This is where I have gotten so far, am I on the right track? How do I get the individual lights?

CRhinoLightTable& light_table = doc.m_light_table;
if (light_table.LightCount() > 0)
{
	for(int light_index = 0; light_index < doc.m_light_table.LightCount(); light_index++)
	{
		const CRhinoLight aLight = ???;
	}
}

Hi Mary,

Try this:

CRhinoCommand::result CCommandTestMary::RunCommand(const CRhinoCommandContext& context)
{
  const CRhinoLightTable& light_table = context.m_doc.m_light_table;
  for (int i = 0; i < light_table.LightCount(); i++)
  {
    const CRhinoLight& light_obj = light_table[i];
    if (light_obj.IsDeleted())
      continue;

    const ON_Light& light = light_obj.Light();

    if (light.IsPointLight())
    {
      // todo...
    }
    else if (light.IsDirectionalLight())
    {
      // todo...
    }
    else if (light.IsSpotLight())
    {
      // todo...
    }
    else if (light.IsLinearLight())
    {
      // todo...
    }
    else if (light.IsLinearLight())
    {
      // todo...
    }
    else // unknown
    {
      // todo...
    }
  }

  return CRhinoCommand::success;
}

– Dale

1 Like

That looks great! Thank you!