How can I bind the rasterImage as part of dwg file not depend on the ori file outside?
I use the imageattach order, However when i delete the ori image or send the dwg file to others
the image is wrong. How can i solve it ? Thanks.
Hi,
>> However when i delete the ori image or send the dwg file to othersthe image is wrong. How can i solve it ?
Use command _ETRANSMIT (>>>details<<<) to transfer your project data, so refrences will not be missed then.
>> How can I bind the rasterImage as part of dwg file
You might insert it as OLE-object, but there are then some issues like file-size, some problems when printing (might be) and some more (read here in the forum about problems with OLE objects, for me: enough to avoid it)
- alfred -
Thanks for your reply! If you can give me some code for example ,that will be perfect!
Hi,
>> If you can give me some code [...]
Code to do what? Running the command _ETRANSMIT or embedding an ole-object into the drawing?
The command _ETRANSMIT is ready to use, there has nothing to be added, it exists 😉
OLE-embedding (which I would avoid as long as possible) ... have you searched here? There are already some threads: >>>click<<<
- alfred -
Hello,
I read this code
[CommandMethod("InsertOle")]
public static void InsertOle()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Database refDb = new Database();
refDb.ReadDwgFile("c:\\Temp\\MyOleTemplate.dwg", System.IO.FileShare.Read, true, "");
using (Transaction Tx = db.TransactionManager.StartTransaction())
{
BlockTable bT = Tx.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
BlockTableRecord bTR = Tx.GetObject(bT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
ObjectId btrId = db.Insert("MyOleTemplate", refDb, true);
BlockReference blockRef = new BlockReference(new Point3d(), btrId);
DBObjectCollection entitySet = new DBObjectCollection();
blockRef.Explode(entitySet);
foreach (object obj in entitySet)
{
if (obj is Ole2Frame)
{
Ole2Frame ole = obj as Ole2Frame;
//...
bTR.AppendEntity(ole);
Tx.AddNewlyCreatedDBObject(ole, true);
}
}
Tx.Commit();
}
}
However I have two question about it.
1、Should MyOleTemplate.dwg be a special file that with the image I want to insert?
2、
if (obj is Ole2Frame)
{
Ole2Frame ole = obj as Ole2Frame;
//...
bTR.AppendEntity(ole);
Tx.AddNewlyCreatedDBObject(ole, true);
can i use this code set 'ole ' to another image file and then the image file it will independ outside?
How about using "WblockCloneObjects" to get the Ole2Frame from the other drawing ?
Here is a sample code that you can try :
Document doc = Application.DocumentManager.MdiActiveDocument; Database destDb = doc.Database; Editor ed = doc.Editor; PromptResult prTableStyleName = ed.GetString("\nEnter drawing file path : "); if (prTableStyleName.Status != PromptStatus.OK) return; string dwgFilePath = prTableStyleName.StringResult; if (!System.IO.File.Exists(dwgFilePath)) return; using (Database srcDb = new Database(false, true)) { srcDb.ReadDwgFile(dwgFilePath, System.IO.FileShare.Read, true, ""); ObjectIdCollection oleObjectIds = new ObjectIdCollection(); using (Transaction Tx = srcDb.TransactionManager.StartTransaction()) { BlockTable bT = Tx.GetObject(srcDb.BlockTableId, OpenMode.ForWrite) as BlockTable; BlockTableRecord btr = Tx.GetObject(bT[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; foreach (ObjectId id in btr) { if (id.ObjectClass.Name != "AcDbOle2Frame") continue; oleObjectIds.Add(id); break; } Tx.Commit(); } if (oleObjectIds.Count > 0) { ObjectId destBTRId = destDb.CurrentSpaceId; IdMapping iMap = new IdMapping(); destDb.WblockCloneObjects(oleObjectIds, destBTRId, iMap, DuplicateRecordCloning.Replace, false); IdPair idPair = iMap.Lookup(oleObjectIds[0]); ObjectId newId = idPair.Value; if (newId.IsValid) { PromptPointResult pr = ed.GetPoint("\nSelect insertion point: "); if (pr.Status == PromptStatus.OK) { Point3d pt = pr.Value; using (Transaction Tx = destDb.TransactionManager.StartTransaction()) { Ole2Frame ole2Frame = Tx.GetObject(newId, OpenMode.ForWrite) as Ole2Frame; dynamic acadOle = ole2Frame.AcadObject; double[] insertionPoint = new double[3]; insertionPoint[0] = pt.X; insertionPoint[1] = pt.Y; insertionPoint[2] = pt.Z; acadOle.InsertionPoint = insertionPoint; Tx.Commit(); } } } } }