- 在编写脚本时,使用形状替换对象,并看到了名为 ReplaceWith (VirtualShape As Shape) 的东西,但不知道如何使用它。
- 下面代码演示了怎么使用这个 API 函数,用来处理成千上万物件 批量替换,极大加速插件的运行时间。
Sub 测试替换()
Set sr = ActiveSelectionRange
vsh_SizeReplace sr(1), sr(2)
End Sub
Private Function vsh_Replace(src, dst)
Dim x As Double, y As Double
Dim vsh As Shape
dst.GetPositionEx cdrCenter, x, y
Set vsh = src.TreeNode.GetCopy().VirtualShape
vsh.SetPositionEx cdrCenter, x, y
dst.ReplaceWith vsh
End Function
Private Function vsh_SizeReplace(src, dst)
Dim x As Double, y As Double
Dim vsh As Shape
Set vsh = src.TreeNode.GetCopy().VirtualShape
dst.GetSize x, y: vsh.SetSize x, y
dst.GetPositionEx cdrCenter, x, y
vsh.SetPositionEx cdrCenter, x, y
dst.ReplaceWith vsh
End Function