Revit二次开发_对段落进行整体缩放

还是要多休息,

 

用了甲方提供的项目样板,里面预设的设计说明图幅和项目对不上,

调比例,导入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;
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值