双击后尝试从命令行运行ATTEDIT并让它选择以前选择的项目。我已经拦截了双击事件并且可以运行ATTEDIT,但是当我尝试将位置传递给“ATTEDIT选择一个块:”时它没有做任何事情。但是当我再次点击该块时会工作。我以为这只是因为我的单位是十进制单位而不是建筑单位。但这并不奏效。这就是我所拥有的:
using Autodesk.AutoCAD;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
public class DoubleClickProcess
{
// This function gets called when a block reference is double clicked on. It then checks to see if the block reference
// that was double clicked on was double clicked
[CommandMethod("DOUBLECLICK", CommandFlags.UsePickSet)]
public void ContinueDoubleClick()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database database = HostApplicationServices.WorkingDatabase;
Editor ed = doc.Editor;
// Get the PickFirst selection set
PromptSelectionResult acSSPrompt;
acSSPrompt = ed.SelectImplied();
SelectionSet selRes;
// If the prompt status is OK, objects were selected before
// the command was started
if (acSSPrompt.Status == PromptStatus.OK)
{
selRes = acSSPrompt.Value;
Transaction tr = doc.TransactionManager.StartTransaction();
using (tr)
{
// Go through all of the objects that were selected...
ObjectId[] objIds = selRes.GetObjectIds();
foreach (ObjectId objId in objIds)
{
Entity theEnt = (Entity)tr.GetObject(objId, OpenMode.ForRead);
// They must be block references...
if (theEnt.GetType().Name.ToUpper() == "BLOCKREFERENCE")
{
BlockReference bRef = theEnt as BlockReference;
BlockTableRecord btr = null;
btr = tr.GetObject(bRef.DynamicBlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
if (bRef != null)
{
// If it is a specific block then we are interested in it
if (btr.Name.ToString().ToUpper() == "specific")
{
doc.SendStringToExecute("SomeCommand ", true, false, true);
}
else
{
// It's not one we're interested in so do what double clicking would normally do
String objPx = Autodesk.AutoCAD.Runtime.Converter.DistanceToString(bRef.Position.X);
objPx = objPx.Replace(" ", "-");
String objPy = Autodesk.AutoCAD.Runtime.Converter.DistanceToString(bRef.Position.Y);
objPy = objPy.Replace(" ", "-");
String objP = objPx +","+ objPy;
doc.SendStringToExecute("ATTEDIT "+ objP + " ", true, false, true);
}
}
}
theEnt.Dispose();
}
tr.Commit();
}
}
// Clear the PickFirst selection set
ObjectId[] idarrayEmpty = new ObjectId[0];
ed.SetImpliedSelection(idarrayEmpty);
}
}
}
键入鼠标的架构位置(101'-6-7 / 8“,89'-5-1 / 2”),但如果键入块的实际位置,则不会选择阻止属性。
答案 0 :(得分:0)
我相信它应该适用于SetImpliedSelection:
SelectionSet selset = SelectionSet.FromObjectIds(new ObjectId[] { bRef.ObjectId });
ed.SetImpliedSelection(selset);
doc.SendStringToExecute("ATTEDIT ", true, false, true);