我必须使用 C# 在 AutoCAD 标题栏中插入徽标?

问题描述 投票:0回答:2

我必须在 AutoCAD 标题栏中的特定插入点处插入图像及其宽度和高度,以便我可以在使用该模板时使用缩放功能。我使用了 RasterImage 但没有得到正确的结果。

请编写代码以在 AutoCAD 中模型空间的特定点插入图像。

c# autocad
2个回答
2
投票

我在Autodesk论坛回答了同样的问题。

        static void InsertImage(Database db, string fileName, Point3d position, double width, double height)
    {
        string imgName = System.IO.Path.GetFileNameWithoutExtension(fileName);
        using (var tr = db.TransactionManager.StartTransaction())
        {
            var imgDictId = RasterImageDef.GetImageDictionary(db);
            if (imgDictId.IsNull)
                imgDictId = RasterImageDef.CreateImageDictionary(db);
            var imgDict = (DBDictionary)tr.GetObject(imgDictId, OpenMode.ForRead);
            ObjectId imgDefId;
            RasterImageDef imgDef;
            if (imgDict.Contains(imgName))
            {
                imgDefId = imgDict.GetAt(imgName);
                imgDef = (RasterImageDef)tr.GetObject(imgDefId, OpenMode.ForRead);
            }
            else
            {
                imgDef = new RasterImageDef();
                imgDef.SourceFileName = fileName;
                imgDef.Load();
                tr.GetObject(imgDictId, OpenMode.ForWrite);
                imgDefId = imgDict.SetAt(imgName, imgDef);
                tr.AddNewlyCreatedDBObject(imgDef, true);
            }

            var modelSpace = (BlockTableRecord)tr.GetObject(
                SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite);

            var raster = new RasterImage();
            raster.ImageDefId = imgDefId;
            var coordSystem = new CoordinateSystem3d(
                position, Vector3d.XAxis * width, Vector3d.YAxis * height);
            raster.Orientation = coordSystem;
            modelSpace.AppendEntity(raster);
            tr.AddNewlyCreatedDBObject(raster, true);
            RasterImage.EnableReactors(true);
            raster.AssociateRasterDef(imgDef);
            tr.Commit();
        }
    }

0
投票

任何人都可以向我展示同样的事情,只是在没有文件的情况下进行。例如,我有一个包含图像的 URL。我想提取 URL 的内容(字节数组/流/任何内容)并使用它来将图像永久存储在 dwg 文件中,而不是 xfref'ing 文件。

非常感谢帮助!

© www.soinside.com 2019 - 2024. All rights reserved.