Valued Contributor
58 Posts
0 Kudos
Registered: ‎12-15-2009
Post 1 of 2

Scale factor issue when inserting Image.

182 Views, 1 Replies
12-05-2013 01:39 AM


I am asking user for scale factor and insertion point. but the actual image alway display width and height as the scale value, if i insert value of 5 for scale factor width and height will be 5 but not according to coordinates system.

 but if i insert the same image manualy width and height are calculated by autocad according to scale factor before insertion.


double scale = promptDoubleResult.Value;
 var xAxis = new Vector3d(scale, 0, 0);
 var yAxis = new Vector3d(0, scale, 0);
 var ucs = document.Editor.CurrentUserCoordinateSystem;                   
using (Transaction trans = database.TransactionManager.StartTransaction())
                        RasterImageDef rasterImageDef = new RasterImageDef();
                        rasterImageDef.SourceFileName = imagePath;
                        ObjectId imgDicId = RasterImageDef.GetImageDictionary(database);
                        if(imgDicId.OldIdPtr == new IntPtr(0))
                            imgDicId = RasterImageDef.CreateImageDictionary(database);
                        DBDictionary imgDict = trans.GetObject(imgDicId, OpenMode.ForWrite, false, true) as DBDictionary;
                        if (imgDict.Contains(BlockName))
                            return false;
                            imgDict.SetAt(BlockName, rasterImageDef);
                            trans.AddNewlyCreatedDBObject(rasterImageDef, true);

                            // now add the REAL raster image reference               
                            RasterImage rasterImg = new RasterImage();
                            rasterImg.ImageDefId = rasterImageDef.ObjectId;

                            rasterImg.Orientation = new CoordinateSystem3d(insertionPoint.TransformBy(ucs),xAxis.TransformBy(ucs),yAxis.TransformBy(ucs));
                            rasterImg.Rotation = rotationAngle;

                            BlockTable bt = (BlockTable)trans.GetObject(database.BlockTableId, OpenMode.ForRead, false, true);
                            BlockTableRecord btr = (BlockTableRecord)trans.GetObject(database.CurrentSpaceId, OpenMode.ForWrite, false, true);
                            ObjectId rasterImgId = btr.AppendEntity(rasterImg);

                            trans.AddNewlyCreatedDBObject(rasterImg, true);


Thanks for your help.

246 Posts
44 Kudos
Registered: ‎07-20-2011
Post 2 of 2

Re: Scale factor issue when inserting Image.

12-07-2013 08:50 AM in reply to: mnav

I have seen the same issues in VBA some years ago.

Currently no C# sample available but have a look at the next code might help

Notice i had to set the scale twice.

                With imageRef
'                    On Error Resume Next
'                        .ImageFile = ".\" & fs.GetFileName(tifPathname)
'                    On Error GoTo EndOfProc
                    .Origin = imagePos
                    .ScaleFactor = imageScale
                    .Rotation = imageAngle
                    .ScaleFactor = 1
                    acadDoc.Layers.Add "Raster"
                    .layer = "Raster"
                    .Transparency = True
                    On Error Resume Next
                        .name = fs.GetBaseName(tifPathname)
                    On Error GoTo EndOfProc
                End With

Also compare the DPI for both the manual and youre program result.

Drawing Units may influence the behaviour as well.

And besure to have the xDPI==yDPI otherwise youre raster may not be editable in RasterDesign.


Post to the Community

Have questions about Autodesk products? Ask the community.

New Post