Home > Software engineering >  Vb.net calls for automatic CAD drawings and open, how to say it's unable to create the Active c
Vb.net calls for automatic CAD drawings and open, how to say it's unable to create the Active c

Time:09-24

Public (x) As a Double
Public (y) As a Double
Public count As Integer
'where x, y x and y coordinates for PolyLine line array, the count of PolyLine line the number of nodes, the x, y, the length of the array
'for the button to add the program code is as follows:
Private Sub Button1_Click (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles for. Click
On Error GoTo handle01
Dim AcadApp As Object
On the Error Resume Next
AcadApp=GetObject (" object "), 'if the CAD has been running, the return of CAD application object reference, otherwise an error
If Err. Number Then 'If Err Number non-zero (true)
Err. The Clear ()
AcadApp=CreateObject (" object ")
If Err. Number Then
MsgBox (Err. Description)
The Exit Sub
End the If
End the If

AcadApp. Visible=True 'set visual interface
AcadApp. WindowState=AutoCAD. AcWindowState. Maximize acMax 'Settings interface
AppActivate (AcadApp. Caption) 'display AutoCAD interface

'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
"' when AcadApp no longer use, should use AcadApp=Nothing to release the memory resources
'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Dim dg As New SaveFileDialog
Dg. Filter="CAD file (*. DWG) | *. DWG"
Dg. ShowDialog ()
Dim savePathname As String
SavePathname=dg. The FileName
'====================================================================
X={0, 100, 200, 300}
Y={0, 50, 0, 50}
The count=4
Dim As Integer I
Dim points (2 * (count - 1) + 1) As a Double
For I=0 To count - 1
Points (I * 2)=x (I)
Points (I * 2 + 1)=y (I)
Next
Dim Ymax As Double=y (0)
For I=0 To count - 1
If Ymax & lt; Y (I) Then
Ymax=y (I)
End the If
Next
AcadApp. ActiveDocument. ModelSpace. AddLightWeightPolyline (points)
'draw X
XAxisTextCord Dim pointsXAxis (3), (2), XAxisArrowCord (5) As a Double
PointsXAxis (0)=0: pointsXAxis (1)=0
PointsXAxis (2)=x (count - 1) + 10: pointsXAxis (3)=0
XAxisTextCord (0)=pointsXAxis (2) : XAxisTextCord (1)=pointsXAxis (3)
XAxisArrowCord (0)=x (count - 1) : XAxisArrowCord=5 (1)
XAxisArrowCord (2)=x (count - 1) + 10: XAxisArrowCord (3)=0
XAxisArrowCord (4)=x (count - 1) : XAxisArrowCord (5)=5
AcadApp. ActiveDocument. ModelSpace. AddLightWeightPolyline (pointsXAxis)
AcadApp. ActiveDocument. ModelSpace. AddText (" distance ", XAxisTextCord, 6)
AcadApp. ActiveDocument. ModelSpace. AddLightWeightPolyline (XAxisArrowCord)
'draw Y
YAxisTextCord Dim pointsYAxis (3), (2), YAxisArrowCord (5) As a Double
PointsYAxis (0)=0: pointsYAxis (1)=0
PointsYAxis (2)=0: pointsYAxis (3)=Ymax + 20
YAxisTextCord (0)=pointsYAxis (2) : YAxisTextCord=Ymax + 20 (1)
YAxisArrowCord (0)=5: YAxisArrowCord (1)=Ymax + 10
YAxisArrowCord (2)=0: YAxisArrowCord (3)=Ymax + 20
YAxisArrowCord (4)=5: YAxisArrowCord (5)=Ymax + 10
AcadApp. ActiveDocument. ModelSpace. AddLightWeightPolyline (pointsYAxis)
AcadApp. ActiveDocument. ModelSpace. AddText (" height ", YAxisTextCord, 6)
AcadApp. ActiveDocument. ModelSpace. AddLightWeightPolyline (YAxisArrowCord)
'drawing origin
Dim XYAxisTextCord (2) As a Double
XYAxisTextCord (0)=- 10: XYAxisTextCord (1)=10
-AcadApp. ActiveDocument. ModelSpace. AddText (0, 0, XYAxisTextCord, 6)
'====================================================================
AcadApp. ActiveDocument. SaveAs (savePathname)
AcadApp. Quit ()
MsgBox (" save the CAD file success!" )
The Exit Sub
Handle01:
MsgBox (Err. The Description)
  • Related