Create a Polymesh

Discuss and ask questions about CAD VCL (Delphi and C++ Builder).

Moderators: admin, support, SDS

Create a Polymesh

Postby FieldConsult » 18 Feb 2018, 16:28

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.
FieldConsult
 
Posts: 47
Joined: 14 Mar 2015, 20:33

Re: Create a Polymesh

Postby support » 19 Feb 2018, 19:45

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
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
support
 
Posts: 2774
Joined: 30 Mar 2005, 08:36

Re: Create a Polymesh

Postby FieldConsult » 19 Feb 2018, 20:57

Tanks!!! Perfect.

Another thing, when you are ready with version 13?
Felipe
FieldConsult
 
Posts: 47
Joined: 14 Mar 2015, 20:33

Re: Create a Polymesh

Postby support » 20 Feb 2018, 14:03

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
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
support
 
Posts: 2774
Joined: 30 Mar 2005, 08:36


Return to CAD VCL

Who is online

Users browsing this forum: No registered users and 9 guests

cron