How do I get blocks name?

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
dlwotj4274
Posts: 13
Joined: 19 Jun 2019, 07:30

How do I get blocks name?

Post by dlwotj4274 » 19 Jun 2019, 08:06

How do I know whether blocks are exist or not. also I would like to know how to get their name.

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

Re: How do I get blocks name?

Post by support » 19 Jun 2019, 18:20

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
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

dlwotj4274
Posts: 13
Joined: 19 Jun 2019, 07:30

Re: How do I get blocks name?

Post by dlwotj4274 » 20 Jun 2019, 03:18

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.

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

Re: How do I get blocks name?

Post by support » 20 Jun 2019, 18:28

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
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

dlwotj4274
Posts: 13
Joined: 19 Jun 2019, 07:30

Re: How do I get blocks name?

Post by dlwotj4274 » 21 Jun 2019, 05:55

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

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

Re: How do I get blocks name?

Post by support » 21 Jun 2019, 20:30

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
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply