本人写了如下一个VBA程式,就是将所选物体变成一个螺丝孔,但是出现了下面一些问题
假如先画一个圆,第一次将其变成m8,这一次很理想,而再次将m8变成m10就将不理想了,它生成了一个由m8和m10组成的块,我以为是没有删除以前块的原因,於是加了下面绿色的程式,可是还是没有用,请知道原因的老大多多指教,谢谢
Public Sub tt1() '以下是变为各种螺丝调用程式 Dim r As Double On Error Resume Next Dim sr As String Dim zm As String Dim shuz As Double
sr = InputBox("请输入人要变的东东", "变变", "") zm = Mid(sr, 1, 1) shuz = Mid(sr, 2) If zm = "m" Then If shuz = 5 Then yj = 4.3 End If If shuz = 6 Then yj = 5.2 End If If shuz = 8 Then yj = 6.8 End If If shuz = 10 Then yj = 8.6 End If If shuz = 12 Then yj = 10.5 End If If shuz = 14 Then yj = 12.5 End If Call gy1(shuz) End If
If zm = "u" Then '以下是正面沉头的调用公式 Call u(shuz)
Else Call gy(Val(sr)) '这是变为圆的调用程式 End If End Sub
Public Sub gy1(ls As Double) On Error Resume Next Dim ssetobj1 As AcadSelectionSet '以下是画螺丝的共用程式 Dim icount1 As Integer Dim i1 As Integer Dim selobj1 As AcadObject Dim blockobj As AcadBlock Dim insertpoint(0 To 2) As Double Dim i As Integer Dim blockrefobj As AcadBlockReference
icount1 = ThisDrawing.SelectionSets.Count While (icount1 > 0) If ThisDrawing.SelectionSets.Item(icount1 - 1).Name = "yuan" Then ThisDrawing.SelectionSets.Item(icount1 - 1).Delete End If icount1 = icount1 - 1 Wend Set ssetobj1 = ThisDrawing.SelectionSets.Add("yuan") ThisDrawing.Utility.Prompt "please select object" ssetobj1.SelectOnScreen Const pi = 3.141592654 insertpoint(0) = 0 insertpoint(1) = 0 insertpoint(2) = 0 i = ThisDrawing.Blocks.Count While (i > 0) If ThisDrawing.Blocks.Item(i - 1).Name = "luosi" Then ThisDrawing.Blocks.Item(i - 1).Delete End If i = i - 1 Wend
Set blockobj = ThisDrawing.Blocks.Add(insertpoint, "luosi") Set arc1 = blockobj.AddArc(insertpoint, ls / 2, pi, pi / 2) Set circ1 = blockobj.AddCircle(insertpoint, yj / 2)
For i1 = 0 To ssetobj1.Count - 1 Set selobj1 = ssetobj1.Item(i1) If selobj1.ObjectName = "AcDbCircle" Or selobj1.ObjectName = "AcDbCrc" Then
pt1 = selobj1.Center Else
pt1 = selobj1.InsertionPoint End If
Set blockrefobj = ThisDrawing.ModelSpace.InsertBlock(pt1, "luosi", 1#, 1#, 1#, 0) selobj1.Delete Next
End Sub |