不用设置,引用一下库后直接用即可。
you must first reference the AutoCAD type library. To do this in VB, select the References option from the Project menu to launch the Reference dialog box. From the References dialog box, choose AutoCAD Type Library, and then press OK.
例程:

- [FONT=courier new]
- Sub Ch2_ConnectToAcad()
- Dim acadApp As AcadApplication
- On Error Resume Next
-
- Set acadApp = GetObject(, "AutoCAD.Application")
- If Err Then
- Err.Clear
- Set acadApp = CreateObject("AutoCAD.Application")
- If Err Then
- MsgBox Err.Description
- Exit Sub
- End If
- End If
- MsgBox "Now running " + acadApp.Name + _
- " version " + acadApp.Version
- End Sub
- [/FONT]
VB与VBA程序比较
VBA:

- [FONT=courier new]
- Sub Ch2_AddLineVBA()
- ' This example adds a line
- ' in model space
- Dim lineObj As AcadLine
- Dim startPoint(0 To 2) As Double
- Dim endPoint(0 To 2) As Double
-
- ' Define the start and end
- ' points for the line
- startPoint(0) = 1
- startPoint(1) = 1
- startPoint(2) = 0
- endPoint(0) = 5
- endPoint(1) = 5
- endPoint(2) = 0
-
- ' Create the line in model space
- Set lineObj = ThisDrawing. _
- ModelSpace.AddLine _
- (startPoint, endPoint)
-
- ' Zoom in on the newly created line
- ZoomAll
- End Sub
- [/FONT]
VB:

- [FONT=courier new]
- Sub Ch2_AddLineVB()
- On Error Resume Next
-
- ' Connect to the AutoCAD application
- Dim acadApp As AcadApplication
- Set acadApp = GetObject _
- (, "AutoCAD.Application")
- If Err Then
- Err.Clear
- Set acadApp = CreateObject _
- ("AutoCAD.Application")
- If Err Then
- MsgBox Err.Description
- Exit Sub
- End If
- End If
-
- ' Connect to the AutoCAD drawing
- Dim acadDoc As AcadDocument
- Set acadDoc = acadApp.ActiveDocument
-
- ' Establish the endpoints of the line
- Dim lineObj As AcadLine
- Dim startPoint(0 To 2) As Double
- Dim endPoint(0 To 2) As Double
- startPoint(0) = 1
- startPoint(1) = 1
- startPoint(2) = 0
- endPoint(0) = 5
- endPoint(1) = 5
- endPoint(2) = 0
- ' Create a Line object in model space
- Set lineObj = acadDoc.ModelSpace.AddLine _
- (startPoint, endPoint)
- ZoomAll
- acadApp.visible = True
- End Sub
- [/FONT]
|