Insert image failed with V7

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
yannick
Posts: 18
Joined: 16 Apr 2008, 12:43

Insert image failed with V7

Post by yannick » 24 Jul 2009, 17:13

Hello,

I try the new version of cadimport.dll (Version 7.2.1.21993) but some code doesn't work now.

With previous version ( V6.3.2942.31653), i manage to insert image with the following code :
cadPictBox.DoubleBuffering = false;

CADLayer entLayer = new CADLayer();
entLayer.Name = "MyLayer";
entLayer.Color = Color.RoyalBlue;
entLayer.Flags = 4;
this.cadImage.Converter.Layers.Add(entLayer);
this.cadImage.Converter.OnCreate(entLayer);
this.cadImage.Converter.Loads(entLayer);

//creation block
CADBlock bl1 = new CADBlock();
string sBlockName = "blimage";

bl1 = (cadImage.Converter.GetSection(CADImport.FaceModule.ConvSection.Blocks).Entities[sBlockName] as CADBlock);

if (bl1 == null)
bl1 = new CADBlock();

bl1.Name = sBlockName;
bl1.Color = CADConst.clNone;
bl1.Visibility = true;
bl1.Visible = true;
bl1.Layer = entLayer;

//creation image
CADImageEnt image = new CADImageEnt();
Image imageObj = null;
double dbHeightImage = 38;

imageObj = System.Drawing.Image.FromFile(@"c:\tmp\GenComposant.JPG");

image.SetImage(imageObj);
image.Color = Color.Bisque;
image.Point = new DPoint(0, 0, 0);
image.Point1 = new DPoint(dbHeightImage, -dbHeightImage, 0);
image.Point2 = new DPoint(0, 0, 0);
image.Point3 = new DPoint(1, 1, 1);
image.Rotate = 0;
image.LineWeight = 0.1;

image.Loaded(this.cadImage.Converter);
this.cadImage.Converter.OnCreate(image);
bl1.AddEntity(image);

//load block
this.cadImage.Converter.Blocks.Add(bl1);
this.cadImage.Converter.OnCreate(bl1);
this.cadImage.Converter.Loads(bl1);


//creation + load insert
CADInsert ins1 = new CADInsert();
ins1.Block = bl1;
ins1.Point = new DPoint(System.Convert.ToDouble(txtPosX.Text), System.Convert.ToDouble(txtPosY.Text), 0);
ins1.Visibility = true;
ins1.Layer = entLayer;

this.cadImage.Converter.Entities.Add(ins1);
this.cadImage.Converter.OnCreate(ins1);
this.cadImage.Converter.Loads(ins1);

this.cadPictBox.Invalidate();

Now image doesn't appear in the dwg map.
Moreover even if call two times the code, the following line return always null (but not in V6):
bl1 = (cadImage.Converter.GetSection(CADImport.FaceModule.ConvSection.Blocks).Entities[sBlockName] as CADBlock);
So i think, i don't manage to insert block with the new version.

Please could you explain me what is wrong.

Thanks, yannick

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: Insert image failed with V7

Post by support » 06 Aug 2009, 11:43

Hello.
Due to changes in CAD Import .NET 7 the code that works well in CAD Import .NET 6 requires some modifications. You can use such code:

Code: Select all

            if (this.cadImage == null)
            {
                this.cadImage = new CADImage();
                this.cadImage.InitialNewImage();
            }
            this.cadImage.UseDoubleBuffering = false;

            CADLayer entLayer = new CADLayer();
            entLayer.Name = "MyLayer";
            entLayer.Color = Color.RoyalBlue;
            entLayer.Flags = 4;
            entLayer.Loaded(this.cadImage.Converter);
            this.cadImage.Converter.OnCreate(entLayer);
            this.cadImage.CurrentLayout.AddEntity(entLayer);

            //creation block
            CADBlock bl1 = new CADBlock();
            string sBlockName = "blimage";

            bl1 = (cadImage.Converter.GetSection(CADImport.FaceModule.ConvSection.Blocks).Entities[sBlockName] as CADBlock);

            if (bl1 == null)
               bl1 = new CADBlock();

            bl1.Name = sBlockName;
            bl1.Visibility = true;
            bl1.Visible = true;
            bl1.Layer = entLayer;

            //creation image
            Point p1 = new Point(0, 0);
            Point p2 = new Point(100, 75);
            Rectangle r1 = CADConst.SetNewRect(p1, p2);
            DPoint pt1 = new DPoint(r1.Left, r1.Top, 0);
            DPoint pt2 = new DPoint(r1.Right, r1.Bottom, 0);
            CADImageEnt image = new CADImageEnt();
            string path = @"c:\tmp\GenComposant.JPG";
            Bitmap bmpTmp;
 
            bmpTmp = new Bitmap(path);

            CADImageDef def = new CADImageDef();
            def.FileName = path;
            this.cadImage.Converter.Loads(def);

            image.ImageDef = def;
            image.Point = new DPoint(pt1.X, pt1.Y, 0);
            image.Size = new DPoint(r1.Width, r1.Height, 0);
            image.Loaded(this.cadImage.Converter);
            this.cadImage.Converter.ImageDefs.Add(image.ImageDef);
           
            bl1.AddEntity(image);

            //load block
            bl1.Loaded(this.cadImage.Converter);
            this.cadImage.Converter.OnCreate(bl1);
            this.cadImage.CurrentLayout.AddEntity(bl1);

            //creation + load insert
            CADInsert ins1 = new CADInsert();
            ins1.Block = bl1;
            ins1.Point = new DPoint(0, 0, 0);
            ins1.Visibility = true;
            ins1.Layer = entLayer;

            ins1.Loaded(this.cadImage.Converter);
            this.cadImage.Converter.OnCreate(ins1);
            this.cadImage.CurrentLayout.AddEntity(ins1);
            
            this.cadPictBox.Invalidate();
Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

yannick
Posts: 18
Joined: 16 Apr 2008, 12:43

Re: Insert image failed with V7

Post by yannick » 25 Aug 2009, 15:27

I test with dll demo version 7.2.1.21993.

Your example works partially, now picture appears in the map.
For informations, the following code was the problem :
V6:
image.Point = new DPoint(0, 0, 0);
image.Point1 = new DPoint(dbHeightImage, -dbHeightImage, 0);
image.Point2 = new DPoint(0, 0, 0);
image.Point3 = new DPoint(1, 1, 1);

With V7 we just need to remplace with :
image.Point = new DPoint(0, 0, 0);
image.Size = new DPoint(dbHeightImage, -dbHeightImage, 0);

But i still get bl1 with null after this line of code with your example when i call two times the code:
bl1 = (cadImage.Converter.GetSection(CADImport.FaceModule.ConvSection.Blocks).Entities[sBlockName] as CADBlock);

I get the same problem if i test this :
CADLayer entLayer = (CADLayer)cadImage.Converter.Layers["MyLayer"];
if (entLayer == null)
{
entLayer = new CADLayer();
entLayer.Name = "MyLayer";
entLayer.Color = Color.RoyalBlue;
entLayer.Flags = 4;

entLayer.Loaded(this.cadImage.Converter);
this.cadImage.Converter.OnCreate(entLayer);
this.cadImage.CurrentLayout.AddEntity(entLayer);
}

I i call two times this code entLayer is always null after this:
CADLayer entLayer = (CADLayer)cadImage.Converter.Layers["MyLayer"];
But i didn't got this problem with V6.

Please could you explain me what is wrong.

Thanks, yannick

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: Insert image failed with V7

Post by support » 27 Aug 2009, 16:39

Hello.
This code fragment doesn't works correctly for version 7:

Code: Select all

...
this.cadImage.Converter.Blocks.Add(bl1);
...
use following string instead of previous:

Code: Select all

this.cadImage.Converter.GetSection(CADImport.FaceModule.ConvSection.Blocks).AddEntity(bl1);
Alexander.

yannick
Posts: 18
Joined: 16 Apr 2008, 12:43

Re: Insert image failed with V7

Post by yannick » 02 Sep 2009, 17:01

I thank you Alexander for yours answers. Now I manage to insert bitmap and to retrieve block and layer.

But I get a new problem with the version V7.
I manage to save a loading dwg into a dxf file with this code:
string sPathFileName = @"c:\tmp\map.dxf";
CADImport.Export.DirectCADtoDXF.CADtoDXF vExp = new CADImport.Export.DirectCADtoDXF.CADtoDXF(cadImage);
vExp.SaveToFile(sPathFileName);

In order to verify the generated file, i use DWG TrueView 2008 from autodesk.
With version V6.3.2942.31653 the view in DWG TrueView was correct but now with version V7.2.2.21605, i don't mange to load the new generated file (dxf) in DWG True View, i get an error. I join the screen of the crash. I don't know how i can send you the original dwg.
I know that DWG True view is not your product but it seems to me that it is a software very know and use, so it's a problem if we can't use it.

Thanks, yannick.
Attachments
crashDWGtrueview.JPG
crashDWGtrueview.JPG (76.73 KiB) Viewed 42718 times

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: Insert image failed with V7

Post by support » 03 Sep 2009, 10:48

Hello.

We recently updated version of the site: http://www.cadsofttools.com/download/cadimportnet.zip. Try using it to export. Please do not pay attention to the fact that the version number has been reduced.
You can send your DWG-file at our technical support: support@cadsofttools.com

Anton

kanita
Posts: 1
Joined: 24 Dec 2014, 16:00

Re: Insert image failed with V7

Post by kanita » 24 Dec 2014, 16:01

Thanks for the reply. Currently I am using the trail version to test the application. Can you suggest me in more detail, please. Because the CADText and the CADMText classes are not found in the dll file I use. I can only load the image using CADImage class. I am not sure about the namespaces for that. If possible please tell me where can I find the documentation for this.
You can join us for best HIT-001 exam dumps exam Test-king.com training solutions. Our stevenson contains all those materials you want to pass for real www.the-bac.edu exam & ase training in Principia College

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: Insert image failed with V7

Post by support » 05 Jan 2015, 17:16

Hello,

CADImage, CADText and CADMText classes are part of CADImport namespace:

Code: Select all

using CADImport;
Mikhail
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply