Page 1 of 1

How to create a BLOCK

Posted: 26 Oct 2010, 18:18
by aby
Hi,

I need an example on how to create and use a block.

Is there any ?

Thanks

Aby

Re: How to create a BLOCK

Posted: 29 Oct 2010, 16:32
by support
Hello aby.
Creation the block is the similar to any common entity. The following code sample shows adding block referense to CADImage structure, you can implement it into AddNewEntities demo code:

Code: Select all

void Add_Entity(TsgDXFConverter * AConverter, TConvSection sect, TsgDXFEntity * AEnt)
{
  AConverter->Sections[sect]->AddEntity(AEnt);
  if (AConverter->OnCreate)
	AConverter->OnCreate(AEnt);
  AConverter->Loads(AEnt);
}


void __fastcall TfmMain::btnNewClick(TObject *Sender)
{
  TsgDXFEntity *Ent = NULL;
  TsgCADImage *Im;
  TsgDXFBlock *blck;
  TsgDXFInsert *ins;

  if (!sgPaintBox->Empty())
	if (sgPaintBox->Picture->Graphic->InheritsFrom(__classid(TsgCADImage)))
	{
	  Im = dynamic_cast<TsgCADImage *>(sgPaintBox->Picture->Graphic);
	  Ent = GetEntity(Im);

	  if (Ent != NULL)
	  {
		TsgDXFBlock *blck = new TsgDXFBlock();
		blck->Name = "NAME1";

		TsgDXFInsert *ins = new TsgDXFInsert();
		ins->Block = blck;

		//AddEntity(Im->Converter, Ent);
		blck->AddEntity(Ent);

		Add_Entity(Im->Converter, csBlocks, blck);
		Add_Entity(Im->Converter, csEntities, ins);

		Im->GetExtents();
		FLastAdded = Ent;
	  }
	  sgPaintBox->Refresh();
	}
}
Alexander.