Hi Jeremy,
Thanks for your suggestion; it would definitely improve the performance this way.
In any case, I don't think that it would affect the behaviour for what concerns the mentioned issue...
I'll try to clarify the data structure I used for the part of code you highlighted:
1. lightTypeName is the list of all the types, which are created previously in the code;
2. typeName is another list, previously created, which has the same number of elements of lightTypeName, and contains all the strings of the names of the types.
The if (lightTypeName == typeName[k]) … statement you highlighted means that, when the statement is true, the plugin
writes the full path in the PhotometricWebFile parameter. The full path is taken from a third list, named fileIesList, which contains
all the full paths of the .ies files and obviously has the same number of elements of the other 2 lists.
In the specific case of the example I posted previously, the list values are the following:
typeName contains:
071451_BLIZ ROUND 40 40W 5000K 0÷10V
079421_MAGICLICK ROUND 25 LED 26W 4000K
079877_MIMIK 50 B TYPE II 39+39W 830 EM90' 0-10V / Main
079877_MIMIK 50 B TYPE II 39+39W 830 EM90' 0-10V / Battery
fileIesList contains:
C:\Plugin\PRODUCT\PIL_071451.IES
C:\Plugin\PRODUCT\PIL_079421.IES
C:\Plugin\PRODUCT\PIL_079877_MainsVoltage.IES
C:\Plugin\PRODUCT\PIL_079877_OnBattery.IES
PLEASE NOTE: In the screenshot uploaded in the previous post, you can see only 2 types instead of 4 because the plugin split
the types between two distinct files, according to the different shape of the Emitting surface (circle and rectangle).
I'll copy below a bigger part of the code, I hope this can help you better understand the data structure.
private void Create_rfa_files()
{
this.doc = application.OpenDocumentFile(get_rfa_template.rfaTemplateFile);
//doc.Save();
if (Get_family_types_in_family() > 0)
{
Reset_window();
return;
}
folderName.Clear();
shapeType.Clear();
destinationFileList.Clear();
foreach (DataGridViewRow item2 in (IEnumerable)this.dgv2.Rows)
{
folderName.Add(item2.Cells[0].Value.ToString());
shapeType.Add(item2.Cells[2].Value.ToString());
}
Create_short_folder_list();
this.int4 = int4 + 1;
this.Progress_bar();
for (int i = 0; i < shortFolderList.Count; i++)
{
this.int4 = int4 + 1;
this.Progress_bar();
this.doc = application.OpenDocumentFile(get_rfa_template.rfaTemplateFile);
//doc.Save();
//foreach (FileInfo fileInfo in new DirectoryInfo(get_rfa_template.rfaTemplatePath).GetFiles("*.00*.rfa"))
//{
// fileInfo.Delete();
//}
Get_family_types_in_family();
FamilyManager familyManager = this.doc.FamilyManager;
FamilyTypeSet famTypes = familyManager.Types;
Transaction transaction = new Transaction(doc);
//Add_existing_family_param_names();
transaction.Start("Add Type to Family");
LightFamily lightFamily = LightFamily.GetLightFamily(doc);
for (int j = 0; j < folderName.Count; j++)
{
this.int4 = int4 + 1;
this.Progress_bar();
if (shortFolderList[i] == folderName[j] && shortShapeList[i] == shapeType[j])
{
if (familyManager.CurrentType.Name != typeName[j])
{
familyManager.NewType(typeName[j]);
if (dgv2.Rows[j].Cells[2].Value.ToString() == "Circle")
{
lightFamily.SetLightShapeStyle(LightShapeStyle.Circle);
FamilyParameter familyParam = familyManager.get_Parameter("Emit from Circle Diameter");
familyManager.Set(familyParam, (circleDiameter[j] / _feet_to_mm) * (-1000));
}
if (dgv2.Rows[j].Cells[2].Value.ToString() == "Rectangle")
{
lightFamily.SetLightShapeStyle(LightShapeStyle.Rectangle);
FamilyParameter familyParam = familyManager.get_Parameter("Emit from Rectangle Length");
familyManager.Set(familyParam, (rectangleLength[j] / _feet_to_mm) * 1000);
familyParam = familyManager.get_Parameter("Emit from Rectangle Width");
familyManager.Set(familyParam, (rectangleWidth[j] / _feet_to_mm) * 1000);
}
{
FamilyParameter familyParam = familyManager.get_Parameter("Lamp");
familyManager.Set(familyParam, sourceType[j]);
}
{
FamilyParameter familyParam = familyManager.get_Parameter("Emit Shape Visible in Rendering");
if (Convert.ToBoolean(dgv2.Rows[j].Cells[3].Value))
{
familyManager.Set(familyParam, 1);
}
else
{
familyManager.Set(familyParam, 0);
}
}
{
//FamilyParameter familyParam = familyManager.get_Parameter("Photometric Web File");
//familyManager.Set(familyParam, fileIesList[j]);
}
}
}
}
for (int index = 0; index < lightFamily.GetNumberOfLightTypes(); index++)
{
LightType lightData = lightFamily.GetLightType(index);
string lightTypeName = lightFamily.GetLightTypeName(index);
for (int k = 0; k < fileIesList.Count; k++)
{
if (lightTypeName == typeName[k])
{
lightFamily.SetLightDistributionStyle(LightDistributionStyle.PhotometricWeb);
PhotometricWebLightDistribution lightDistribution = lightData.GetLightDistribution() as PhotometricWebLightDistribution;
lightDistribution.PhotometricWebFile = fileIesList[k];
//lightDistribution.TiltAngle = Math.PI / 6; // use radian value to set
lightData.SetLightDistribution(lightDistribution); // set back
InitialColor initColor = lightData.GetInitialColor();
CustomInitialColor customInitialColor = initColor as CustomInitialColor;
double colorTemperature = customInitialColor.Temperature;
customInitialColor.Temperature = Convert.ToDouble(initialColor[k]);
lightData.SetInitialColor(customInitialColor);
if (wattage[k] == 0)
{
wattage[k] = 1;
}
double efficacy = luminousFlux[k] / wattage[k];
lightData.SetInitialIntensity(new InitialWattageIntensity(efficacy, wattage[k]));
lightData.SetInitialIntensity(new InitialFluxIntensity(luminousFlux[k]));
}
}
}
familyManager.Dispose();
transaction.Commit();
//ModifyLightDistributionStyle(doc,i);
string fileName = "";
if (shortShapeList[i] == "Circle")
{
fileName = shortFolderList[i] + "_Photometrics_C";
}
if (shortShapeList[i] == "Rectangle")
{
fileName = shortFolderList[i] + "_Photometrics_R";
}
string destinationFile = select_destination_folder.destinationFolderName + "\\N1_" + fileName + ".rfa";
if (File.Exists(destinationFile))
{
File.Delete(destinationFile);
}
doc.SaveAs(destinationFile);
destinationFileList.Add(destinationFile);
if (transaction != null)
{
((IDisposable)transaction).Dispose();
}
}
Hope this can clarify… If necessary I'll give further explanation.
Thanks a lot.