Accessing entities by key

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
lolena1888
Posts: 19
Joined: 03 Dec 2008, 20:04

Accessing entities by key

Post by lolena1888 » 11 Dec 2008, 20:55

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

support
Posts: 3254
Joined: 30 Mar 2005, 11:36
Contact:

Re: Accessing entities by key

Post by support » 12 Dec 2008, 11:31

Hello Elena,

What code do you use to manage with Keys?

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

lolena1888
Posts: 19
Joined: 03 Dec 2008, 20:04

Re: Accessing entities by key

Post by lolena1888 » 13 Dec 2008, 16:15

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.

lolena1888
Posts: 19
Joined: 03 Dec 2008, 20:04

Re: Accessing entities by key

Post by lolena1888 » 14 Dec 2008, 19:13

There is also interesting thing.
For all entities except lines work also the code

Code: Select all

entity.KeyEnt = key;
block.AddEntity(entity);
For lines work only

Code: Select all

block.Entities[key]=key;

support
Posts: 3254
Joined: 30 Mar 2005, 11:36
Contact:

Re: Accessing entities by key

Post by support » 22 Dec 2008, 16:55

Hello Elena,

Code: Select all

block.Entities[key]=entity;
- this is incorrect usage. It may harm entities collection.
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();
}
Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply