VB 源程序代码如下
Private Sub Command1_Click()
Dim TopApp As TopSolid.Application
Dim TopDoc As TopSolid.DocumentDesign
' connect Visual Basic with TopSolid
' if TopSolid isn't open, it will open a new session of TopSolid
Set TopApp = New TopSolid.Application
' create a new document *.top
Set TopDoc = TopApp.Documents.Add("top")
Dim TopCircle As TopSolid.Curve
' Create a basic circle
' Centre = 0, 0, 0
' X axis = 1, 0, 0
' Y axis = 0, 1, 0
' Radius = 0.01
Set TopCircle = TopDoc.Curves.AddBasicCircle(0, 0, 0, 1, 0, 0, 0, 1, 0, 0.01)
' Set the name of the circle
TopCircle.Element.Name = "Circle_1"
' Free the memory
Set TopCircle = Nothing
Dim TopShape As TopSolid.Shape
Dim TopElt As TopSolid.Element
On Error Resume Next
' Search the curve to do the extruded
Set TopElt = TopDoc.Document.SearchElementByName("Circle_1")
' "cast" the element in circle
Set TopCircle = TopElt
If TopCircle Is Nothing Then
'error management
Exit Sub
End If
' Create a basic extruded
' Curve = Circle 1
' Z axis = 0, 0, 1
' Length = 0.02
Set TopShape = TopDoc.Shapes.AddBasicExtruded(TopCircle, 0, 0, 1, 0.02)
' Change the color of the shape
TopShape.Element.Color = topColorBlue
' Free the memory
Set TopCircle = Nothing
Set TopShape = Nothing
Set TopElt = Nothing
' Save the document with the name how_to_start.top
' If the document is modified, TopSolid must ask the user
TopDoc.Document.SaveAs "d:\how_to_start2.top", True
' TopSolid must save the modification(first 'True')
' TopSolid must ask the user (second 'True')
TopDoc.Document.Close True, True
' Close TopSolid
TopApp.Quit
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Free memory
Set TopDoc = Nothing
Set TopApp = Nothing
End Sub |