小伙子,你做了全面的命令。 看起来不错。没有尝试过你的代码,因为我正处于特定用途的中间。 我得到了一张测量地图,上面有所有的注释(方位角,距离,注释......),需要分成3张,有两个不同的比例和重叠的区域。有些文本需要保持水平,有些是对齐的,有些是1:50,有些是1:100。无论如何,这是我处理过的VBA中的代码;
- 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
有趣的是,您不必将自定义比例因子应用于 Mtext.Width。至少在我看来是这样。
我将审查你的代码,以便将来我可以C#一些Mspace2Pspace工具。 谢谢。 |