乐筑天下

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

Bricscad ET Chspace like command

[复制链接]

14

主题

67

帖子

8

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
122
发表于 2010-4-10 08:28:59 | 显示全部楼层 |阅读模式
我需要帮助。我正在尝试用Acad Express Tools Chang Space命令将实体从MS复制到PS,运气不佳。幸运的是,我使用VBA是因为它易于调试/运行。我想出了复制和旋转视图扭曲,但我似乎不能让transformcoordinates像我期望的那样工作。我需要将模型中的文本插入点转换到acadPViewport中的相同位置。有人在布里斯卡德做到了吗?我之所以说Bricscad,是因为扭曲似乎没有像我预期的那样工作,或者没有像样本Acad代码显示的那样工作。求助于方向目标。我一直有再生问题,当它从Mspace切换到Pspace可能会造成严重破坏。任何建议将不胜感激。

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

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

使用道具 举报

0

主题

3

帖子

3

银币

初来乍到

Rank: 1

铜币
4
发表于 2010-4-10 12:27:30 | 显示全部楼层
使用现有的快递工具会更容易。 如果您在Google上搜索“chspace.lsp”,则很容易获得。 allexperts.com 的版本来自Autodesk Australia,版权声明允许免费使用。 请注意,这与 Autocad 美国版本中的 Express 工具中的版本不同。 还有兰迪·金茨利(Randy Kintzley)发布的版本的副本,这就是美国快递工具中的内容。
回复

使用道具 举报

0

主题

13

帖子

6

银币

初来乍到

Rank: 1

铜币
14
发表于 2010-4-10 16:48:13 | 显示全部楼层
我认为这必须要做到,基本上我可以用base复制并实现同样的效果。如果有人能使用com、VBA或Vlax将MSpace坐标转换为PSace坐标,我仍感兴趣。
回复

使用道具 举报

0

主题

3

帖子

1

银币

初来乍到

Rank: 1

铜币
3
发表于 2010-4-10 23:47:36 | 显示全部楼层
嗨,杰瑞,
我的VBA咬,所以也许你可以翻译一下。我在几个端口上测试了这个,其中一些端口是旋转的(dview ),看起来工作正常..YMMV,但我希望它让你开始。
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using System.Diagnostics;
  7. using BricscadApp;
  8. using BricscadDb;
  9. using RxNet.ApplicationServices;
  10. using RxNet.Runtime;
  11. using RxNet.Geometry;
  12. using RxNet.RxGlobal;
  13. namespace Bricscad
  14. {
  15.   public static class Commands
  16.   {
  17.     // from papaerspace vp is active
  18.     [CommandMethod("doit")]
  19.     public static void test01()
  20.     {
  21.       try
  22.       {
  23.         // get app stuff
  24.         var app = Application.AcadApplication as AcadApplication;
  25.         var doc = app.ActiveDocument;
  26.         var mspace = doc.ModelSpace;
  27.         GlobalFunctions.MSpace();
  28.         //select an entity and copy
  29.         object opnt, oent, pairs = null;
  30.         doc.Utility.GetEntity(out oent, out opnt, "Select Entity");
  31.         AcadEntity entity = oent as AcadEntity;
  32.         AcadEntity[] ocol = { entity };
  33.         object[] ncol = doc.CopyObjects((object)ocol, doc.PaperSpace, ref pairs);
  34.         AcadEntity nentity = ncol[0] as AcadEntity;
  35.         // get the center of both entities bounding box
  36.         Point3d cenent = getBBCenter(entity);
  37.         Point3d cennent = getBBCenter(nentity);
  38.         // scale
  39.         nentity.ScaleEntity(cennent.ToArray(), doc.ActivePViewport.CustomScale);
  40.         // rotate
  41.         nentity.Rotate(cennent.ToArray(), doc.ActivePViewport.TwistAngle);
  42.         // move
  43.         nentity.Move(cennent.ToArray(),
  44.           doc.Utility.TranslateCoordinates(
  45.           cenent.ToArray(), AcCoordinateSystem.acUCS, AcCoordinateSystem.acPaperSpaceDCS, 0));
  46.         // delete
  47.         entity.Delete();
  48.         GlobalFunctions.PSpace();
  49.       }
  50.       catch (System.Exception ex)
  51.       {
  52.         GlobalFunctions.Printf("\n{0}\n{1}",
  53.          ex.Message, ex.StackTrace);
  54.       }
  55.     }
  56.     static Point3d getBBCenter(AcadEntity ent)
  57.     {
  58.       object omin, omax;
  59.       ent.GetBoundingBox(out omin, out omax);
  60.       Point3d min = new Point3d((double[])omin);
  61.       Point3d max = new Point3d((double[])omax);
  62.       return new Point3d(min[0] + ((max[0] - min[0]) / 2),
  63.                          min[1] + ((max[1] - min[1]) / 2), 0);
  64.     }
  65.   }
  66. }

回复

使用道具 举报

0

主题

6

帖子

2

银币

初来乍到

Rank: 1

铜币
6
发表于 2010-4-10 23:50:26 | 显示全部楼层
突出显示的项目从MS克隆到PS,VP扭曲。。。
回复

使用道具 举报

0

主题

11

帖子

3

银币

初来乍到

Rank: 1

铜币
11
发表于 2010-4-11 00:21:34 | 显示全部楼层
适用于选择集,您可能希望过滤暗淡
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using System.Diagnostics;
  7. using BricscadApp;
  8. using BricscadDb;
  9. using RxNet.ApplicationServices;
  10. using RxNet.Runtime;
  11. using RxNet.Geometry;
  12. using RxNet.RxGlobal;
  13. namespace Bricscad
  14. {
  15.   public static class Commands
  16.   {
  17.     // from papaerspace vp is active
  18.     [CommandMethod("doit")]
  19.     public static void test01()
  20.     {
  21.       AcadSelectionSet selection = null;
  22.       try
  23.       {
  24.         // get app stuff
  25.         var app = Application.AcadApplication as AcadApplication;
  26.         var doc = app.ActiveDocument;
  27.         GlobalFunctions.MSpace();
  28.         selection = doc.SelectionSets.Add("MySel");
  29.         selection.SelectOnScreen();
  30.         foreach (AcadObject o in selection)
  31.         {
  32.           AcadEntity e = o as AcadEntity;
  33.           if (e != null)
  34.             cloneToPspace(e, doc);
  35.         }
  36.         foreach (AcadObject o in selection)
  37.         {
  38.           AcadEntity e = o as AcadEntity;
  39.           if (e != null)
  40.             e.Delete();
  41.         }
  42.         GlobalFunctions.PSpace();
  43.       }
  44.       catch (System.Exception ex)
  45.       {
  46.         GlobalFunctions.Printf("\n{0}\n{1}",
  47.          ex.Message, ex.StackTrace);
  48.       }
  49.       finally
  50.       {
  51.         selection.Delete();
  52.       }
  53.     }
  54.     static void cloneToPspace(AcadEntity entity, AcadDocument doc)
  55.     {
  56.       try
  57.       {
  58.         object pairs = null;
  59.         AcadEntity[] ocol = { entity };
  60.         object[] ncol = doc.CopyObjects((object)ocol, doc.PaperSpace, ref pairs);
  61.         AcadEntity nentity = ncol[0] as AcadEntity;
  62.         // get the center of both entities bounding box
  63.         Point3d cenent = getBBCenter(entity);
  64.         Point3d cennent = getBBCenter(nentity);
  65.         // scale
  66.         nentity.ScaleEntity(cennent.ToArray(), doc.ActivePViewport.CustomScale);
  67.         // rotate
  68.         nentity.Rotate(cennent.ToArray(), doc.ActivePViewport.TwistAngle);
  69.         // move
  70.         nentity.Move(cennent.ToArray(),
  71.           doc.Utility.TranslateCoordinates(
  72.           cenent.ToArray(), AcCoordinateSystem.acUCS, AcCoordinateSystem.acPaperSpaceDCS, 0));
  73.       }
  74.       catch {/*hehe*/}
  75.     }
  76.     static Point3d getBBCenter(AcadEntity ent)
  77.     {
  78.       object omin, omax;
  79.       ent.GetBoundingBox(out omin, out omax);
  80.       Point3d min = new Point3d((double[])omin);
  81.       Point3d max = new Point3d((double[])omax);
  82.       return new Point3d(min[0] + ((max[0] - min[0]) / 2),
  83.                          min[1] + ((max[1] - min[1]) / 2), 0);
  84.     }
  85.   }
  86. }

回复

使用道具 举报

0

主题

11

帖子

5

银币

初来乍到

Rank: 1

铜币
12
发表于 2010-4-11 05:46:16 | 显示全部楼层
小伙子,你做了全面的命令。 看起来不错。没有尝试过你的代码,因为我正处于特定用途的中间。 我得到了一张测量地图,上面有所有的注释(方位角,距离,注释......),需要分成3张,有两个不同的比例和重叠的区域。有些文本需要保持水平,有些是对齐的,有些是1:50,有些是1:100。无论如何,这是我处理过的VBA中的代码;
  1. Sub msTxt2ps()
  2.       Dim pp As Variant
  3.       Dim pt1 As Variant
  4.       Dim ent As AcadEntity
  5.       Dim aTxt As AcadText
  6.       Dim mTxt As AcadMText
  7.       Dim nTxt As AcadText
  8.       Dim amTxt As AcadMText
  9.       Dim mAtt As Variant
  10.       
  11.       Dim ss As AcadSelectionSet
  12.       Dim Code(0) As Integer
  13.       Dim Val(0) As Variant
  14.       Set ss = ThisDrawing.ActiveSelectionSet
  15.       ss.Clear
  16.           Code(0) = 0
  17.           Val(0) = "TEXT,MTEXT"
  18.          
  19.      Dim styl As AcadTextStyle
  20.      Set styl = ThisDrawing.ActiveTextStyle
  21.       
  22.       Dim ps As AcadPViewport
  23.       Set ps = ThisDrawing.ActivePViewport
  24.       pss = ps.CustomScale
  25.       psrot = ps.TwistAngle
  26.       
  27.       ss.SelectOnScreen Code, Val
  28.       ThisDrawing.ActiveSpace = acPaperSpace
  29. For Each ent In ss
  30.       If TypeOf ent Is AcadText Then
  31.           Set aTxt = ent
  32.           pt1 = aTxt.InsertionPoint
  33.           pt1 = transPt(pt1)
  34.           rot = Math.Round(aTxt.Rotation, 5)
  35.           pt2 = aTxt.TextAlignmentPoint
  36.           pt2 = transPt(pt2)
  37.           txtht = aTxt.Height * pss
  38.           Set nTxt = ThisDrawing.PaperSpace.AddText(aTxt.TextString, pt1, txtht)
  39.           nTxt.Alignment = aTxt.Alignment
  40.           nTxt.TextAlignmentPoint = pt2
  41.           nTxt.InsertionPoint = pt1
  42.                If rot = 0# Then
  43.                nTxt.Rotation = 0#
  44.                Else
  45.                nTxt.Rotation = rot + psrot
  46.                End If
  47.           Else
  48.           Set mTxt = ent
  49.           pt1 = mTxt.InsertionPoint
  50.           pt1 = transPt(pt1)
  51.           rot = Math.Round(mTxt.Rotation, 5)
  52.           wid = mTxt.Width
  53.           mAtt = mTxt.AttachmentPoint
  54.           Set amTxt = ThisDrawing.PaperSpace.AddMText(pt1, wid, mTxt.TextString)
  55.           amTxt.AttachmentPoint = mAtt
  56.                If rot = 0# Then
  57.                amTxt.Rotation = 0#
  58.                Else
  59.                amTxt.Rotation = rot + psrot
  60.                End If
  61.           amTxt.StyleName = styl.Name
  62.           amTxt.ScaleEntity pt1, pss
  63.      End If
  64. Next
  65.       
  66. End Sub
  67. Function transPt(ByRef pt1 As Variant) As Variant
  68.      pt1 = ThisDrawing.Utility.TranslateCoordinates(pt1, acUCS, acDisplayDCS, 0)
  69.      pt1 = ThisDrawing.Utility.TranslateCoordinates(pt1, acDisplayDCS, acPaperSpaceDCS, 0)
  70.      transPt = pt1
  71. End Function

有趣的是,您不必将自定义比例因子应用于 Mtext.Width。至少在我看来是这样。
我将审查你的代码,以便将来我可以C#一些Mspace2Pspace工具。 谢谢。
回复

使用道具 举报

0

主题

8

帖子

5

银币

初来乍到

Rank: 1

铜币
13
发表于 2010-4-11 07:23:57 | 显示全部楼层
干得漂亮!我看到您正在创建新实体,而我正在使用复制对象函数...为什么我需要缩放对象。
BTY,我只使用C#,因为我对它更满意。没有理由不能将其移植到VBA...它的所有 COM
回复

使用道具 举报

0

主题

8

帖子

4

银币

初来乍到

Rank: 1

铜币
10
发表于 2010-4-12 05:19:28 | 显示全部楼层
我之所以创建新对象,是因为我想到了将它们放在新图层(当前图层)上的最简单方法,我不想删除原始对象,只需关闭它们,因为同一文本可能需要复制到不同的布局。出于同样的原因,我的下一个项目是将纪念碑符号(块)转换成PS。这将是简单的,除了符号包含擦除实体。复制它们似乎无法维持提款顺序。一旦他们进入纸面空间,将他们带到前台似乎取得了喜忧参半的成功。我一定忽略了什么。无论如何,必须尽快完成此映射,因此必须等待编写例程。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-1 19:23 , Processed in 0.276673 second(s), 70 queries .

© 2020-2025 乐筑天下

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