.NET

Reply
New Member
CSHodge
Posts: 2
Registered: ‎10-03-2006
Message 1 of 2 (516 Views)

Crash when Creating Raster Image

516 Views, 1 Replies
10-03-2006 11:14 AM
I know I'm missing something simple...here's my code:

Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
using (Transaction t = tm.StartTransaction())
{

// open the dictionary
Autodesk.AutoCAD.DatabaseServices.ObjectId imgDictID = RasterImageDef.GetImageDictionary(db);
DBDictionary imgDict;
if (imgDictID.OldId == 0)
{
imgDictID = RasterImageDef.CreateImageDictionary(db);
}


// create the raster image definition
RasterImageDef rasterDef = new RasterImageDef();
// rasterDef.SourceFileName = mapURL;
rasterDef.SourceFileName = "C:/ObjectARX 2007/samples/graphics/Render/background.jpg";
rasterDef.Load();

// test the image dictionary and the raster before going further
bool bTestLoad = rasterDef.IsLoaded;
Autodesk.AutoCAD.DatabaseServices.ObjectId TestImgDictID = RasterImageDef.GetImageDictionary(db);
imgDict = (DBDictionary)t.GetObject(imgDictID, OpenMode.ForWrite);


// add the raster definition to the dictionary iff it doesn't already exist
Autodesk.AutoCAD.DatabaseServices.ObjectId rasterDefID;
if (!imgDict.Contains("NewMap"))
{
rasterDefID = imgDict.SetAt("NewMap", rasterDef);
}
t.AddNewlyCreatedDBObject(rasterDef, true);

/* test */
bool bTestImage = imgDict.Contains("NewMap");

// everything is good up to this point...


// now add the REAL raster image reference
RasterImage rasterRef = new RasterImage();
rasterRef.ImageDefId = rasterDef.ObjectId;
// rasterRef.AssociateRasterDef(rasterDef); // crashes here if I use Associate
Autodesk.AutoCAD.DatabaseServices.ObjectId testRefID = rasterRef.ObjectId;
t.AddNewlyCreatedDBObject(rasterRef, false); // crashes here
testRefID = rasterRef.ObjectId;


t.Commit();

}
New Member
CSHodge
Posts: 2
Registered: ‎10-03-2006
Message 2 of 2 (516 Views)

Re: Crash when Creating Raster Image

10-03-2006 11:28 AM in reply to: CSHodge
Doh!

I forgot to add the entity to the database! Should have been:

// now add the REAL raster image reference
RasterImage rasterRef = new RasterImage();
rasterRef.ImageDefId = rasterDef.ObjectId;
Autodesk.AutoCAD.DatabaseServices.ObjectId testRefID = rasterRef.ObjectId;
BlockTable bt = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
BlockTableRecord btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
btr.AppendEntity(rasterRef);

tm.AddNewlyCreatedDBObject(rasterRef, true);
testRefID = rasterRef.ObjectId;

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community