Page 1 of 1

Add Attribs to DXFInsert

Posted: 08 Nov 2010, 18:03
by hls
I have a problem to add Attribs to a DXFInsert with the following code:

Code: Select all

function InsertFileAsBlock(const FileName, BlockName:string; Target:TsgDXFConverter; Scale:double; InsPoint:TFPoint):boolean;
var
  InsCADFile:TsgCADImage;
  InsConv:TsgDXFConverter;
  DxfIns:TsgDXFInsert;
  Block:TsgDXFBlock;
  i,j:integer;

  procedure AddAttributes;
  var
    i:integer;
    vAttr:TsgDXFAttdef;
    vAttrib:TsgDXFAttrib;
    vP:TFPoint;
  begin
    for i:=0 to Block.Count-1 do begin
      if Block.Entities[i] is TsgDXFAttdef then begin
        vAttr:=Block.Entities[i] as TsgDXFAttdef;

        vAttrib:=TsgDXFAttrib.Create;
        vAttrib.AssignEntity(vAttr);
        vAttrib.Value:='TESTValue';

        if Assigned(Target.OnCreate) then
          Target.OnCreate(vAttrib);
        Target.Loads(vAttrib);
        
        DXFIns.Attribs.Add(vAttrib);
      end;
    end;
  end;


begin
  Result := false;
  InsCADFile := TsgCADImage.Create;

  try
    InsCADFile := GetCADFile(FileName);
    InsConv := InsCADFile.Converter;

    CopyLineTypes(InsConv, Target);
    CopyLayers(InsConv, Target);

    try
      Block := CreateBlockFromEntities(InsConv, Target, BlockName);
      Block.Flags:=2;

      if Assigned(Target.OnCreate) then
        Target.OnCreate(Block);
      Target.Loads(Block);
      Target.Sections[csBlocks].AddEntity(Block);

      DxfIns := TsgDXFInsert.Create;
      DxfIns.Block := Block;
      DxfIns.Scale := MakeFPoint(Scale, Scale, Scale);
      DxfIns.Point := InsPoint;
      
      AddAttributes;

      if Assigned(Target.OnCreate)then
        Target.OnCreate(DxfIns);
      Target.Loads(DxfIns);

      Target.Sections[csEntities].AddEntity(DxfIns);

      Result := true;

    finally
    end;

  finally
    InsCADFile.Free;
  end;
end;



The block is created by copying all entities from an external file to a new block. Then, of course, the attribute values should be set in the new DXFInsert.
The new attribs shows up (not at the position I excpected), however when I move the block (for example with you editor example), the attributes don't move with the block (as if they are not fixed to the block, but they are).
Can you please assist me with this?

Thanks!

Frank

Re: Add Attribs to DXFInsert

Posted: 09 Nov 2010, 18:14
by support
Hello Frank.
This situation is normal. ATTRib object displays on drawing specified string value instead the corresponding ATTDef object that is inside a block. DXF specification provide ATTRibs placement on the drawing, that's why you don't move it with the insert. CAD Import VCL store ATTRibs in TsgDXFInsert.Entities with drawing coordinates. In code you set ATTDef block coordinates to ATTRib drawing coordinates. Because of this you found ATTRib object in position other than expected.

Alexander.

Re: Add Attribs to DXFInsert

Posted: 09 Nov 2010, 19:16
by hls
Hello Alexander.
Then I will stop searching what I did wrong. I will work-around this (maybe by using text instead of attributes or moving the attributes manually after the insert is moved). I expected the attributes should be moving with the block, because that is the way Autocad works.
Thank you for the info!
Frank

Re: Add Attribs to DXFInsert

Posted: 10 Nov 2010, 11:41
by support
Hello Frank.
AutoCAD software include superior editing functionality, it allows also moving attributes separately from an insert. Editor application from the CAD Import VCL package is only a demo, implemented editing functionality is minimal. You can see moving insert/attributes realization in ABViewer: moving insert or attribute separately is possible as well as both objects simultaneously.
You can add coordinates recalculation to your code. TsgDXFInsert.Point, TsgDXFBlock.Offset, TsgDXFBlock.Scale define difference between attdef and attrib insertion points.

Alexander.