Change TsgDXFText.Text and save to DXF/DWG

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

Moderators: admin, support, SDS

Post Reply
bwilms
Posts: 2
Joined: 15 Feb 2011, 13:49

Change TsgDXFText.Text and save to DXF/DWG

Post by bwilms » 13 Mar 2018, 16:57

Hi,

I have existing DWG/DXF-Files with thousands of sgDXFText-Entities, that Need to be renamed and save a copy of the original DXF/DWG.

I use Converter.Iterate to find all sgDXFText-Entities in all layers.

When finding a valid sgDXFText I do following:

TsgDXFText(Entity).Text:= 'NEWTEXT';
TsgCADImage(DNavigator.Picture.Graphic).Converter.Loads(Entity);
After refreshing the drawing, the new text will be shown and when I save it as SWF, SVG
etc. the changes are also visible.

But when I do an Export to DWG, DXF no changes are visible and it Looks like a 1:1 copy of the original DXF/DWG.

What did I missed?

Greets,

Benjamin

support
Posts: 2930
Joined: 30 Mar 2005, 11:36
Contact:

Re: Change TsgDXFText.Text and save to DXF/DWG

Post by support » 13 Mar 2018, 18:28

Hello Benjamin,

Please post the code which exports the drawing to DWG and DXF, so that we could find what is going wrong.


Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

bwilms
Posts: 2
Joined: 15 Feb 2011, 13:49

Re: Change TsgDXFText.Text and save to DXF/DWG

Post by bwilms » 14 Mar 2018, 10:09

This part is for loading the existing Dxf. CADImage

Code: Select all

procedure TfmMain.Load1Click(Sender: TObject);
begin
  DNavigator.LoadFromFile('c:\temp\Input.dxf';
end;
CADImage is a property, resulting DNavigator.Picture.Graphic as TsgCadImage...

This part is for iterating through all entities.

Code: Select all

procedure TfmMain.Translate1Click(Sender: TObject);
begin
  FCADParams.Matrix := cnstIdentityMat;
  CadImage.Converter.AutoInsert := True; // to get all the elements inside of inserts
  CadImage.Converter.Iterate(ReadCADEntities, nil, FCADParams);
end;
This is the part for adjusting all TsgDXFText-Entities. Later I will only change text from entities on specific layers and with matching texts.

Code: Select all

function TfmMain.ReadCADEntities(Entity: TsgDXFEntity): Integer;
begin
  Result := 0;
  if Entity is TsgDXFText then
  begin
      TsgDXFText(Entity).Text:= 'NEW_TEXT_'+TsgDXFText(Entity).Text;
      CadImage.Converter.Loads(Entity);
  end;
end;
This part is responsible for saving.

Code: Select all

procedure TfmMain.Save1Click(Sender: TObject);
var
  vExpCADfile : TsgCADtoDXF;
begin
    vExpCADfile := TsgCADtoDXF.Create(CadImage);
    vExpCADfile.Version := acR2010; //Tried different versions already
    vExpCADfile.SaveToFile('C:\temp\Output.dxf');
    vExpCADfile.Free;
end;

support
Posts: 2930
Joined: 30 Mar 2005, 11:36
Contact:

Re: Change TsgDXFText.Text and save to DXF/DWG

Post by support » 14 Mar 2018, 19:28

Hello Benjamin,

Thank you for the code.

It appears that your DXF/DWG files contain MTEXT (multiline text) entities which are splitted into TsgDXFText objects when a TsgCADImage.Converter.AutoInsert property is set to True. To verify it, change the line

Code: Select all

CadImage.Converter.AutoInsert := True;
to

Code: Select all

CadImage.Converter.AutoInsert := False;
and then check if the 'NEW_TEXT_' appendix is shown for all texts after clicking the Translate1 button and refreshing the drawing in DNavigator. In this case the appendix will be added only to TEXT entities in the input drawing, while MTEXT entities won't be changed.


Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

benjamin.wilms
Posts: 2
Joined: 17 Apr 2018, 12:25

Re: Change TsgDXFText.Text and save to DXF/DWG

Post by benjamin.wilms » 17 Apr 2018, 12:29

Hi Mikhail,

thx for the answer. Yes, it seems to be auto-inserted from blocks/mtext inside the cad-drwaing. Any chance to export the resulting DXF resulted after auto-insert and my changes to the TEXT-entities are done?

If not, how can I acces/change the attributes of an entity?

Greets,

Benjamin

support
Posts: 2930
Joined: 30 Mar 2005, 11:36
Contact:

Re: Change TsgDXFText.Text and save to DXF/DWG

Post by support » 17 Apr 2018, 18:48

Hello Benjamin,

The TEXT objects extracted from MTEXTs using a TsgDXFConverter.Iterate method cannot be saved directly to DXF. You will have to create a new TsgDXFText instance for each extracted TEXT, copy the TEXT properties to this instance using AssignEntity method, calculate the absolute coordinates for the text insertion point and then add it to the CADImage. After that you should delete the input MTEXTs from the CADImage.


Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

benjamin.wilms
Posts: 2
Joined: 17 Apr 2018, 12:25

Re: Change TsgDXFText.Text and save to DXF/DWG

Post by benjamin.wilms » 18 Apr 2018, 12:37

Thx a lot for the answer.

Is there any way to get the mtext-object, that is responsible for the auto-inserted text-object?
Any kind of parent/reference-information?

Greets,

Benjamin

support
Posts: 2930
Joined: 30 Mar 2005, 11:36
Contact:

Re: Change TsgDXFText.Text and save to DXF/DWG

Post by support » 18 Apr 2018, 18:29

Hello Benjamin,

You can determine the MTEXT object from which a certain TsgDXFText was extracted through a TsgCADIterate.Insert field. Please have a look at the code example below.

Code: Select all

FCADParams: TsgCADIterate;

...

function TfmMain.ReadCADEntities(Entity: TsgDXFEntity): Integer;
var
  vDXFMText: TsgDXFMText;
begin
  Result := 0;
  if Entity is TsgDXFText then
  begin
    if Assigned(FCADParams.Insert) and (FCADParams.Insert.EntType = ceMText) then
      vDXFMText := FCADParams.Insert as TsgDXFMText;
    ...

  end;
end;
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply