还是要多休息,
用了甲方提供的项目样板,里面预设的设计说明图幅和项目对不上,
调比例,导入CAD都碰到了不同的问题,于是直接上代码
下面代码可以框选注释文字,进行整体缩放,
没有考虑文字类型的重命名,使用的时候要注意将文字先复制到一个空项目,缩放后改类型名称粘回去
[Transaction(TransactionMode.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
//框选TextNote
IList<Element> tnSet = uidoc.Selection.PickElementsByRectangle(new SelectionTextNoteFilter(), "框选 文字注释");
if (tnSet != null)
{
//选择一个点
var selPoint = uidoc.Selection.PickPoint("选择一个点");
if (selPoint != null)
{
using (Transaction tran = new Transaction(doc, "test"))
{
tran.Start();
//比例系数
double scaleFactor = 0.8;
IList<TextNoteType> textNoteTypes = new List<TextNoteType>();
foreach (TextNote tn in tnSet)
{
//修改注释位置
ElementTransformUtils.MoveElement(doc, tn.Id, (selPoint - tn.Coord) * (1 - scaleFactor));
//修改所有相关文字类型
bool tag = false;
foreach (TextNoteType type in textNoteTypes)
{
if (tn.TextNoteType.Id.Equals(type.Id))
tag = true;
}
if (tag)
continue;
double textSize = tn.TextNoteType.get_Parameter(BuiltInParameter.TEXT_SIZE).AsDouble();
tn.TextNoteType.get_Parameter(BuiltInParameter.TEXT_SIZE).Set(textSize * scaleFactor);
textNoteTypes.Add(tn.TextNoteType);
}
tran.Commit();
}
}
}
return Result.Succeeded;
}
}
class SelectionTextNoteFilter : ISelectionFilter
{
public bool AllowElement(Element elem)
{
if (elem is TextNote)
return true;
return false;
}
public bool AllowReference(Reference reference, XYZ position)
{
return false;
}
}