Add Attribs to DXFInsert
Posted: 08 Nov 2010, 18:03
I have a problem to add Attribs to a DXFInsert with the following code:
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
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