autocad.netQQ群:193522571属性块中属性文字宽度比例自动调整到格子宽度内,比例因子小于标准比例因子的自动设置为标准比例因子
#region 属性自动缩进 /// <summary> /// 属性比例因子设置 /// </summary> /// <param name="br">属性块参照</param> /// <param name="lstWidth">属性宽度集合</param> /// <param name="Factor">标准比例因子</param> public static void setAttributeReferenceWidth(this BlockReference br, List<double> lstWidth,double Factor) { //定义事务对象 var trans = br.Id.Database.TransactionManager; //初始化计数器 int i = 0; //在每个属性中循环 foreach (ObjectId attId in br.AttributeCollection) { // 获取块参照属性对象 AttributeReference attRef = (AttributeReference)trans.GetObject(attId, OpenMode.ForRead); //打开能属性对象 attRef.UpgradeOpen(); //如果属性对象不为空 if (attRef.TextString != "") { //属性比例因子 double nowFactor = attRef.WidthFactor; //属性宽度 double attributeWidth = Math.Abs(attRef.GeometricExtents.MaxPoint.X - attRef.GeometricExtents.MinPoint.X); attributeWidth=attributeWidth/nowFactor; //标准宽度 double standardWidth=attributeWidth*Factor; //如果属性宽度超出了指定宽度则修改属性宽度因子 if (standardWidth > lstWidth[i]-2) { double calFactor = (lstWidth[i]-2)/ standardWidth; attRef.WidthFactor = Factor * calFactor; } //如果未超出则将比例因子统一为标准比例因子 else { attRef.WidthFactor = Factor; } } attRef.DowngradeOpen(); i++; } } #endregion