I’m using Aspose.CAD for .NET (C#) and I’m generating a DwgImage completely from scratch.
I’ve successfully created a CadLwPolyline using 2D coordinates, but now I need to represent actual 3D data — meaning coordinates that include Z-values. For that purpose, I assume I need to use CadPolyline, but I couldn’t find a clear example or explanation in the documentation.
Question:
Could you please clarify if it’s possible to properly create a CadPolyline with full 3D coordinates (X, Y, and Z), and what the recommended way is to achieve this in a newly created DwgImage?
Could you please provide more details about the specific method or properties you are using to create the CadPolyline with 3D coordinates in Aspose.CAD for .NET?
I’m currently using a custom method called CreateCadLwPolyline to create CadLwPolyline objects using 2D points that I extract from 3D data (by dropping the Z-coordinate).
Here’s a simplified version of the method:
internal CadLwPolyline? CreateCadLwPolyline(Feature feature, CadImage templImage)
{
var points = Create2DPointsFrom3DData(feature);
if (points.Count < 2) return null;
var cadPolyline = new CadLwPolyline
{
Coordinates = points,
Flag = CadLwPolylineFlag.None,
PointCount = points.Count,
LayerName = feature.SymbolName,
IsByLayer = true,
};
return cadPolyline;
}
This works well for 2D representation, but since I now want to include real 3D coordinates (with Z values), I’d like to switch from CadLwPolyline to CadPolyline.
My question is: how can I properly build a CadPolyline with 3D vertices in a new DwgImage, and what is the recommended way to associate the 3D points with the polyline object?
@Abne,
Hello,
please, test if this example is useful:
var dwgImage = new DwgImage();
var cadPolyline3D = new CadPolyline3D()
{
ObjectHandle = NextAvailableHandle(dwgImage),
Flag = CadPolylineFlag.POLY_3D
};
var points = new List<Cad3DPoint>()
{
new Cad3DPoint(00, 0, 10),
new Cad3DPoint(40, 40, 50),
new Cad3DPoint(80, 80, -10)
};
foreach (var point in points)
{
var vertex = new Cad3DVertex()
{
ObjectHandle = NextAvailableHandle(dwgImage),
SoftOwner = cadPolyline3D.ObjectHandle,
XDirMissingFlag = true,
LocationPoint = point,
};
cadPolyline3D.ChildObjects.Add(vertex);
}
var seqend = new CadSeqend()
{
ObjectHandle = NextAvailableHandle(dwgImage),
SoftOwner = cadPolyline3D.ObjectHandle,
XDirMissingFlag = true,
};
cadPolyline3D.ChildObjects.Add(seqend);
dwgImage.AddEntity(cadPolyline3D);
dwgImage.Save("3dpolyline.dwg");
Yes, the code is working well. Thank you!
So far, I’m able to create layers, blocks, and polygons. I still need to check if I can copy blocks from one DWG file to a new one.
Thanks again for your help — if I run into any issues, I’ll let you know.
1 Like
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.