Iterating CADEntities in CADInsert

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
fernandofelix
Posts: 2
Joined: 06 Oct 2010, 03:05

Iterating CADEntities in CADInsert

Post by fernandofelix » 06 Oct 2010, 03:34

Hi support,

I am using your CADImport.NET7 dll trial version to see if it suits our need to purchase it... What we would want to do is to extract all the lines and texts from the drawings so we can do our work. I have read CADLine and CADText with no problem, now I am trying to read more complex entities and convert them to CADLines and CADTexts, for example, CADPolylines, CADLWPolylines, CADMLines, CADMTexts, CADAttrib, CADAttdef (not very sure if this one contains texts) and CADInsert (Block References).

I used a sample drawing with a Block Reference, that inside has two normal texts and two lines... When I iterate the entities inside the block reference, I see the objects but the base points of the lines seems to be wrong, I do not know what I am doing wrong, maybe you could guide me a little bit please.

This is a fragment of the code (I am using C++):

CADImport::CADImage^ dwg = CADImport::CADImage::CreateImageByExtension("path_of_drawing");
dwg->LoadFromFile("path_of_drawing");
IterateEntities(dwg->Converter->Entities);

//Iterate Entities Function:
void IterateEntities(CADImport::CADEntityCollection^ ents)
{
for (int i = 0; i < ents->Count; i++)
{
CADImport::CADEntity^ entSource = ents;
[...] // I take all the "types" that I need, the mentioned above including CADText and CADLine..
else if (entSource->EntType == CADImport::EntityType::Insert)
{
CADImport::CADInsert^ insert = gcnew CADImport::CADInsert();
insert = dynamic_cast<CADImport::CADInsert^>(entSource);
IterateEntities(insert->Block->Entities);
IterateEntities(insert->Entities);
}
[...] // Finish taking all "types"
}
}

1.- Am I opening correctly the drawing? Are those two first functions necessary? (Its my first day using the library)
2.- In the CADInsert fragment, I have to iterate "intert->Block->Entities" and "insert->Entities"... is this correct? Because if I only use one of them, I do not get all the entities inside the Block Reference.
3.- If I get a normal CADLine, the member CADLine::Point and CADLine::Point1 gives me correctly the start point and end point of the line, however, if it comes inside the Block Reference, the points are not correct... BUT, the text that are inside the Block Reference have correctly their Insertion Point... I thought that maybe the "Point" and "Point1" values of the line were according to the Block Reference, so I tried adding the values of "Point" and "Point1" from the Block Reference to the Line, and it gave me better results but still wrong (also, texts do not need this sum).

As I said above, my function "IterateEntities" is handling correctly the CADTexts and CADLines entities, the only problem is when they come inside a Block Reference, can someone help me please, or guide me to a better result

Thanks in advance,
Eng. Fernando Felix

fernandofelix
Posts: 2
Joined: 06 Oct 2010, 03:05

Re: Iterating CADEntities in CADInsert

Post by fernandofelix » 06 Oct 2010, 03:40

Small correction... The Block Reference have two lines and two attributions (CADAttrib... which I can successfully threat them as Texts)... So I am also reading correctly the CADAttribs too,

Thanks,
Eng. Fernando Felix

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

Re: Iterating CADEntities in CADInsert

Post by support » 06 Oct 2010, 14:35

Hello Fernando.
Your code is correct mostly. However, entities within block reference must be handled differently. The coordinates of Point property of an entity within block have values in "block system". The null point of block coordinates can be found on drawing in CADInsert->Point after deduction of CADBlock->Offset values. For example, if block's offest point is null then block coordinates start coincide with CADInsert->Point. To recount block coordinates of entity into drawing coordinates you need summarize CADInsert->Point and CADBlock->Entities->Point and subtract CADBlock->Offset.

If you won't receive correct coordinates for all entities using this method the please post to the forum or send us such file and we will give more detailed answer.

You don't need iterate the CADInsert->Entities collection, it's empty. All insert's entities placed in CADInsert->Block->Entities collection.

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

Post Reply