using Autodesk.AutoCAD.ApplicationServices;
using Acap = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using IFoxCAD.Cad;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Windows;
using System.Runtime.InteropServices;
namespace DYH.Demo
{
public class ShiQuXianChang
{
//目标,选择一条线,点击文字,将线的长度赋值到文字上;
[CommandMethod("SQXC")]
public void SQXC()
{
//建事务
using var tr = new DBTrans();
//选择对象
var r1 = Env.Editor.GetEntity("\n选择一条线");
if (r1.Status == PromptStatus.OK)//如果选择到了对象
{
var ent1 = tr.GetObject<Entity>(r1.ObjectId);//获取对象实体
if (ent1 is Curve cur)//如果对象是线
{
var length = cur.GetLength() / 1000;//获取长度;获取到的是毫米,转为m除以1000;
var r2 = Env.Editor.GetEntity("\n选择要赋值的文字");//提示用户选择文字
if (r2.Status == PromptStatus.OK)//如果用户选到对象
{
var ent2 = tr.GetObject<Entity>(r2.ObjectId, OpenMode.ForWrite);//拿到对象;因为要赋值所以为ForWrite可写模式
if (ent2 is DBText text)//如果选到的对象是文字
{
text.TextString = "长度为:" + length.ToString("0.00") + "m";//按格式赋值并保留两位小数
}
}
}
}
}
}
}
武汉格发信息技术有限公司,格发许可优化管理系统可以帮你评估贵公司软件许可的真实需求,再低成本合规性管理软件许可,帮助贵司提高软件投资回报率,为软件采购、使用提供科学决策依据。支持的软件有: CAD,CAE,PDM,PLM,Catia,Ugnx, AutoCAD, Pro/E, Solidworks ,Hyperworks, Protel,CAXA,OpenWorks LandMark,MATLAB,Enovia,Winchill,TeamCenter,MathCAD,Ansys, Abaqus,ls-dyna, Fluent, MSC,Bentley,License,UG,ug,catia,Dassault Systèmes,AutoDesk,Altair,autocad,PTC,SolidWorks,Ansys,Siemens PLM Software,Paradigm,Mathworks,Borland,AVEVA,ESRI,hP,Solibri,Progman,Leica,Cadence,IBM,SIMULIA,Citrix,Sybase,Schlumberger,MSC Products...