<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic how to put a  block  into image? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4879858#M45078</link>
    <description>how to put a block in DWG into image with C# code?</description>
    <pubDate>Wed, 12 Mar 2014 04:41:21 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2014-03-12T04:41:21Z</dc:date>
    <item>
      <title>how to put a  block  into image?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4879858#M45078</link>
      <description>how to put a block in DWG into image with C# code?</description>
      <pubDate>Wed, 12 Mar 2014 04:41:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4879858#M45078</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-12T04:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to put a  block  into image?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4881998#M45079</link>
      <description>&lt;P&gt;You can use something like this code:&lt;/P&gt;
&lt;PRE&gt;    public class BlockUtils
    {
        //ads_queueexpr
        [DllImport("accore.dll", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl,
EntryPoint = "ads_queueexpr")]
        extern static private int ads_queueexpr(byte[] command);


        //_____________________________________________________//
        //used block named "Door"
        //Path to save bitmap: "c:\\Test\\Door.bmp"
        //Change all to your suit

        [CommandMethod("dic")]
        public void AddBlockImageToDwg()
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            Transaction tr = doc.TransactionManager.StartTransaction();
            try
            {
                using (DocumentLock doclock = doc.LockDocument())
                {
                    using (tr)
                    {
                        DBDictionary namedDic = (DBDictionary)tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead);
                        if (!namedDic.Contains("ACAD_IMAGE_DICT") )
                        {
                            ed.WriteMessage("\nACAD_IMAGE_DICT does not Exist");
                            return;
                        }
                        ObjectId dictId = RasterImageDef.GetImageDictionary(db);
                       // string recBase = "Door#";
    

                        if (dictId == ObjectId.Null)
                        {
                            // Image dictionary doesn't exist, create new
                            dictId = RasterImageDef.CreateImageDictionary(db);
                        }

                        // Open the image dictionary
                        DBDictionary dict = (DBDictionary)tr.GetObject(dictId, OpenMode.ForRead);
                        // Get a record name for our raster image definition
                        if (dict.Contains("Door"))
                        {
                            ed.WriteMessage("\nDoor RasterImage Definition Exists");
                        }
                        BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                        if (!bt.Has("Door"))
                        {
                            ed.WriteMessage("\nDoor does not Exist");
                            return;
                        }
                        BlockTableRecord blkDef = (BlockTableRecord)tr.GetObject(bt["Door"], OpenMode.ForRead);

                        UnicodeEncoding uEncode = new UnicodeEncoding();
                        // create block preview icon
                        ads_queueexpr(uEncode.GetBytes("(COMMAND \"_.BLOCKICON\" \"Door\" )\n"));
                        try
                        {
                            System.Drawing.Bitmap blkImg = blkDef.PreviewIcon;
                            blkImg.Save("c:\\Test\\Door.bmp");
                        }
                        catch
                        {
                            throw new System.Exception("Impossible to save block preview icon!");
                        }

                        ObjectId defId = ObjectId.Null;

                        RasterImageDef rid = new RasterImageDef();
                     
                        rid.SourceFileName = "c:\\Test\\Door.png";

                        // Load it

                        rid.Load();
                        dict.UpgradeOpen();
                  
                            defId = dict.SetAt("Door", rid);             

                        // Let the transaction know
                        
                        tr.AddNewlyCreatedDBObject(rid, true);

                        // Create the raster image that references the definition
                        defId = dict.GetAt("Door");
                        RasterImage ri = new RasterImage();

                        //ri.Name = "Door";//optional
                        ri.ImageDefId = defId;                       
                        ri.ShowImage = true;
                        Matrix3d ucs = ed.CurrentUserCoordinateSystem;
                        Point3d pt = Point3d.Origin;
                        Vector3d xAxis = new Vector3d(1, 0, 0);
                        Vector3d yAxis = new Vector3d(0, 1, 0);
                        ri.Orientation =
                          new CoordinateSystem3d(
                            pt.TransformBy(ucs),
                            xAxis.TransformBy(ucs),
                            yAxis.TransformBy(ucs)
                          );
                        ri.SetClipBoundaryToWholeImage();
                        btr.AppendEntity(ri);
                        tr.AddNewlyCreatedDBObject(ri, true);

                        // Create a reactor between the RasterImage and the
                        // RasterImageDef to avoid the "unreferenced" 
                        // warning in the XRef palette

                        RasterImage.EnableReactors(true);
                        ri.AssociateRasterDef(rid);

                        tr.Commit();
                    }
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message );
            }
            finally
            {
                // empty code block
            }
        }
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2014 18:51:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4881998#M45079</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2014-03-12T18:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to put a  block  into image?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4883182#M45080</link>
      <description>hi thank you&lt;BR /&gt;what's the " accore.dll"? where can i download it?</description>
      <pubDate>Thu, 13 Mar 2014 10:14:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4883182#M45080</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-13T10:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to put a  block  into image?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4884220#M45081</link>
      <description>if you in A2012 or higher reqiure reference to&lt;BR /&gt;accoremgd.dll from acad folder, nothing else</description>
      <pubDate>Thu, 13 Mar 2014 16:25:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4884220#M45081</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2014-03-13T16:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to put a  block  into image?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4888862#M45082</link>
      <description>Hi Hallex, thank you for your reply! actually，I wan't to do like this. I choose some entity in dwg ,then i put these entity into a image. with C# Code how can i do it ? is it possible to do?</description>
      <pubDate>Sun, 16 Mar 2014 05:12:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4888862#M45082</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-16T05:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to put a  block  into image?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4888874#M45083</link>
      <description>&lt;P&gt;&lt;SPAN class="hps"&gt;You can create&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;a block of&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;this entity&lt;/SPAN&gt;&lt;SPAN&gt;, and then use&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;the same code&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;unfortunately&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;I do not have&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;time&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;for this job&lt;/SPAN&gt;&lt;SPAN&gt;, try&lt;/SPAN&gt; it &lt;SPAN class="hps"&gt;yourself&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Mar 2014 06:09:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4888874#M45083</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2014-03-16T06:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to put a  block  into image?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4889014#M45084</link>
      <description>Hi hellax, thank you your reply! i try to run your code, unfortunately I I get the error "ACAD_IMAGE_DICT does not Exist"! what should i do? i try to create a ACAD_IMAGE_DICT DBDictionary ,then run again ,the applicaion collapse !! my code like this DBDictionary IMAGEDict; //************* my add code try { IMAGEDict = (DBDictionary)tr.GetObject(namedDic.GetAt("ACAD_IMAGE_DICT"), OpenMode.ForRead); } catch { IMAGEDict = new DBDictionary(); namedDic.SetAt("ACAD_IMAGE_DICT", IMAGEDict); tr.AddNewlyCreatedDBObject(IMAGEDict, true); } if (!namedDic.Contains("ACAD_IMAGE_DICT")) { ed.WriteMessage("\nACAD_IMAGE_DICT does not Exist"); return; } //*************************** what should i do? i need your help</description>
      <pubDate>Sun, 16 Mar 2014 12:20:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-put-a-block-into-image/m-p/4889014#M45084</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-16T12:20:51Z</dc:date>
    </item>
  </channel>
</rss>

