0

Is there any way to insert one kind of image files such as png or jpg to a drawing, programmatically in c# by using Autodesk.Autocad.Interop and Autodesk.Autocad.Interop.common dlls?

I have tried AcadDocument.Database.ModelSpace.InsertBlock() but it works just with dwg files and returns the following error for images :

"Invalid File Header."

M_Mogharrabi
  • 1,369
  • 5
  • 29
  • 57

1 Answers1

3

InsertBlock() is only for inserting block definitions. Use AddRaster() to import an image via AutoCAD Interop libraries:

var imgPath = @"C:\Users\Public\Pictures\Sample Pictures\Jellyfish.jpg";
var imgScale = 2.0;
var imgRot = (Math.PI / 180) * 90;
var imgPoint = new double[] {1, 1, 0};

doc.ModelSpace.AddRaster(imgPath, imgPoint, imgScale, imgRot);

Where 'doc' is the ActiveDocument of a running AutoCAD session.

Parrish Husband
  • 3,148
  • 18
  • 40
  • Thanks a lot,That was my answer.I have searched too many but i could not find anything.I have another little question yet! How can i find the position of a special attribute in a block? – M_Mogharrabi Mar 11 '14 at 07:23