NaWin55
Mechanical
- Mar 21, 2020
- 97
Hello
i am trying to create points using excel X Y Z data
below is the code i have written in VBA, How can i write it without using while or if conditions
Dim opartDoc As Document
Set opartDoc = CATIA.Documents.Add("Part")
Dim oprt As Part
Set oprt = opartDoc.Part
Dim hybshpfact As HybridShapeFactory
Set hybshpfact = oprt.HybridShapeFactory
Dim hybs As HybridBodies
Set hybs = oprt.HybridBodies
Dim hyb1 As HybridBody
Set hyb1 = hybs.Add
Dim opoint As HybridShapePointCoord
On Error Resume Next
Dim oexcel As Object
Set oexcel = GetObject(, "Excel.Application")
If oexcel Is Nothing Then
Set oexcel = CreateObject("Excel.Application")
Err.Clear
oexcel.Visible = True
End If
Dim wrkbk As Workbook
Set wrkbk = oexcel.ActiveWorkbook
Dim osheet As Worksheet
Set osheet = wrkbk.Worksheets.Item(1)
Dim rowsnum As Integer
rowsnum = osheet.UsedRange.Rows.Count
Dim colnum As Integer
colnum = osheet.UsedRange.Columns.Count
Dim x As Double
Dim y As Double
Dim z As Double
Dim i, j As Integer
For j = 1 To colnum
While (j = 1)
For i = 2 To rowsnum
x = osheet.Cells(i, j).Value
y = osheet.Cells(i, j + 1).Value
z = osheet.Cells(i, j + 2).Value
Set opoint = hybshpfact.AddNewPointCoord(x, y, z)
hyb1.AppendHybridShape opoint
oprt.UpdateObject opoint
Next
j = j + 1
Wend
Next
oprt.Update
Excel Data
Thanks
i am trying to create points using excel X Y Z data
below is the code i have written in VBA, How can i write it without using while or if conditions
Dim opartDoc As Document
Set opartDoc = CATIA.Documents.Add("Part")
Dim oprt As Part
Set oprt = opartDoc.Part
Dim hybshpfact As HybridShapeFactory
Set hybshpfact = oprt.HybridShapeFactory
Dim hybs As HybridBodies
Set hybs = oprt.HybridBodies
Dim hyb1 As HybridBody
Set hyb1 = hybs.Add
Dim opoint As HybridShapePointCoord
On Error Resume Next
Dim oexcel As Object
Set oexcel = GetObject(, "Excel.Application")
If oexcel Is Nothing Then
Set oexcel = CreateObject("Excel.Application")
Err.Clear
oexcel.Visible = True
End If
Dim wrkbk As Workbook
Set wrkbk = oexcel.ActiveWorkbook
Dim osheet As Worksheet
Set osheet = wrkbk.Worksheets.Item(1)
Dim rowsnum As Integer
rowsnum = osheet.UsedRange.Rows.Count
Dim colnum As Integer
colnum = osheet.UsedRange.Columns.Count
Dim x As Double
Dim y As Double
Dim z As Double
Dim i, j As Integer
For j = 1 To colnum
While (j = 1)
For i = 2 To rowsnum
x = osheet.Cells(i, j).Value
y = osheet.Cells(i, j + 1).Value
z = osheet.Cells(i, j + 2).Value
Set opoint = hybshpfact.AddNewPointCoord(x, y, z)
hyb1.AppendHybridShape opoint
oprt.UpdateObject opoint
Next
j = j + 1
Wend
Next
oprt.Update
Excel Data
Thanks