Page 1 of 1

Problem with export to DXF

Posted: 23 Jan 2009, 20:27
by lolena1888
Hello, Sergey!

I have a problem with export of my drawing (created from scratch) to DXF, which I do with the following code:

Code: Select all

            CADImport.Export.DirectCADtoDXF.CADtoDXF exp = new CADImport.Export.DirectCADtoDXF.CADtoDXF(cadImage);
            exp.SaveToFile("C:\\...\\dxf.dxf");
The resulted file is empty (4K) - see the attached screenshot. When downloading to ViewerDemo it shows that my Insert is there. CadImage also is not empty (I see the drawing on the screen). Can you advise what is wrong?
screenshot.jpg
screenshot.jpg (110.45 KiB) Viewed 20110 times
Elena

Re: Problem with export to DXF

Posted: 26 Jan 2009, 16:12
by support
Hello Elena,

Can you please give the whole code of creating your file?

Sergey.

Re: Problem with export to DXF

Posted: 26 Jan 2009, 18:06
by lolena1888
Sergey,
I cannot provide you with all code it is complex, but my schema is like this:

1. I create my own class Polyline wich inherits from CADPolyline.
...Create polyline adding some vertexes and add it to block (my own class)

2. I create my own class Block which inherits from CADBlock and adds it to CADInsert.

Code: Select all

           if (BlockKey != null) this.KeyEnt = BlockKey;
            this.CadImage.Converter.OnCreate(this);
            this.CadImage.Converter.Loads(this);
           
 // is not required, for testing purposes
            CADLayer cadLayer = new CADLayer();
            cadLayer.Name = "Insert";
            cadLayer.Color = Color.Red;
            this.CadImage.Converter.Layers.Add(cadLayer);
//
            if (Insert != null)
            {
                Insert.Block = this;
                Insert.Visibility = true;
                Insert.Point = new DPoint(Parameters.offsetX,Parameters.offsetY+Parameters.dOffsetZ,0);
                Insert.Layer = cadLayer;
                this.CadImage.Converter.Entities.Add( Insert);
                this.CadImage.Converter.OnCreate(Insert);
                this.CadImage.Converter.Loads(Insert);
            }
        }
For testing purposes I export file on button_click:

Code: Select all

...
{            CADImport.Export.DirectCADtoDXF.CADtoDXF ctd = new CADImport.Export.DirectCADtoDXF.CADtoDXF(cadImage);
            ctd.SaveToFile("C:\\...\\dxf.dxf");
}

While debugging in cadImage.Converter I have entity of type CADInsert,
insert.Block has block of type myBlock (can it be the problem for convertion?),
block has entities of type myPolyline and CADLine.
myPolyline has Vertexes of type CADVertex.

I will try to test if my own types are the problem for convertion, but in this case why entities that are of CADImport types are not exported?
This is pretty much it. I have a cadImage that shows drawing on the screen, but creates an empty dxf file.

Elena

Re: Problem with export to DXF

Posted: 26 Jan 2009, 20:10
by lolena1888
Sergey,
after some testing I have follows:
everything goes right if I add my custom polyline directly to cadImage:

Code: Select all

this.cadImage.Converter.Entities.Add(myPolyline);
Everything that I try to add to block / insert is not visible on the screen in dxf file. Everything that I add to cadImage directly works properly:

Code: Select all

CADBlock block = new CADBlock();

CADLine ln0 = new CADLine();
                ln0.Color = Color.Violet;
                ln0.LineWeight = 0.7;
                ln0.Point = new DPoint(0,0,0);
                ln0.Point1 = new DPoint(Parameters.masshtab * 4, 0, 0);
                ln0.Loaded(this.cadImage.Converter);
                this.cadImage.Converter.OnCreate(ln0);
                this.cadImage.Converter.Entities.Add(ln0); //this line will be visible in dxf
                
                CADLine ln1 = new CADLine();
                ln1.Color = Color.Green;
                ln1.LineWeight = 0.7;
                ln1.Point = new DPoint(0, 0, 0); ;
                ln1.Point1 = new DPoint(0, Parameters.masshtab * 4, 0);
                block.AddEntity(ln1); // this line is visible on drawing and not visible in dxf
                ln1.Loaded(this.cadImage.Converter);
                this.cadImage.Converter.OnCreate(ln1);

                CADLine ln2 = new CADLine();
                ln2.Color = Color.Yellow;
                ln2.LineWeight = 0.7;
                ln2.Point = new DPoint(0, 0, 0); ;
                ln2.Point1 = new DPoint(0, 0,Parameters.masshtab*4);
                block.AddEntity(ln2); // this line is visible on drawing and not visible in dxf

                ln2.Loaded(this.cadImage.Converter);
                this.cadImage.Converter.OnCreate(ln2);

            cadImage.Converter.OnCreate(block);
            cadImage.Converter.Loads(block);


            CADLayer cadLayer = new CADLayer();
            cadLayer.Name = "InsertLayer";
            cadLayer.Color = Color.Red;
            cadImage.Converter.Layers.Add(cadLayer);

            CADInsert Insert = new CADInsert();

                Insert.Block = block;
                Insert.Visibility = true;
                Insert.Point = new DPoint(0, 0, 0);
                Insert.Layer = cadLayer;
                                cadImage.Converter.OnCreate(Insert);
                cadImage.Converter.Loads(Insert);
            this.cadImage.Converter.Entities.Add(Insert); //this is visible on drawing and not visible in dxf. 


Elena

Re: Problem with export to DXF

Posted: 27 Jan 2009, 11:15
by support
Hello, Elena!

Please try the following code:

Code: Select all

class MyCADPolyLine: CADPolyLine
{
}
class MyCADBlock: CADBlock
{
}		

private void btnAddMyEntities_Click(object sender, System.EventArgs e)
{
	if(this.cadImage == null) 
	{
		this.cadImage = new CADImage();
		this.cadImage.InitialNewImage();
		this.cadImage.UseDoubleBuffering = false;
	}
	else
		this.cadImage.UseDoubleBuffering = false;

	MyCADPolyLine entPolyine = new MyCADPolyLine();
	entPolyine.Color = CADConst.clNone;
	CADVertex entVert = new CADVertex();
	entVert.Point = new DPoint(34000, -31607, -9600);
	entPolyine.AddEntity(entVert);
	entVert = new CADVertex();
	entVert.Point = new DPoint(50392, -36000, -12000);
	entPolyine.AddEntity(entVert);
	entVert = new CADVertex();
	entVert.Point = new DPoint(60784, -30000, -12000);
	entPolyine.AddEntity(entVert);
	entVert = new CADVertex();
	entVert.Point = new DPoint(28000, -21215, -9600);
	entPolyine.AddEntity(entVert);
	this.cadImage.Converter.OnCreate(entPolyine);
	this.cadImage.Converter.Loads(entPolyine);

	MyCADBlock bl1 = new MyCADBlock();				
	bl1.Name = "MyBlock";
	bl1.Color = Color.Red;
	bl1.Visibility = true;
	bl1.Visible = true;
	bl1.AddEntity(entPolyine);
	this.cadImage.Converter.Blocks.Add(bl1);
	this.cadImage.Converter.OnCreate(bl1);
	this.cadImage.Converter.Loads(bl1);
	CADInsert ins1 = new CADInsert();
	ins1.Block = bl1;
	ins1.Point = new DPoint(10, 10, 0);
	ins1.Visibility = true;
	this.cadImage.Converter.Entities.Add(ins1);
	this.cadImage.Converter.OnCreate(ins1);
	this.cadImage.Converter.Loads(ins1);
	this.cadPictBox.Invalidate();

	this.cadImage.GetExtents();
	this.DoResize();    
	SaveAsDXF(@"c:\12.dxf");
}
It works.

Sergey.