Question

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."

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top