zoukankan      html  css  js  c++  java
  • CAD.NET调整属性块中文字宽度

    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(" Pick 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(" Pick width base point:");
                        PromptPointResult pres = ed.GetPoint(popt);
                        if (pres.Status != PromptStatus.OK) return;
                        Point3d basePt = pres.Value;

                        PromptDistanceOptions dopt = 
                            new PromptDistanceOptions(" Pick ");
                        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!");
                    }
                }
            }
        }
    }

  • 相关阅读:
    c 的内存分配与释放原则: 通常应遵循“谁malloc,谁free”的原则。
    总算知道怎样从ImageMagick生成的数据转换成HICON: MagickGetImageBlob & LookupIconIdFromDirectoryEx
    收藏:Non-direct与direct ByteBuffer区别
    java NIO 直接与非直接缓冲区
    [收藏]:[算法]LRU和LFU的区别
    异步IO的并发能力:backlog的配置很重要
    ByteBuffer: 当由一个byte[]来生成一个固定不变的ByteBuffer时,使用ByteBuffer.wrap(byte[]);
    ByteBuffer的allocate与allocateDirect2013-01-11
    Windows完成端口与Linux epoll技术简介
    Java并发——Fork/Join框架与ForkJoinPool
  • 原文地址:https://www.cnblogs.com/swtool/p/3832332.html
Copyright © 2011-2022 走看看