How to fetch the data of the BlockReference in Aspose.cad for dotnet of a dwg file.
To fetch the data of a BlockReference in a DWG file using Aspose.CAD for .NET, you can utilize the CadImage
class to load the DWG file and access the block entities. Below is a code example demonstrating how to retrieve the external reference of a block attribute:
using System;
using Aspose.CAD;
namespace Aspose.CAD.Examples.CSharp.DWG_Drawings
{
public class GetBlockAttributeValue
{
public static void Run()
{
// Specify the path to the DWG file
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string sourceFilePath = MyDir + "sample.dwg";
// Load the DWG file as a CadImage
using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath))
{
// Access the block entities and retrieve the external reference
Console.WriteLine(cadImage.BlockEntities["*MODEL_SPACE"].XRefPathName);
}
}
}
}
In this example, replace "sample.dwg"
with the path to your DWG file. The XRefPathName
property is used to get the external reference of the block attribute from the BlockEntities
collection of the CadImage
object. This allows you to access the data associated with the BlockReference effectively.
For more detailed information, you can refer to the official documentation on getting block attribute values and check the complete code example available on GitHub here.
Feel free to ask if you have any further questions!
How can i fetch the text, lines, ellipses, etc. entities in the BlockReference ?
@Asheesh32,
Hi,
please test if this is useful:
foreach (CadEntityBase baseEntity in cadImage.Entities)
{
if (baseEntity.TypeName == CadEntityTypeName.INSERT)
{
CadInsertObject insert = (CadInsertObject)baseEntity;
CadBlockEntity block = cadImage.BlockEntities[insert.Name];
foreach (CadEntityBase blockEntity in block.Entities)
{
if (blockEntity.TypeName == CadEntityTypeName.MTEXT)
{ ... }
if (blockEntity.TypeName == CadEntityTypeName.LINE)
{ ... }
// other entities
}
}
}