代码跟随,在以下帖子中解释
- Option Explicit
- Dim N As Integer, dwgn As Integer, intCount As Integer
- Dim WBL As AcadSelectionSet
- Dim pt1 As Variant, pt2 As Variant
- Dim dblPT1(1) As Double, dblPT2(1) As Double
- Dim strFilename As String
- Private Sub UserForm_Initialize()
- TextBox1.Value = "Enter 1st Dwg#"
- TextBox1.SetFocus
- TextBox1.SelStart = 0
- TextBox1.SelLength = TextBox1.TextLength
- CommandButton1.Enabled = False
- CommandButton2.Enabled = False
- If ThisDrawing.SelectionSets.Count > 0 Then
- For N = 0 To ThisDrawing.SelectionSets.Count - 1
- If ThisDrawing.SelectionSets.Item(N).Name = "WBL" Then
- ThisDrawing.SelectionSets("WBL").Delete
- End If
- Next N
- End If
- End Sub
- Private Sub CommandButton1_Click()
- Me.Hide
- With ThisDrawing.Utility
- .InitializeUserInput 1
- pt1 = .GetPoint(, vbCr & "Pick First Corner: ")
- .InitializeUserInput 1 ' or 1 for Window 33 for Crossing
- pt2 = .GetCorner(pt1, "Pick Other Corner: ")
- If ThisDrawing.SelectionSets.Count > 0 Then
- For N = 0 To ThisDrawing.SelectionSets.Count - 1
- If ThisDrawing.SelectionSets.Item(N).Name = "WBL" Then
- ThisDrawing.SelectionSets("WBL").Delete
- End If
- Next N
- End If
- Set WBL = ThisDrawing.SelectionSets.Add("WBL")
- WBL.Select acSelectionSetWindow, pt1, pt2
- End With
- WBL.Highlight True
- CommandButton2.Enabled = True
- Me.Show
- End Sub
- Private Sub CommandButton2_Click()
- Dim hgt As Double
- strFilename = "c:\details\DTL" & TextBox1.Value
- For intCount = 0 To 1
- dblPT1(intCount) = CDbl(pt1(intCount))
- dblPT2(intCount) = CDbl(pt2(intCount))
- Next intCount
- hgt = (dblPT2(1) - dblPT1(1)) * 0.03
- ThisDrawing.ModelSpace.AddText strFilename, pt1, hgt
- ThisDrawing.Regen acActiveViewport
- ThisDrawing.ActiveLayout.SetWindowToPlot dblPT1, dblPT2
- ThisDrawing.WBlock strFilename, WBL
- DetailDwf (strFilename)
- WBL.Highlight False
- WBL.Erase
- WBL.Delete
- ThisDrawing.Regen acAllViewports
- 'textbox1.value = textbox1.value 1+
- TextBox1.Value = ThisDrawing.Utility.DistanceToReal(TextBox1.Value, acDecimal) + 1
- End Sub
- Private Sub CommandButton3_Click()
- Unload Me
- End Sub
- Private Sub TextBox1_Change()
- CommandButton1.Enabled = True
- End Sub
|