Hello,
I am using Aspose.CAD .net api to create dwg and insert mtext acc. to Work with text|CAD Documentation
here is my code
[HttpPost("createDwgByAspose2")]
public async void CreateDwgByAspose2Async()
{
DwgImage dwgImage = new DwgImage();
CadMText mText = new CadMText();
mText.Text = "Watermark message";
mText.InitialTextHeight = 40;
mText.InsertionPoint = new Cad3DPoint(300, 40, 0);
mText.LayerName = "0";
//mText.DrawingDirection = Aspose.CAD.FileFormats.Cad.CadConsts.CadDrawingDirection.LeftToRight;
//mText.ExtrusionDirection = new Cad3DPoint(0, 0, 1);
dwgImage.AddEntity(mText);
dwgImage.UpdateSize();
var folderPath = @"C:\Users\xj2ssf\Desktop\Aspose_test";
var fileName = $"test_{DateTime.Now:yyyyMMddHHmmssffff}.dwg";
dwgImage.Save(Path.Combine(folderPath, fileName));
}
But the created dwg file is not correct for the mtext, and I have attached the result dwg file.
Please take a look, the mtext did created but cannot show correctly.
My aspose.cad version is 24.4.0
test_202505080905087332.zip (21.8 KB)
@msdos41
It seems that you are encountering issues with the display of the MText in the DWG file created using the Aspose.CAD .NET API. Based on the code you provided, it looks like you are correctly setting up the MText entity, but there may be some additional considerations to ensure it displays correctly.
Here are a few suggestions to troubleshoot and potentially resolve the issue:
-
Layer Visibility: Ensure that the layer you are adding the MText to (in your case, “0”) is visible in the DWG viewer you are using. Sometimes, layers can be turned off or set to not display.
-
Text Height and Insertion Point: Verify that the InitialTextHeight
and InsertionPoint
values are appropriate for your drawing. If the insertion point is too far from the visible area of the drawing, the text may not appear. You might want to adjust these values to see if the MText becomes visible.
-
Using Model Space: Make sure you are adding the MText to the correct block entity. In many cases, entities should be added to the “*Model_Space” block. You can check if your code is correctly targeting this block.
-
Example Reference: You can refer to a similar example from the Aspose.CAD documentation, which demonstrates how to add MText to a DWG file. The example initializes the MText with similar properties and adds it to the model space, which might help you identify any discrepancies in your implementation.
Here is a simplified version of how you might structure your code based on the example:
using Aspose.CAD.FileFormats.Cad;
using Aspose.CAD.FileFormats.Cad.CadObjects;
// Create a new DWG image
DwgImage dwgImage = new DwgImage();
// Create MText entity
CadMText mText = new CadMText();
mText.Text = "Watermark message";
mText.InitialTextHeight = 40;
mText.InsertionPoint = new Cad3DPoint(300, 40, 0);
mText.LayerName = "0";
// Add MText to the model space
dwgImage.BlockEntities["*Model_Space"].AddEntity(mText);
// Save the DWG file
dwgImage.Save("path_to_your_file.dwg");
Make sure to replace "path_to_your_file.dwg"
with the actual path where you want to save the DWG file.
If you continue to experience issues, consider checking the viewer settings or trying a different viewer to ensure that the problem is not related to the software you are using to view the DWG file.
If you have any further questions or need additional assistance, feel free to ask!
@msdos41,
Hi,
thank you for the details, we have created CADNET-10135 to investigate this problem.
@msdos41
Hi,
DirectionVector and ExtrusionDirection properties should be set up, please, test if this is helpful:
DwgImage dwgImage = new DwgImage();
CadMText mText = new CadMText();
mText.Text = "Watermark message";
mText.InitialTextHeight = 40;
mText.InsertionPoint = new Cad3DPoint(300, 40, 0);
mText.LayerName = "0";
var rotationInDegree = 45;
var rotationInRadian = rotationInDegree * Math.PI / 180;
var directionVector = new Cad3DPoint(Math.Cos(rotationInRadian), Math.Sin(rotationInRadian), 0);
mText.DirectionVector = directionVector;
mText.ExtrusionDirection = new Cad3DPoint(0, 0, 1);
dwgImage.AddEntity(mText);
dwgImage.UpdateSize();
dwgImage.Save("mtext.dwg");
@msdos41,
we are happy to help 