本帖最后由 作者 于 2006-12-31 18:36:53 编辑
我改了一下程序。现在能实现第8贴中图1的效果。 Option Explicit Const PI As Double = 3.1415926535897 Public Sub Chamfering() On Error Resume Next Dim SSet As AcadSelectionSet If Not IsNull(ThisDrawing.SelectionSets.Item("chamfering")) Then Set SSet = ThisDrawing.SelectionSets.Item("chamfering") SSet.Delete End If Set SSet = ThisDrawing.SelectionSets.Add("chamfering") ThisDrawing.Utility.Prompt ("选择要斜切的对象...") SSet.SelectOnScreen Dim ptBase As Variant ptBase = ThisDrawing.Utility.GetPoint(, "请输入斜切对象的基点:") Dim pt2 As Variant pt2 = ThisDrawing.Utility.GetPoint(ptBase, "请输入斜切对象的插入点:") Dim angle As Double angle = ThisDrawing.Utility.GetAngle(ptBase, "请输入倾斜角度:") If Abs((angle / (0.5 * PI)) - Int(angle / (0.5 * PI))) < 0.001 Then MsgBox ("您输入的角度不合适,无法完成操作!") Exit Sub End If Dim newb As AcadBlock, newbName As String, n As Integer n = 1 newbName = "ahlzl" BLOCK2: For Each newb In ThisDrawing.Blocks If newb.Name = newbName Then newbName = "ahlzl" & "_" & CStr(n) n = n + 1 GoTo BLOCK2 End If Next newb Set newb = ThisDrawing.Blocks.Add(ptBase, newbName) Dim objCollection0() As Object, i As Integer ReDim objCollection0(SSet.Count - 1) As Object For i = 0 To SSet.Count - 1 Set objCollection0(i) = SSet.Item(i) Next Dim retObjects0 As Variant retObjects0 = ThisDrawing.CopyObjects(objCollection0, newb) Dim a1 As AcadBlockReference Set a1 = ThisDrawing.ModelSpace.InsertBlock(ptBase, newbName, 1 / Cos(angle), 1, 1, 0) a1.Rotate ptBase, DegreeToRadian(-45) Dim strBlkName As String strBlkName = "CAD倾斜" n = 1 Dim blockObj As AcadBlock BLOCK: For Each blockObj In ThisDrawing.Blocks If blockObj.Name = strBlkName Then strBlkName = "CAD倾斜" & "_" & CStr(n) n = n + 1 GoTo BLOCK End If Next blockObj Set blockObj = ThisDrawing.Blocks.Add(ptBase, strBlkName) Dim objCollection(0) As Object Set objCollection(0) = a1 Dim retObjects As Variant retObjects = ThisDrawing.CopyObjects(objCollection, blockObj) Dim xScale As Double, yScale As Double, zScale As Double, ang As Double xScale = Cos(PI / 4 - angle / 2) / Cos(DegreeToRadian(45)) yScale = Sin(PI / 4 - angle / 2) / Sin(DegreeToRadian(45)) zScale = 1 ang = PI / 4 + angle / 2 Dim ref1 As AcadBlockReference Set ref1 = ThisDrawing.ModelSpace.InsertBlock(pt2, strBlkName, xScale, yScale, zScale, ang) a1.Delete SSet.Delete End Sub Private Function DegreeToRadian(angle As Double) As Double DegreeToRadian = angle * PI / 180 End Function |