明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1355|回复: 2

[图元] 块引用BlockReference的ScaleFactors无法修改块内的属性比例?

[复制链接]
发表于 2018-4-16 18:26 | 显示全部楼层 |阅读模式
本帖最后由 zjh2785 于 2018-4-16 19:08 编辑

BlockReference br = tr. GetObject(id, OpenMode. ForWrite) as BlockReference;
br. ScaleFactors = new Scale3d(100, 100, 1);

命令完成之后 块里面的直线、填充图案这些可以按比例缩放了,而且CAD的属性面板里面也显示成了100,100,1。
但文字的大小、对齐点什么的还是在原来的位置。


已经解决了,完整代码:
  1.         public static void SetBlockScale (string blockName, double scale)
  2.         {
  3.             Document doc = AcadApp. DocumentManager. MdiActiveDocument;
  4.             Database db = doc. Database;
  5.             using (DocumentLock docLock = doc. LockDocument( ))
  6.             using (Transaction tr = db. TransactionManager. StartTransaction( ))
  7.             {
  8.                 BlockTable bt = tr. GetObject(db. BlockTableId, OpenMode. ForRead) as BlockTable;
  9.                 if (bt. Has(blockName))
  10.                 {
  11.                     BlockTableRecord btr = tr. GetObject(bt [blockName], OpenMode. ForRead) as BlockTableRecord;
  12.                     ObjectIdCollection ids = btr. GetBlockReferenceIds(true, true);
  13.                     foreach (ObjectId id in ids)
  14.                     {
  15.                         BlockReference br = tr. GetObject(id, OpenMode. ForWrite) as BlockReference;
  16.                         double oldScale = br.ScaleFactors.X;
  17.                         br. ScaleFactors = new Scale3d(scale, scale, 1);
  18.                         foreach (ObjectId i in br. AttributeCollection)
  19.                         {
  20.                             AttributeReference att = tr. GetObject(i, OpenMode. ForWrite) as AttributeReference;
  21.                             Matrix3d mat = Matrix3d. Scaling( scale / oldScale, br. Position);
  22.                             att. TransformBy(mat);
  23.                         }
  24.                     }
  25.                     tr. Commit( );
  26.                 }
  27.             }
  28.         }

 楼主| 发表于 2018-4-16 19:01 | 显示全部楼层
本帖最后由 zjh2785 于 2018-4-16 19:03 编辑

解决了                     
BlockReference br = tr. GetObject(id, OpenMode. ForWrite) as BlockReference;double oldScale = br.ScaleFactors.X;
br. ScaleFactors = new Scale3d(scale, scale, 1);
foreach (ObjectId i in br. AttributeCollection)
{
    AttributeReference att = tr. GetObject(i, OpenMode. ForWrite) as AttributeReference;
    Matrix3d mat = Matrix3d. Scaling( scale / oldScale, br. Position);
   att. TransformBy(mat);
}



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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-25 15:42 , Processed in 0.283214 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表