奥特加 .SendStringToExicute ATTEDIT 未选择所选对象
本文关键字:对象 选择 SendStringToExicute ATTEDIT 奥特 | 更新日期: 2023-09-27 18:31:29
双击后尝试从命令行运行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"),但如果键入块的实际位置,则不会选择块属性。
我相信它应该与SetImpliedSelection一起使用:
SelectionSet selset = SelectionSet.FromObjectIds(new ObjectId[] { bRef.ObjectId });
ed.SetImpliedSelection(selset);
doc.SendStringToExecute("ATTEDIT ", true, false, true);