Page 1 of 1
Create a Polymesh
Posted: 18 Feb 2018, 18:28
by FieldConsult
The library can read dwg files that contain Polymesh, the relevant question is, is it possible to create Polymesh objects using code? IF the answer is affirmative, you could show a simple code on how to do it.
Thank you.
Re: Create a Polymesh
Posted: 19 Feb 2018, 21:45
by support
Hello,
CAD VCL allows to create Polyface Mesh objects from code. A polyface mesh is represented in DWG/DXF files as a variant of a polyline entity, so you should use a
TsgDXFPolyline class for creating a polymesh.
The code example below shows how to create a polyface mesh using the
TsgDXFPolyline and
TsgDXFVertex classes.
Code: Select all
uses
..., CADImage, DXFConv, sgConsts;
implementation
{$R *.dfm}
procedure AddEntityToImage(ATargetImage: TsgCADImage; AEntity: TsgDXFEntity);
begin
if not Assigned(ATargetImage) then Exit;
ATargetImage.CurrentLayout.AddEntity(AEntity);
if Assigned(ATargetImage.Converter.OnCreate) then
ATargetImage.Converter.OnCreate(AEntity);
ATargetImage.Converter.Loads(AEntity);
ATargetImage.GetExtents;
end;
procedure Add3DVertex(ADXFPolyline: TsgDXFPolyline; const AX, AY, AZ: TsgFloat);
var
vDXFVertex: TsgDXFVertex;
begin
vDXFVertex := TsgDXFVertex.Create;
vDXFVertex.Point := MakeFPoint(AX, AY, AZ);
ADXFPolyline.AddEntity(vDXFVertex);
end;
procedure AddPolyfaceByVertices(ADXFPolyline: TsgDXFPolyline; const I1, I2, I3, I4: Integer);
var
vDXFVertex: TsgDXFVertex;
begin
vDXFVertex := TsgDXFVertex.Create;
vDXFVertex.Flags := 128; // Polyface mesh vertex
vDXFVertex.PolyFaceVertexIndex1 := I1;
vDXFVertex.PolyFaceVertexIndex2 := I2;
vDXFVertex.PolyFaceVertexIndex3 := I3;
vDXFVertex.PolyFaceVertexIndex4 := I4;
ADXFPolyline.AddEntity(vDXFVertex);
end;
procedure CreatePolyfaceMesh(ATargetImage: TsgCADImage);
var
vDXFPolyline: TsgDXFPolyline;
begin
vDXFPolyline := TsgDXFPolyline.Create;
vDXFPolyline.Flags := 64; // The polyline is a polyface mesh
vDXFPolyline.MeshM := 10; // The number of vertices
vDXFPolyline.MeshN := 3; // The number of polyfaces
// Add 10 vertices
Add3DVertex(vDXFPolyline, 157, 177, 0);
Add3DVertex(vDXFPolyline, 190, 196, 0);
Add3DVertex(vDXFPolyline, 223, 176, 0);
Add3DVertex(vDXFPolyline, 209, 203, 0);
Add3DVertex(vDXFPolyline, 234, 218, 0);
Add3DVertex(vDXFPolyline, 201, 218, 0);
Add3DVertex(vDXFPolyline, 190, 244, 0);
Add3DVertex(vDXFPolyline, 179, 219, 0);
Add3DVertex(vDXFPolyline, 148, 219, 0);
Add3DVertex(vDXFPolyline, 172, 204, 0);
// Add 3 triangular polyfaces
AddPolyfaceByVertices(vDXFPolyline, 1, 5, 8, 0);
AddPolyfaceByVertices(vDXFPolyline, 3, 7, 10, 0);
AddPolyfaceByVertices(vDXFPolyline, 9, 8, 10, 0);
// Set a color for the polyface mesh
vDXFPolyline.Color := clRed;
AddEntityToImage(ATargetImage, vDXFPolyline);
end;
Mikhail
Re: Create a Polymesh
Posted: 19 Feb 2018, 22:57
by FieldConsult
Tanks!!! Perfect.
Another thing, when you are ready with version 13?
Felipe
Re: Create a Polymesh
Posted: 20 Feb 2018, 16:03
by support
Felipe,
The next major version is currently at the testing stage, so for now we cannot give you any information about the release date.
Mikhail