乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 98|回复: 5

标签行长度

[复制链接]

12

主题

29

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
77
发表于 2019-1-31 03:25:35 | 显示全部楼层 |阅读模式
我想用它的长度标记一行,以便文本高度可以在运行时中与行的长度成比例地调整。
为此,我编写了以下代码,但我的问题是文本高度保持在“标准”文本样式的常量默认值(TextSize=0.2)上,并且不会更改。
请建议我 .
  1.    private static void AddLine_Blue(double x1,double y1,double x2,double y2)
  2.         {
  3.             // Get the current document and database
  4.             Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  5.             Database acCurDb = acDoc.Database;
  6.             // Start a transaction
  7.             using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  8.             {
  9.                 // Open the Block table for read
  10.                 BlockTable acBlkTbl;
  11.                 acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
  12.                                                 OpenMode.ForRead) as BlockTable;
  13.                 // Open the Block table record Model space for write
  14.                 BlockTableRecord acBlkTblRec;
  15.                 acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
  16.                                                 OpenMode.ForWrite) as BlockTableRecord;
  17.                
  18.                 double line_length;
  19.                 double line_angle;
  20.                 using (Line acLine = new Line(new Point3d(x1, y1, 0),
  21.                                               new Point3d(x2, y2, 0)))
  22.                 {
  23.                     // Add the new object to the block table record and the transaction
  24.                     acBlkTblRec.AppendEntity(acLine);
  25.                     acTrans.AddNewlyCreatedDBObject(acLine, true);
  26.                      line_length=Math.Round(acLine.Length,2);
  27.                      line_angle = Math.Round(acLine.Angle, 6);
  28.                      acLine.Color =Autodesk.AutoCAD.Colors. Color.FromColorIndex(ColorMethod.ByAci, 5);
  29.                     TextStyleTable myTextStyleTable = acTrans.GetObject(acDoc.Database.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
  30.                     if (!myTextStyleTable.Has("Arial"))  
  31.                     {
  32.                         myTextStyleTable.UpgradeOpen();
  33.                         TextStyleTableRecord myTextStyleTableRecord = new TextStyleTableRecord();
  34.                         myTextStyleTableRecord.FileName = "Arial.ttf";
  35.                         myTextStyleTableRecord.Name = "Arial";
  36.                         myTextStyleTableRecord.TextSize = Math.Round(line_length, 2) * 0.035;
  37.                         myTextStyleTable.Add(myTextStyleTableRecord);
  38.                         acTrans.AddNewlyCreatedDBObject(myTextStyleTableRecord, true);
  39.                         
  40.                     }
  41.                                                 else
  42.                                                 {
  43.                                                    myTextStyleTableRecord.TextSize = Math.Round(line_length, 2) * 0.035;
  44.                                                 }
  45.                     var curTextstyle = acCurDb.Textstyle;
  46.                     if (myTextStyleTable.Has("Arial") )
  47.                     {
  48.                         curTextstyle = myTextStyleTable["Arial"];
  49.                     }
  50.         
  51.    
  52.                     // Create a multiline text object
  53.                     using (MText acMText = new MText())
  54.                     {
  55.                         double xm = (x1 + x2) / 2;
  56.                         double ym = (y2 + y1) / 2;
  57.                         acMText.Location = new Point3d(xm, ym, 0);
  58.                        
  59.                         if (Math.Round(line_length, 2) - (int)(Math.Round(line_length, 2)) == 0)
  60.                         {
  61.                             acMText.Contents = Convert.ToString(line_length) + ".00";
  62.                         }
  63.                         else
  64.                         {
  65.                             acMText.Contents = Convert.ToString(line_length);
  66.                         }
  67.                         acMText.Rotation = line_angle;
  68.                         acMText.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 3);
  69.                         acMText.Attachment = AttachmentPoint.BottomCenter;
  70.                         acMText.SetDatabaseDefaults();
  71.                         acMText.TextStyleId = curTextstyle;
  72.                         acMText.Height = 0.035 * line_length;
  73.                         acBlkTblRec.AppendEntity(acMText);
  74.                         acTrans.AddNewlyCreatedDBObject(acMText, true);
  75.                        
  76.                     }
  77.                 }
  78.                         
  79.                 // Save the new object to the database
  80.                 acTrans.Commit();
  81.             }
  82.         }

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2019-1-31 11:49:20 | 显示全部楼层
myTextStyleTableRecord.TextSize = 0;  我认为你需要这个能够改变高度
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2019-1-31 15:22:11 | 显示全部楼层
此外,为了补充Byrco指出的内容,我可能记错了,但您可能需要在设置高度之前附加多行文字实体。
回复

使用道具 举报

0

主题

3

帖子

1

银币

初来乍到

Rank: 1

铜币
3
发表于 2019-2-1 19:37:00 | 显示全部楼层
tsr.FileName=Environment.GetEnvironmentVariable("SystemRoot") + @"\Fonts\"+sFilename;
当我制作字体时,我也添加了路径,这可能就是为什么你得到标准字体的原因。
回复

使用道具 举报

12

主题

29

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
77
发表于 2019-2-21 10:13:18 | 显示全部楼层
希望不会太晚。您应该将以下行更改为
  1. acMText.Height = 0.035 * line_length;

在您的代码中,使用下一个
  1. acMText.TextHeight = 0.035 * line_length;

文本高度
控制文本大小(高度)。
回复

使用道具 举报

12

主题

29

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
77
发表于 2019-3-7 11:14:31 | 显示全部楼层
嗨pera,
这正是我的问题,已经解决了。
谢谢你的建议。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-4 08:47 , Processed in 0.310330 second(s), 64 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表