乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 51|回复: 3

读取属性块出现的问题??

[复制链接]

5

主题

13

帖子

4

银币

初来乍到

Rank: 1

铜币
33
发表于 2011-10-20 17:06:00 | 显示全部楼层 |阅读模式
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk..ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
namespace MyApplication
{
    class DumpAttributes
    {
        [CommandMethod("LISTATT")]
        public void ListAttributes()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = HostApplicationServices.WorkingDatabase;
            Transaction trans = db.TransactionManager.StartTransaction();
            try
            {
                TypedValue[] filList = new TypedValue[1];
                filList[0] = new TypedValue((int)DxfCode.Start, "Insert");
                SelectionFilter filter = new SelectionFilter(filList);
                PromptSelectionOptions opts = new PromptSelectionOptions();
                opts.MessageForAdding = "Select block references:";
                PromptSelectionResult res = ed.GetSelection(opts, filter);
                if (res.Status != PromptStatus.OK)
                {
                    return;
                }
                SelectionSet selSet = res.Value;
                ObjectId[] idArray = selSet.GetObjectIds();
                foreach (ObjectId blkId in idArray)
                {
                    BlockReference blkRef = (BlockReference)trans.GetObject(blkId, OpenMode.ForRead);
                    BlockTableRecord btr = (BlockTableRecord)trans.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead);
                    ed.WriteMessage("\nBlock:" + btr.Name);
                    btr.Dispose();
                    AttributeCollection attCol = blkRef.AttributeCollection;
                    foreach (ObjectId attId in attCol)
                    {
                        AttributeReference attRef = (AttributeReference)trans.GetObject(attId, OpenMode.ForRead);
                        string str = ("\n Attribute Tag:" + attRef.Tag + "\n Attribute String" + attRef.TextString);
                        ed.WriteMessage(str);
                        trans.Commit();
                    }
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                ed.WriteMessage(ex.Message);
            }
            finally
            {
                trans.Dispose();
            }
        }        
    }
}
AttributeCollection attCol = blkRef.AttributeCollection;
对象的当前状态使该操作无效。为什麽??
回复

使用道具 举报

29

主题

503

帖子

8

银币

中流砥柱

Rank: 25

铜币
619
发表于 2011-10-21 17:49:00 | 显示全部楼层
屏蔽btr.dispose试试
回复

使用道具 举报

5

主题

13

帖子

4

银币

初来乍到

Rank: 1

铜币
33
发表于 2011-10-23 16:35:00 | 显示全部楼层
还是不行;
还是出现同样的问题。还是谢谢你的回答!
回复

使用道具 举报

4

主题

86

帖子

7

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
102
发表于 2011-10-25 16:29:00 | 显示全部楼层
解决了吗,把 trans.Commit();放在循环外面试试,我也不是很明白
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-15 17:36 , Processed in 0.578125 second(s), 60 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表