I'm sorry if a similar question is posted on here. I could not find this answer anywhere, but perhaps I could have if I knew which key words to search.
I am trying to name a variable within a for loop or find an alternative way to solve my problem. Here is an example of what I am trying to do.
for (int i = 0; i < 100; i++)
{
string strName = "ImportedBody" + (i+1).ToString();
IBody strName = model.GetEntity(strName) as IBody;
}
Essentially, my goal is to shorten:
IBody ImportedBody1 = model.GetEntity("ImportedBody1") as IBody;
IBody ImportedBody2 = model.GetEntity("ImportedBody2") as IBody;
IBody ImportedBody3 = model.GetEntity("ImportedBody3") as IBody;
IBody ImportedBody4 = model.GetEntity("ImportedBody4") as IBody;
IBody ImportedBody5 = model.GetEntity("ImportedBody5") as IBody;
IBody ImportedBody6 = model.GetEntity("ImportedBody6") as IBody;
...
IBody ImportedBody100 = model.GetEntity("ImportedBody100") as IBody;
into a for loop or something that makes that quicker to write.
The name could also change if that is a problem. For example:
IBody ImportedBody1a = model.GetEntity("ImportedBody1") as IBody;
IBody ImportedBody2a = model.GetEntity("ImportedBody2") as IBody;
IBody ImportedBody3a = model.GetEntity("ImportedBody3") as IBody;
IBody ImportedBody4a = model.GetEntity("ImportedBody4") as IBody;
IBody ImportedBody5a = model.GetEntity("ImportedBody5") as IBody;
IBody ImportedBody6a = model.GetEntity("ImportedBody6") as IBody;
...
IBody ImportedBody100a = model.GetEntity("ImportedBody100") as IBody;
Here are a few notes on what this program is supposed to do. The program I am writing is interacting with a CAD program. If I import geometry into CAD then I have a list of bodies named "ImportedBody1, ImportedBody2, ImportedBody3, etc.. In order to edit that body within my c# program I have to get that from the CAD program using:
IBody Name = model.GetEntity(StringNameAsLabeledWithinCAD) as IBody;
Now I can do things like change the direction that it is facing:
Name.SetNormalDirection(0, 1, 0);
List<IBody>instead. Why do you think you actually need 100 variables?