Adding Linear Dimensions to Wall Lines or Polylines in a DXF File Using Aspose.CAD

Dear Aspose.CAD Support Team,

I am working on a project where I need to programmatically add linear dimensions for all walls in a DXF file When export to PDF . These walls are represented as either lines or polylines, but the original DXF file does not include any dimensions.

Here’s what I need to accomplish:

  1. Detect Wall Entities: Identify all wall-like entities in the DXF file, which could be simple lines or polylines in the drawing.
  2. Calculate Dimensions: For each line or polyline, calculate the distance (length) between the start and end points.
  3. Add Linear Dimensions: Programmatically insert linear dimensions referencing the detected entities (lines/polylines). The dimensions should include:
  • Extension lines starting from the endpoints of the entity.
  • A dimension line with the calculated length displayed as text.
  1. Save the Updated DXF: Save the modified DXF file with the added dimensions.

Questions:

  1. Entity Detection:
  • How can I efficiently identify lines and polylines in the DXF model space using Aspose.CAD?
  1. Adding Linear Dimensions:
  • Which Aspose.CAD API methods or classes should I use to create and configure a DxfLinearDimension object?
  • How do I ensure that the extension lines, dimension line, and dimension text are properly positioned relative to the detected entity?
  1. Dimension Properties:
  • Can I customize the dimension text, text height, and offset? If so, what properties should I use?
  • How can I set the layer or style of the dimension to ensure it aligns with the existing drawing style?
  1. Polyline Handling:
  • For polylines representing walls (with multiple segments), is there a way to add a linear dimension for each segment individually?

Your guidance on this would be greatly appreciated. If possible, please provide sample code or API references to help me implement this functionality In java. I have added sample Screen shot for missing Dimensions.
Screenshot 2025-01-02 162820.png (15.5 KB)

Screenshot 2025-01-05 161734.png (48.8 KB)

@johnhedo,
Hello.

1.You can iterate all entities available in the drawing and analyze them, the example is below. You can investigate the properties of entities and desire which ones are useful for your case, e.g., coordinates of the lines/polylines, layer name, color, or use the relation between entities etc.


CadImage cadImage = (CadImage)Image.load(inputFile);

for (CadEntityBase cadEntityBase : cadImage.getEntities())
{
	if (cadEntityBase.getTypeName() == CadEntityTypeName.LINE)
	{
		CadLine line = (CadLine)cadEntityBase;
		
		// analysis of the line
	}

	if (cadEntityBase.getTypeName() == CadEntityTypeName.LWPOLYLINE)
	{
		CadLwPolyline lwpolyline = (CadLwPolyline)cadEntityBase;

		// analysis of lwpolyline
	}
	
	if (cadEntityBase.getTypeName() == CadEntityTypeName.POLYLINE)
	{
		CadPolyline lwpolyline = (CadPolyline)cadEntityBase;

		// analysis of polyline
	}
}
		

Please note that only 100 entities are possible to see in Entities collection if there is no license applied, you need at least free temporarily license to get access to the entire collection.

2 and 3. Working with dimensions is complex, because they store their structure inside a file in a special way, so adding new dimensions as well as using some its features is problematic.

Here is basic example how to add new dimension, but saving it back to DXF will produce invalid file. Export of the drawing with new entity to PDF should be easier. Please note that all values are random now, you need to play with them to feel how the required type of dimension is formed.

DxfImage dxfImage = (DxfImage) Image.load(inputFile);

CadAlignedDimension alignedDimension = new CadAlignedDimension();
alignedDimension.setInsertionPoint(new Cad3DPoint(0,0,0));
alignedDimension.setDefinitionPoint1(new Cad3DPoint(10,10,0));
alignedDimension.setDefinitionPoint(new Cad3DPoint(20,20,0));
alignedDimension.setDefinitionPoint2(new Cad3DPoint(30, 30, 0));
alignedDimension.setMiddleTextLocation(new Cad3DPoint(15, 15, 15));

alignedDimension.setText("Sample text");
alignedDimension.setStyleName("standard");
dxfImage.addEntity(alignedDimension);

4.I believe this is possible because you need to specify definition points for the dimension, and corresponding points are available inside a CadPolyline or CadLine object.

Ok Thanks, i will check with above solution and update here.

1 Like