還是要多休息,
用了甲方提供的項目樣板,裏面預設的設計說明圖幅和項目對不上,
調比例,導入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;
}
}