Sergey,
Sorry, I have one more confusion in understanding of accessing entities inside the collection of block.
As I understand, I can assign any string key to the entity in order to access it directly without looping through the entire collection.
However, when I check AllKeys property of my block, I don't see my keys there. Instead, there are long numbers (as I understand from your examples they are string representations of the Handle property, the purpose of which is also not very clear to me...).
Can you clarify this to me, please? How can I get desired entity from the collection by key?
Elena
Accessing entities by key
Moderators: SDS, support, admin
Re: Accessing entities by key
Hello Elena,
What code do you use to manage with Keys?
Sergey.
What code do you use to manage with Keys?
Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
-
- Posts: 19
- Joined: 03 Dec 2008, 20:04
Re: Accessing entities by key
I use
block.Entities[key]=entity;
But the problem seems to be resolved. I didn't change the key from your example in all my functions.
block.Entities[key]=entity;
But the problem seems to be resolved. I didn't change the key from your example in all my functions.
-
- Posts: 19
- Joined: 03 Dec 2008, 20:04
Re: Accessing entities by key
There is also interesting thing.
For all entities except lines work also the code
For lines work only
For all entities except lines work also the code
Code: Select all
entity.KeyEnt = key;
block.AddEntity(entity);
Code: Select all
block.Entities[key]=key;
Re: Accessing entities by key
Hello Elena,
- this is incorrect usage. It may harm entities collection.
Also here goes an example of getting access to entities by KeyEnt parameter.
Sergey.
Code: Select all
block.Entities[key]=entity;
Also here goes an example of getting access to entities by KeyEnt parameter.
Code: Select all
string FreeLineKey = "";
string InsertKey = "";
string InsertCircleKey = "";
private void btnGetEntKeys_Click(object sender, System.EventArgs e)
{
if(this.cadImage == null)
return;
int entCount = (this.cadImage.Converter.GetSection(CADImport.FaceModule.ConvSection.Entities).Count)
for (int i = 0; i < entCount; i++)
{
CADEntity ent = this.cadImage.Converter.GetSection(CADImport.FaceModule.ConvSection.Entities).Entities[i];
if (ent is CADLine)
{
CADLine entLine = ent as CADLine;
if (FreeLineKey == "")
FreeLineKey = entLine.KeyEnt;
}
if(ent.EntType == CADImport.EntityType.Insert)
{
CADInsert entInsert = ent as CADInsert;
for (int j = 0; j < entInsert.Block.Count; j++)
{
if (entInsert.Block.Entities[j] is CADCircle)
{
CADCircle entCircle = (CADCircle)entInsert.Block.Entities[j];
if (InsertCircleKey == "")
{
InsertKey = entInsert.KeyEnt;
InsertCircleKey = entCircle.KeyEnt;
}
}
}
}
}
}
private void btnGetEntitiesByKeys_Click(object sender, System.EventArgs e)
{
if(this.cadImage == null)
return;
this.cadImage.UseDoubleBuffering = false;
CADEntity ent;
ent = this.cadImage.Converter.Entities[FreeLineKey] as CADEntity;
ent.Color = Color.Red;
CADInsert ins = this.cadImage.Converter.Entities[InsertKey] as CADInsert;
if (ins != null)
{
ent = ins.Block.Entities[InsertCircleKey] as CADEntity;
if (ent != null)
{
ent.Color = Color.Red;
}
}
this.cadPictBox.Invalidate();
}
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support