Page 1 of 1

How do I get blocks name?

Posted: 19 Jun 2019, 08:06
by dlwotj4274
How do I know whether blocks are exist or not. also I would like to know how to get their name.

Re: How do I get blocks name?

Posted: 19 Jun 2019, 18:20
by support
Hello,

You can check whether a block exists or not by a given block name. For example:

Code: Select all

CADBlock block = cadImage.Converter.BlockByName("Block1");
If a block with the given name doesn't exist, the BlockByName method returns null. The block name can be read through a CADBlock.Name property.

Mikhail

Re: How do I get blocks name?

Posted: 20 Jun 2019, 03:18
by dlwotj4274
Thanks for your reply.

Could I ask another question?

Image

It is our drawing template as block

we would like to get a data from certain location of text from this blocks origin.

Is it possible to implement this sequence?

1. Find the most largest block(template in drawing) in dwg and get a location(origin)

or select block(template) manually

2. Get a text data from offset(from block's origin). We would like to parse the text data to distinguish what it is.

Re: How do I get blocks name?

Posted: 20 Jun 2019, 18:28
by support
Hello,

It is possible to find the largest block by its bounding rectangle (CADBlock.Box) and read the text data from the CADBlock through a CADBlock.Entities collection. For example:

Code: Select all

public static List<string> GetTextDataFromBlock(CADBlock block)
{
    List<string> textData = new List<string>();
    List<CADEntity> cadTexts = block.Entities.FindAll(ent => ent.EntType == EntityType.Text);
    cadTexts.ForEach(entity => textData.Add((entity as CADText).Text));
    return textData;
}
Mikhail

Re: How do I get blocks name?

Posted: 21 Jun 2019, 05:55
by dlwotj4274
Thanks for your support.

Sorry to bothering you.

Could you give me any example how to use this function?

You gave me how to find texts of block. However I'm hard to find a way to use this function.

Input parameter is the CADBlock block. Then

Should I get a handle of blocks?

For example, There is a block "A". I want to know that texts in this block by this function.

I don't know how to use "A"block as input parameter in this function.

Thanks

Jaeseo

Re: How do I get blocks name?

Posted: 21 Jun 2019, 20:30
by support
Hello Jaeseo,

You are welcome.

CAD .NET allows to find a CADBlock object in a given CAD image by a given block name (see my first reply), so you can rewrite the GetTextDataFromBlock method as follows:

Code: Select all

public static List<string> GetTextDataFromBlock(CADImage cadImage, string blockName)
{
    List<string> textData = new List<string>();
    CADBlock block = cadImage.Converter.BlockByName(blockName);
    if (block != null)
    {
        List<CADEntity> cadTexts = block.Entities.FindAll(ent => ent.EntType == EntityType.Text);
        cadTexts.ForEach(entity => textData.Add((entity as CADText).Text));
    }
    return textData;
}
Mikhail