2

我正在尝试编写一种以编程方式将块导入图形的方法,以便我的 .NET 插件可以将这些块的实例放入图形中。现在我的方法是这样的:

        /// <summary>
        /// Method to programatically import all the blocks in a given list
        /// </summary>
        public static void ImportBlocks(string[] filesToTryToImport)
        {
            //Importing all the blocks
            for (int i = 0; i < filesToTryToImport.Count(); i++)
            {
                if (filesToTryToImport[i].EndsWith(".dwg"))
                {
                    try
                    {
                        Transaction tr = _database.TransactionManager.StartTransaction();
                        DocumentLock docLock = _activeDocument.LockDocument();
                        using (tr)
                        using (docLock)
                        {
                            BlockTable blkTbl = tr.GetObject(_database.BlockTableId, OpenMode.ForRead) as BlockTable;
                            // ToDo: Add files 
                        }
                    }
                    catch (Autodesk.AutoCAD.Runtime.Exception ex)
                    {
                        _editor.WriteMessage("\nError during copy: " + ex.Message);
                    }
                }
            }
        }

我想要的是文件路径在字符串数组 filesToTryToImport 中的所有块在我插入块时显示为选项

在此处输入图像描述

因此,例如,如果 One-Inch-Block 最初不在列表中,但它的文件路径作为字符串传递给传递给此方法的数组中的字符串,则它成为一个选项。

4

0 回答 0