Code:
Private Sub CommandButton1_Click()Dim CATIA As Object
On Error Resume Next
Set CATIA = GetObject(, "CATIA.Application")
If Err.Number <> 0 Then
Set CATIA = CreateObject("CATIA.Application")
End If
If CATIA Is Nothing Then
MsgBox "First open a CATIA application!!!", vbCritical, "Error Macro"
Exit Sub
End If
Set documents1 = CATIA.Documents
Set partDocument1 = documents1.Add("Part")
toto = Right(partDocument1.Name, 8)
Set product1 = partDocument1.GetItem(toto)
product1.PartNumber = "Importing points from Excel"
Set part1 = partDocument1.Part
Set hybridBodies1 = part1.HybridBodies
'Asks for Name of the Geometrical Set
GSname = InputBox("Name of Destination Set?", "Name of the Set", "Inserting Points from Excel")
'Create the Geometrical Set of the points
Set hybridBody1 = hybridBodies1.Add()
hybridBody1.Name = GSname
Set hybridShapeFactory1 = part1.HybridShapeFactory
Call ototalcount
'Lanzar Form ProgressBar
start_time = Timer
ProgressForm1.Show vbModeless
ProgressForm1.ExitButton.Enabled = False
sInfo = "Processing ....." & vbCrLf & _
" " & vbCrLf & _
"Please wait!!!"
ProgressForm1.Label1.Caption = sInfo
i = 2
While Excel.Cells(i, 1) <> ""
Excel.Cells(i, 1).Select
PointName = Excel.Cells(i, 1).Value
X = Excel.Cells(i, 2).Value
Y = Excel.Cells(i, 3).Value
Z = Excel.Cells(i, 4).Value
Set hybridShapePointCoord1 = hybridShapeFactory1.AddNewPointCoord(X, Y, Z)
If (PointName <> Excel.Cells(i - 1, 1).Value) Then
hybridBody1.AppendHybridShape Spline
part1.InWorkObject = Spline
Spline.Name = Excel.Cells(i - 1, 1).Value
Set Spline = hybridShapeFactory1.AddNewSpline
Else
Spline.addpoint hybridShapePointCoord1
End If
hybridBody1.AppendHybridShape hybridShapePointCoord1
part1.InWorkObject = hybridShapePointCoord1
hybridShapePointCoord1.Name = PointName
i = i + 1
part1.Update
'Progressbar con frames
oExportValue = ((i - 2) * 100) / n
UpdateProgressBar oExportValue
DoEvents
Wend
stop_time = Timer
sInfo = "Process Finished!!!" & vbCrLf & _
" " & vbCrLf & _
"Total Exporting Points = " & i - 2 & vbCrLf & _
" " & vbCrLf & _
"Executing Time : " & Format(stop_time - start_time, "0.00") & " s" & vbCrLf & _
" " & vbCrLf & _
"Thanks for using this macro!"
ProgressForm1.Label1.Caption = sInfo
ProgressForm1.ExitButton.Enabled = True
End Sub