本帖最后由 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。
但文字的大小、对齐点什么的还是在原来的位置。
已经解决了,完整代码:
- public static void SetBlockScale (string blockName, double scale)
- {
- Document doc = AcadApp. DocumentManager. MdiActiveDocument;
- Database db = doc. Database;
- using (DocumentLock docLock = doc. LockDocument( ))
- using (Transaction tr = db. TransactionManager. StartTransaction( ))
- {
- BlockTable bt = tr. GetObject(db. BlockTableId, OpenMode. ForRead) as BlockTable;
- if (bt. Has(blockName))
- {
- BlockTableRecord btr = tr. GetObject(bt [blockName], OpenMode. ForRead) as BlockTableRecord;
- ObjectIdCollection ids = btr. GetBlockReferenceIds(true, true);
- foreach (ObjectId id in ids)
- {
- 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);
- }
- }
- tr. Commit( );
- }
- }
- }
|