马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 csharp 于 2014-4-20 16:11 编辑
- [CommandMethod("AttOnOff")]
- public static void AttributeOn()
- {
- Document document = Application.DocumentManager.MdiActiveDocument;
- Editor editor = document.Editor;
- Database database = document.Database;
- Transaction transaction = document.TransactionManager.StartTransaction();
- TypedValue[] values = new TypedValue[]
- {
- new TypedValue((int) DxfCode.Start, "INSERT"),
- new TypedValue(66,1)
- };
- SelectionFilter filter = new SelectionFilter(values );
- using (transaction )
- try
- {
- PromptSelectionResult selectionResult = editor.GetSelection(filter);
- if (selectionResult.Status != PromptStatus.OK)
- {
- return;
- }
- ObjectId[] ids = selectionResult.Value.GetObjectIds();
- foreach (ObjectId id in ids)
- {
- BlockReference blockRef = (BlockReference)transaction.GetObject(id, OpenMode.ForRead );
- AttributeCollection attribute = blockRef.AttributeCollection;
- foreach (ObjectId att in attribute)
- {
- Entity attEntity = (Entity) transaction.GetObject(att, OpenMode.ForWrite);
- if (attEntity.Visible)
- {
- attEntity.Visible = false;
- }
- else
- {
- attEntity.Visible = true;
- }
- }
- }
- transaction.Commit();
- }
- catch (System.Exception ex)
- {
- editor.WriteMessage(ex.ToString() );
- }
-
- }
|