栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

cad文字宽度因子

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

cad文字宽度因子

using System;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Geometry;

using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(AttributeWidthFactor.MyCommands))]

namespace AttributeWidthFactor

{

public class MyCommands

{

[CommandMethod("AttWidth")]

public static void SetAttrWidthFactor()

{

Document dwg = Application.DocumentManager.MdiActiveDocument;

Editor ed = dwg.Editor;

//Pick an attributereference in a block

PromptNestedEntityOptions opt = new

PromptNestedEntityOptions("nPick an attribute:");

PromptNestedEntityResult res = ed.GetNestedEntity(opt);

if (res.Status == PromptStatus.OK)

{

if (res.ObjectId.ObjectClass.DxfName.ToUpper() == "ATTRIB")

{

//Ask user to pick a distance as desired width for

//the attribute to fit in. Based on the block, the width

//could be a known value

PromptPointOptions popt = new

PromptPointOptions("nPick width base point:");

PromptPointResult pres = ed.GetPoint(popt);

if (pres.Status != PromptStatus.OK) return;

Point3d basePt = pres.Value;

PromptDistanceOptions dopt =

new PromptDistanceOptions("nPick width: ");

dopt.UseBasePoint = true;

dopt.BasePoint = basePt;

PromptDoubleResult dres = ed.GetDistance(dopt);

if (dres.Status != PromptStatus.OK) return;

//This is the width we want to fit the attribute text's width

double w = dres.Value;

using (Transaction tran =

dwg.TransactionManager.StartTransaction())

{

AttributeReference att = (AttributeReference)tran.GetObject(

res.ObjectId, OpenMode.ForWrite);

//Get attribute's width, assuming it is placed horizontally

double aw = Math.Abs(att.GeometricExtents.MaxPoint.X

- att.GeometricExtents.MinPoint.X);

//This is the WidthFactor

double factor = w / aw;

att.WidthFactor = factor;

tran.Commit();

}

}

else

{

Application.ShowAlertDialog("Not an attribute!");

}

}

}

}

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/908136.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号