.NET

.NET

Reply
Valued Contributor
78 Posts
0 Kudos
Registered: ‎08-20-2012
Post 1 of 7

How can I insert rasterImage but not depend on the ori file outside?

349 Views, 6 Replies
05-18-2013 01:54 AM

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.

*Expert Elite*
9,795 Posts
1,210 Kudos
Registered: ‎06-29-2007
Post 2 of 7

Re: How can I insert rasterImage but not depend on the ori file outside?

05-18-2013 02:09 AM in reply to: kevinsir

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 -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
78 Posts
0 Kudos
Registered: ‎08-20-2012
Post 3 of 7

Re: How can I insert rasterImage but not depend on the ori file outside?

05-18-2013 04:43 AM in reply to: Alfred.NESWADBA

Thanks for your reply! If you can give me some code for example ,that will be perfect!

*Expert Elite*
9,795 Posts
1,210 Kudos
Registered: ‎06-29-2007
Post 4 of 7

Re: How can I insert rasterImage but not depend on the ori file outside?

05-18-2013 06:17 AM in reply to: kevinsir

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 :smileywink:

OLE-embedding (which I would avoid as long as possible) ... have you searched here? There are already some threads: >>>click<<<

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
78 Posts
0 Kudos
Registered: ‎08-20-2012
Post 5 of 7

Re: How can I insert rasterImage but not depend on the ori file outside?

05-19-2013 01:52 AM in reply to: Alfred.NESWADBA

Thanks,I will try it ,Then give  you a feedback

Valued Contributor
78 Posts
0 Kudos
Registered: ‎08-20-2012
Post 6 of 7

Re: How can I insert rasterImage but not depend on the ori file outside?

05-19-2013 05:02 AM in reply to: Alfred.NESWADBA

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?

ADN Support Specialist
761 Posts
100 Kudos
Registered: ‎03-21-2011
Post 7 of 7

Re: How can I insert rasterImage but not depend on the ori file outside?

05-24-2013 05:32 AM in reply to: kevinsir

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();
                }
            }
        }
    }
}

 



Balaji
Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post