Bricscad ET Chspace-like命令
我需要帮助 ;我正在尝试编写Acad Express Tools Chang Space命令,用于将实体从MS复制到PS,但运气不佳 ;本人';m使用VBA,因为它';幸运的是,它易于调试/运行 ;我找到了复制和旋转到viewtwist的方法,但我可以#039;我似乎没有像预期的那样工作 ;我需要将模型中的文本插入点转换为acadPViewport中的相同点 ;有谁在Bricscad做到了这一点 ;我之所以说Bricscad,是因为它似乎并没有像我预期的那样工作,也没有像Acad代码示例所显示的那样工作 ;求助于方向-目标 ;当它从Mspace切换到Pspace时,我一直遇到再生问题,这可能会造成严重破坏 ;如有任何建议,我们将不胜感激。使用现有的express工具会更容易 ;如果你在谷歌上搜索';chspace.lsp' ;allexperts的版本。com来自Autodesk Australia,版权声明允许免费使用 ;请注意,这与美国版本的Autocad中的express tools中的版本不同 ;还有Randy Kintzley发布的版本副本,这是美国express tools中的版本。 我认为这将不得不做,基本上我可以复制与基地,并实现相同的。如果有人可以使用com、VBA或Vlax将MSpace坐标转换为PSace坐标,我仍然很感兴趣。 嗨,Jerry,我的VBA咬伤了,也许你可以翻译一下。我在几个端口进行了测试,其中一些端口进行了旋转(dview),它似乎可以工作。YMMV,但我希望它能让你开始
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
using BricscadApp;
using BricscadDb;
using RxNet.ApplicationServices;
using RxNet.Runtime;
using RxNet.Geometry;
using RxNet.RxGlobal;
namespace Bricscad
{
public static class Commands
{
// from papaerspace vp is active
public static void test01()
{
try
{
// get app stuff
var app = Application.AcadApplication as AcadApplication;
var doc = app.ActiveDocument;
var mspace = doc.ModelSpace;
GlobalFunctions.MSpace();
//select an entity and copy
object opnt, oent, pairs = null;
doc.Utility.GetEntity(out oent, out opnt, "Select Entity");
AcadEntity entity = oent as AcadEntity;
AcadEntity[] ocol = { entity };
object[] ncol = doc.CopyObjects((object)ocol, doc.PaperSpace, ref pairs);
AcadEntity nentity = ncol as AcadEntity;
// get the center of both entities bounding box
Point3d cenent = getBBCenter(entity);
Point3d cennent = getBBCenter(nentity);
// scale
nentity.ScaleEntity(cennent.ToArray(), doc.ActivePViewport.CustomScale);
// rotate
nentity.Rotate(cennent.ToArray(), doc.ActivePViewport.TwistAngle);
// move
nentity.Move(cennent.ToArray(),
doc.Utility.TranslateCoordinates(
cenent.ToArray(), AcCoordinateSystem.acUCS, AcCoordinateSystem.acPaperSpaceDCS, 0));
// delete
entity.Delete();
GlobalFunctions.PSpace();
}
catch (System.Exception ex)
{
GlobalFunctions.Printf("\n{0}\n{1}",
ex.Message, ex.StackTrace);
}
}
static Point3d getBBCenter(AcadEntity ent)
{
object omin, omax;
ent.GetBoundingBox(out omin, out omax);
Point3d min = new Point3d((double[])omin);
Point3d max = new Point3d((double[])omax);
return new Point3d(min + ((max - min) / 2),
min + ((max - min) / 2), 0);
}
}
}
突出显示的项目从MS克隆到PS,VP扭曲。。。 在选择集上工作时,您可能需要过滤DIMusing System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
using BricscadApp;
using BricscadDb;
using RxNet.ApplicationServices;
using RxNet.Runtime;
using RxNet.Geometry;
using RxNet.RxGlobal;
namespace Bricscad
{
public static class Commands
{
// from papaerspace vp is active
public static void test01()
{
AcadSelectionSet selection = null;
try
{
// get app stuff
var app = Application.AcadApplication as AcadApplication;
var doc = app.ActiveDocument;
GlobalFunctions.MSpace();
selection = doc.SelectionSets.Add("MySel");
selection.SelectOnScreen();
foreach (AcadObject o in selection)
{
AcadEntity e = o as AcadEntity;
if (e != null)
cloneToPspace(e, doc);
}
foreach (AcadObject o in selection)
{
AcadEntity e = o as AcadEntity;
if (e != null)
e.Delete();
}
GlobalFunctions.PSpace();
}
catch (System.Exception ex)
{
GlobalFunctions.Printf("\n{0}\n{1}",
ex.Message, ex.StackTrace);
}
finally
{
selection.Delete();
}
}
static void cloneToPspace(AcadEntity entity, AcadDocument doc)
{
try
{
object pairs = null;
AcadEntity[] ocol = { entity };
object[] ncol = doc.CopyObjects((object)ocol, doc.PaperSpace, ref pairs);
AcadEntity nentity = ncol as AcadEntity;
// get the center of both entities bounding box
Point3d cenent = getBBCenter(entity);
Point3d cennent = getBBCenter(nentity);
// scale
nentity.ScaleEntity(cennent.ToArray(), doc.ActivePViewport.CustomScale);
// rotate
nentity.Rotate(cennent.ToArray(), doc.ActivePViewport.TwistAngle);
// move
nentity.Move(cennent.ToArray(),
doc.Utility.TranslateCoordinates(
cenent.ToArray(), AcCoordinateSystem.acUCS, AcCoordinateSystem.acPaperSpaceDCS, 0));
}
catch {/*hehe*/}
}
static Point3d getBBCenter(AcadEntity ent)
{
object omin, omax;
ent.GetBoundingBox(out omin, out omax);
Point3d min = new Point3d((double[])omin);
Point3d max = new Point3d((double[])omax);
return new Point3d(min + ((max - min) / 2),
min + ((max - min) / 2), 0);
}
}
}
小子,你下达了全面的命令 ;看起来不错。哈文#039;我没有试过你的代码,因为我正处于一个特定的使用过程中 ;我得到了一张包含所有注释(方位、距离、注释等)的测量地图,需要将其分为3张,具有两个不同的比例和重叠区域。一些文本需要保持水平,一些对齐,一些1:50,一些1:100
Sub msTxt2ps()
Dim pp As Variant
Dim pt1 As Variant
Dim ent As AcadEntity
Dim aTxt As AcadText
Dim mTxt As AcadMText
Dim nTxt As AcadText
Dim amTxt As AcadMText
Dim mAtt As Variant
Dim ss As AcadSelectionSet
Dim Code(0) As Integer
Dim Val(0) As Variant
Set ss = ThisDrawing.ActiveSelectionSet
ss.Clear
Code(0) = 0
Val(0) = "TEXT,MTEXT"
Dim styl As AcadTextStyle
Set styl = ThisDrawing.ActiveTextStyle
Dim ps As AcadPViewport
Set ps = ThisDrawing.ActivePViewport
pss = ps.CustomScale
psrot = ps.TwistAngle
ss.SelectOnScreen Code, Val
ThisDrawing.ActiveSpace = acPaperSpace
For Each ent In ss
If TypeOf ent Is AcadText Then
Set aTxt = ent
pt1 = aTxt.InsertionPoint
pt1 = transPt(pt1)
rot = Math.Round(aTxt.Rotation, 5)
pt2 = aTxt.TextAlignmentPoint
pt2 = transPt(pt2)
txtht = aTxt.Height * pss
Set nTxt = ThisDrawing.PaperSpace.AddText(aTxt.TextString, pt1, txtht)
nTxt.Alignment = aTxt.Alignment
nTxt.TextAlignmentPoint = pt2
nTxt.InsertionPoint = pt1
If rot = 0# Then
nTxt.Rotation = 0#
Else
nTxt.Rotation = rot + psrot
End If
Else
Set mTxt = ent
pt1 = mTxt.InsertionPoint
pt1 = transPt(pt1)
rot = Math.Round(mTxt.Rotation, 5)
wid = mTxt.Width
mAtt = mTxt.AttachmentPoint
Set amTxt = ThisDrawing.PaperSpace.AddMText(pt1, wid, mTxt.TextString)
amTxt.AttachmentPoint = mAtt
If rot = 0# Then
amTxt.Rotation = 0#
Else
amTxt.Rotation = rot + psrot
End If
amTxt.StyleName = styl.Name
amTxt.ScaleEntity pt1, pss
End If
Next
End Sub
Function transPt(ByRef pt1 As Variant) As Variant
pt1 = ThisDrawing.Utility.TranslateCoordinates(pt1, acUCS, acDisplayDCS, 0)
pt1 = ThisDrawing.Utility.TranslateCoordinates(pt1, acDisplayDCS, acPaperSpaceDCS, 0)
transPt = pt1
End Function
有趣的是你没有';t必须将自定义比例因子应用于Mtext.Width。或者在我看来是这样的;我会检查你的代码,这样也许我可以为将来开发一些Mspace2Pspace工具 ;非常感谢。 干得好!我看到你了;重新创建新实体,而我正在使用CopyObjects功能…为什么我需要缩放对象
顺便说一句,我只使用C,因为我';我对它比较舒服。没有理由这样做;t被移植到VBA…它的所有组件; 我之所以创建新对象,是因为我找到了最简单的方法将它们放在新层(当前层)上,而我没有&35;039;我不想删除原件,只需将其关闭,因为同一文本可能需要复制到不同的版面 ;我的下一个项目是出于同样的原因将纪念碑符号(块)转换成PS ;将很简单,除非符号包含擦除实体 ;复制它们不会';我似乎没有遵守提款顺序 ;一旦他们进入纸面空间,将他们带到前台似乎取得了喜忧参半的成功。我一定忽略了什么 ;无论如何,必须尽快完成此映射,因此必须等待编写例程。
页:
[1]