How to export a single DB Object to a JPEG or BITMAP image

How to export a single DB Object to a JPEG or BITMAP image

scavallariTRKRY
Explorer Explorer
1,057 Views
5 Replies
Message 1 of 6

How to export a single DB Object to a JPEG or BITMAP image

scavallariTRKRY
Explorer
Explorer

Hi,

I'm developing a DLL using .NET I want to know if there is a way to export a single DB object, Polyline, BlockReference, MText etc. in a JPEG or BITMAP image?

I want to read object directly from DB, without open the design:

 

 

using (Database masterDb = new Database(false, true))
{
	masterDb.ReadDwgFile("C:\MyDesign.dwg", FileOpenMode.OpenForReadAndAllShare, false, null);
	using (Transaction masterTr = masterDb.TransactionManager.StartTransaction())
	{
		BlockTable masterBt = masterTr.GetObject(masterDb.BlockTableId, OpenMode.ForRead) as BlockTable;
		BlockTableRecord masterBtr = (BlockTableRecord)masterTr.GetObject(masterBt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

		foreach (ObjectId objId in masterBtr)
		{
			Entity ent = (Entity)masterTr.GetObject(objId, OpenMode.ForRead);
			
			// HOW TO EXPORT THE SINGLE ENTITY IN A JPEG/BMP IMAGE ?????????
			..................
			..................
		}
	}
}

 

0 Likes
Accepted solutions (1)
1,058 Views
5 Replies
Replies (5)
Message 2 of 6

norman.yuan
Mentor
Mentor

Is there specific reason that you need to the image of an entity or a few entities from a drawing file by opening it as side database?

 

If you have the drawing opened in editor, you can simply use the COM API's Export() method. That is, zoom to an entity (you may want to also turn off layers to hide other overlapped entities, select it and then call Export() with proper file format input.

 

However, it is doable with side database. I just wrote some quick code to prove it works. I'll post the whole source code as a complete project in my blog ASAP. Stay tuned.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 6

norman.yuan
Mentor
Mentor
Accepted solution

OK, since I found a bit of time, I have the code published here:

 

https://drive-cad-with-code.blogspot.com/2022/10/extract-entity-image-from-side-loaded.html 

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 6

scavallariTRKRY
Explorer
Explorer

I can surely open the document as active, but I need to save the bitmap/jpeg of entities that respect some characteristics, so I thought to use side database.

 

Thank you in advance

0 Likes
Message 5 of 6

Ed__Jobe
Mentor
Mentor

I'm not sure if your requirement is to have a coded solution as part of a larger project. If not, you can do what you want with Raster Design. First, create a REM region using the IREGFROMVEC command. Then use the ICONVTOIMG command to push the REM to a new raster image.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 6 of 6

scavallariTRKRY
Explorer
Explorer
Man it works!!!!!

Thank you very much 🙂
0 Likes