Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catia create points using Excel data

Status
Not open for further replies.

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
Screenshot_2024-09-20_133126_snrqag.png


Thanks
 
Replies continue below

Recommended for you

You dealed with so many codes , CAA and other stuff.Are you sure you can't solve this one ?
 
i tried other ways without conditions but not getting correct result

i just want to stop column count after all rows counted so that loop wont start from 2nd column again
for that i used if condition

just want to know how to do without CONDITIONS
 
i am using nested loop to get each row and loop thru column and go to next row and loop thru column until the last row and stop
this is why i am using "j"

to stop the loop i am using condition (once the last row comes stop the loop)

but how to do it without condition
 
To remove "IF" : assume that excel it's allready opened or create one .

To remove "while" , i presume that columns will always be X , Y, Z ?

Dim i As Integer
For i = 2 To rowsnum
x = osheet.Cells(i, 1).Value
y = osheet.Cells(i, 2).Value
z = osheet.Cells(i, 3).Value
Set opoint = hybshpfact.AddNewPointCoord(x, y, z)
hyb1.AppendHybridShape opoint
oprt.UpdateObject opoint
Next i

Or i'm missing something ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor