nobody 发表于 2017-8-18 21:48:18

堆叠多行文字

尝试适当地重新打包某些文本。我试过几种不同的方法,但都失败了。见下文。首先检查第一个文本项中是否有“2”,然后检查位置是否正确。X是第二个文本的位置,然后交换它们。尝试了一些不同的检查,除了文本处于奇怪的角度外,这些检查在大多数情况下都有效
私有void swaptext()
{
使用(help.AcadDocumentLock)
{
使用(var t=help.StartTransaction)
{
试试
{
多行文字tx1=(多行文字)ID。获取对象(OpenMode.ForRead)
MText tx2=(MText)id.GetObject(OpenMode.ForRead)
字符串cont1=tx1.Contents
字符串cont2=tx2.Contents
点3d pos1=tx1.位置
Point3d pos2=tx2.位置
if((tx1.Contents.Contains(“两”)&&(pos1.X
{
tx1.UpgradeOpen()
tx2.UpgradeOpen()
tx1.Contents=cont2
tx2.Contents=cont1
}
else if((tx2.Contents.Contains(“两”)&&(pos2.X
{
tx1.UpgradeOpen()
tx2.UpgradeOpen()
tx1.Contents=cont2
tx2.Contents=cont1
}
else if((tx1.Contents.Contains(“两”)&&(pos1.Y>pos2.Y))
{
tx1.UpgradeOpen()
tx2.UpgradeOpen()
tx1.Contents=cont2
tx2.Contents=cont1
}
else if((tx2.Contents.Contains(“两”)&&(pos2.Y>pos1.Y))
{
tx1.UpgradeOpen()
tx2.UpgradeOpen()
tx1.Contents=cont2
tx2.Contents=cont1
}
ids.Clear()
}
caTWOh(System.Exception.ex)
{
help.AcadDocument.Editor。WriteMessage(“错误:==>\n{0}\n路径:===>\n}1}”,例如Message,例如StackTrace)
}
t.Commit()
}
}
}
-修改代码以匹配最接近的工作解决方案

**** Hidden Message *****

nobody 发表于 2017-8-18 22:01:32

实际上,我为这篇文章制作的图形给了我一些想法......我认为如果我检查从第一个字符串位置到第二个字符串的角度不是在第一个180度可能会起作用

nobody 发表于 2017-8-18 22:24:15

哦...再次躲避我任何帮助,不胜感激。谢谢!公共静态双角度fromxpos(Point3d pt1,Point3d pt2)。
{。
协调系统3d=Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d;。
平面平面=新平面(systemd.Origin,systemd.Xaxis,systemd.Yaxis);。
Vector3d vectord=(Vector3d)(pt2-pt1);。
返回vectord.AngleOnPlane(平面);。
}。


私有无效交换文本()。
{。
使用(help.AcadDocumentLock)。
{。
使用(var t=help.StartTransaction)。
{。
尝试。
{。
MTexttx1=(MText1)id. GetObject(OpenMode.ForRead);。
MTexttx2=(MText2)id. GetObject(OpenMode.ForRead);。
字符串conts1=tx1.Contents;。
字符串conts2=tx2.Contents;。

Point3d pos1=tx1.Location;。
Point3d pos2=tx2.Location;。

if((tx1.Contents.Contains("TWO")) && (anglefromxpos(pos1, pos2)pos2. Y))。
{。
tx1.Contents=conts2;。
tx2.Contents=conts1;。
}。

if((tx2.Contents.Contains("TWO")) && (anglefromxpos(pos2, pos1)pos1. Y))。
{。
tx2.Contents=conts1;。
tx1.Contents=conts2;。
}。


ids.Clear();。
}。
捕获(System.Exceptionex)。
{。
help.AcadDocument.Editor.WriteMessage("Error:==>\n{0}\nTrace:==>\n{1}",ex.Message,ex.StackTrace);。
}。
t.Commit();。
}。
}。
}。


Bryco 发表于 2017-8-19 11:42:59

anglefromxpos(pos1,pos2)-tx1.rotationpos2.Y))等,也许我错过了一些东西

nobody 发表于 2017-8-19 15:13:46

我知道这是lisp,但会根据需要对两行进行排序,这样就可以使用当前文本交换文本,即使多行文字只是剥离到多行。
(setq lst (list "this is line two" "this is line one"))
Command: (setq lst (VL-SORT lst '(lambda (a b) (> a b))))
("this is line two" "this is line one")
Command: (setq lst (VL-SORT lst '(lambda (a b) (< a b))))
("this is line one" "this is line two")
页: [1]
查看完整版本: 堆叠多行文字