我修改的程序:(旨在抛砖引玉,没有剽窃原创的意思)
Sub copyAndRotate()
Dim ssetObj As AcadSelectionSet Dim ent As AcadEntity Dim i As Integer
Dim Osmode As Integer ThisDrawing.StartUndoMark Osmode = ThisDrawing.GetVariable("osmode") ThisDrawing.SetVariable "osmode", 37 '设成什么看自己习惯了
'新建选择集 On Error Resume Next ThisDrawing.SelectionSets("New_SelectionSet").Delete Set ssetObj = ThisDrawing.SelectionSets.Add("New_SelectionSet")
'检查选择集是否为空,是则退出程序 ssetObj.SelectOnScreen If ssetObj.Count = 0 Then GoTo ExitSub
'确定目标点 Dim P1 As Variant Dim Angle1 As Double Dim Angle2 As Double Dim Angle As Double P1 = ThisDrawing.Utility.GetPoint(, "请选择旋转中心:") P1 = ThisDrawing.Utility.TranslateCoordinates(P1, acWorld, acUCS, False) '因为用户当前坐标系可能不是世界坐标系 If Err Then GoTo ExitSub Angle1 = ThisDrawing.Utility.GetAngle(P1, "请选择基点:") If Err Then GoTo ExitSub Angle2 = ThisDrawing.Utility.GetAngle(P1, "请选择目标点:") If Err Then GoTo ExitSub
Do While Err.Number = 0 For i = 0 To ssetObj.Count - 1 Set ent = ssetObj.Item(i).Copy Angle = Angle2 - Angle1 ent.Rotate ThisDrawing.Utility.TranslateCoordinates(P1, acUCS, acWorld, False), Angle Next Angle2 = ThisDrawing.Utility.GetAngle(P1, "请选择目标点:") Loop
ExitSub: ThisDrawing.SetVariable "osmode", Osmode ThisDrawing.EndUndoMark End Sub
|