Page 1 of 1

How to change all colors

Posted: 22 Jun 2006, 20:04
by Izuba
Hello,

I would like to change all the colors of a DWG file to make them "whiter".

But lines that do not use layer color are still in original colors.

Here is what I have done :

Code: Select all

//Get the colors into table "Couleurs"

      <b>For</b> i := 0 <b>to</b> DWG.Converter.Counts[csLayers]-1 <b>do
      begin</b>
        Couleurs[i] := DWG.Converter.layers[i].Color;
      <b>end</b>;

      <b>For</b> i := 0 <b>to</b> DWG.Converter.Counts[csEntities]-1 <b>do
      begin</b>
        Couleurs[i+DWG.Converter.Counts[csLayers]] :=
              EntColor(DWG.Converter.Entities[i],<b>nil</b>);
      <b>end</b>;

//Transform and set the colors

      <b>For</b> i := 0 <b>to</b> DWG.Converter.Counts[cslayers]-1 <b>do
      begin</b>
        Couleur := Couleurs[i];
        Couleur := ColorTransformation(couleur);
        DWG.Converter.layers[i].Color := Couleur;
      <b>end</b>;
      <b>For</b> i := 0 <b>to</b> DWG.Converter.Counts[csEntities]-1 <b>do
      begin</b>
        Couleur := Couleurs[i+DWG.Converter.Counts[cslayers]];
        Couleur := ColorTransformation(couleur);
        DWG.Converter.entities[i].SetColor(Couleur);
      <b>end</b>;
Did I miss something ?

PS : You have done a fantastic job with CADImportVCL !

Posted: 23 Jun 2006, 13:59
by support
Dear Izuba,

Please try the following code. It changes a color of all entities in the file to Blue:

Code: Select all

<b>type</b>
  TForm1 = <b>class</b>(TForm)
    sgImage1: TsgImage;
...
<b>procedure</b> TForm1.CADImportVCLForum274Click(Sender: TObject);
<b>var</b>
  vImg: TsgDWGImage;
  I: Integer;
  vEnt: TsgDXFEntity;
<b>begin
  try</b>
  sgImage1.LoadFromFile('c:\test.dwg');
  sgImage1.Align := alClient;
  <b>except</b>
    ShowMessage('Error');
    Exit;
  <b>end</b>;
  vImg := TsgDWGImage(sgImage1.Picture.Graphic);
  <b>for</b> I := 0 <b>to</b> vImg.Converter.Counts[csEntities] - 1 <b>do
  begin</b>
    vEnt := vImg.Converter.Sections[csEntities].Entities[I];
    vEnt.SetColor(clBlue);
    vImg.Converter.Loads(vEnt);
  <b>end</b>;
<b>end</b>;
Sergey.

please post questions to the forum or write to support@cadsofttools.com

Posted: 23 Jun 2006, 14:20
by Izuba
I have tried your method, most of the lines become blue, but not all of them.

Do you want that I send you my dwg file by email (275 Ko), so you can try ?

Posted: 23 Jun 2006, 14:25
by support
Of course!

Please send it to support@cadsofttools.com

Sergey.

please post questions to the forum or write to support@cadsofttools.com

Posted: 23 Jun 2006, 14:26
by Izuba
Some precisions : I do not use sgImage to display the dwg, I just load a TsgDXFImage and draw as any Tgraphic on my own Timage.
But I do not think this is linked to my problem.

Posted: 23 Jun 2006, 16:25
by support
Hello again,

Please use the following code:

Code: Select all

<b>procedure</b> TForm1.CADImport2741Click(Sender: TObject);
<b>var</b>
  vImg: TsgDWGImage;
  I,J: Integer;
  vEnt: TsgDXFEntity;
  vBlck: TsgDXFBlock;
<b>begin
  try</b>
  sgImage1.LoadFromFile('c:\Test.dwg');
  sgImage1.Align := alClient;
  <b>except</b>
    ShowMessage('Error');
    Exit;
  <b>end</b>;
  vImg := TsgDWGImage(sgImage1.Picture.Graphic);
  <b>for</b> I := 0 <b>to</b> vImg.Converter.Counts[csEntities] - 1 <b>do
  begin</b>
    vEnt := vImg.Converter.Sections[csEntities].Entities[I];
    vEnt.SetColor(clBlue);
    vImg.Converter.Loads(vEnt);
  <b>end</b>;

  <b>for</b> I := 0 <b>to</b> vImg.Converter.Counts[csBlocks] - 1 <b>do
  begin</b>
    vBlck := TsgDXFBlock(vImg.Converter.Sections[csBlocks].Entities[I]);
    <b>for</b> J := 0 <b>to</b> vBlck.Count -1 <b>do
    begin</b>
      vBlck.Entities[J].SetColor(clBlue);
      <b>if</b> vBlck.Entities[J].ClassType = TsgDXFMText <b>then</b>
      <b>begin</b>
        TsgDXFMText(vBlck.Entities[J]).SetColor(clBlue);
        vImg.Converter.Loads(vBlck.Entities[J]);
      <b>end</b>;
    <b>end</b>;
  <b>end</b>;
<b>end</b>;
Sergey.

please post questions to the forum or write to support@cadsofttools.com

Posted: 23 Jun 2006, 18:18
by Izuba
Hello again, thank's for your quick response.
It works perfectly to set the color with all the dwg I have.

But, now I realize that I do not get the real color for all entities that are in blocks.
Sometimes I have $1F FF FF FF instead of the color.

I have tried that:

Code: Select all

      <b>For</b> i := 0 <b>to</b> DWG.Converter.Counts[csblocks]-1 <b>do
      begin</b>
        vBlck := TsgDXFBlock(DWG.Converter.Sections[csBlocks].Entities[i]);
        <b>For</b> j := 0 <b>to</b> vBlck.Count-1 <b>do
        begin</b>
             FormDWG.Couleurs[ii] := <b>vBlck.Entities[J].color</b>;
             <b>if</b> vBlck.Entities[J].ClassType = TsgDXFMText <b>then
             begin</b>
                  FormDWG.Couleurs[ii] :=
                     <b>TsgDXFMText(vBlck.Entities[J]).color</b>;
             <b>end</b>;
             inc(ii);
        <b>end</b>;
      <b>end</b>;
and that

Code: Select all

      <b>For</b> i := 0 <b>to</b> DWG.Converter.Counts[csblocks]-1 <b>do
      begin</b>
        vBlck := TsgDXFBlock(DWG.Converter.Sections[csBlocks].Entities[i]);
        <b>For</b> j := 0 <b>to</b> vBlck.Count-1 <b>do
        begin</b>
             FormDWG.Couleurs[ii] := <b>EntColor(vBlck.Entities[J])</b>;
             <b>if</b> vBlck.Entities[J].ClassType = TsgDXFMText <b>then
             begin</b>
                  FormDWG.Couleurs[ii] := <b>EntColor(
                     TsgDXFMText(vBlck.Entities[J]))</b>;
             <b>end</b>;
             inc(ii);
        <b>end</b>;
      <b>end</b>;

Posted: 23 Jun 2006, 18:41
by Izuba
You can test that with the DWG file that I have sent by email.

Posted: 26 Jun 2006, 14:13
by support
Hello,

Graphic.pas:
clNone = TColor($1FFFFFFF);

sgConsts.pas:
clByLayer = $2FFFFFFF;
clByBlock = $3FFFFFFF;

<b>clNone</b>: entity will be drawn with black color if background color is white and vice versa. Please examine DXFImage.pas on using clNone in CADImportVCL. You can find it in the respective Lib folders of the CADImportVCL package: http://www.cadsofttools.com/download/cadimportvcl.zip
<b>clByLayer</b> - entity's color is specified by Layer color
<b>clByBlock</b> - entity's color is specified by Block color

Sergey.


please post questions to the forum or write to support@cadsofttools.com

Posted: 26 Jun 2006, 16:43
by Izuba
Ok, thank's for all