I have a script creating points by using an excel file.
I would like to create axis systems in the same manner.
The format should be as in the below example
' A B C D E F G
' 1 Name X Y Z rX rY rZ
' 2 Axis1 123,321 123,321 123,321 45 90 120
' 3 Axis2 456,654 456,654 456,654 45 90 120
' 4 Axis3 789,987 789,987 789,987 45 90 120
Can anyone help me creating a script?
Reards
RobertW
Sub CATMain()
'''''''''''''''''''''''''''''''''''''
' ÅF Robotic Engineering Olofström '
'''''''''''''''''''''''''''''''''''''
' A B C D
' 1 Name X Y Z
' 2 Point1 123,321 123,321 123,321
' 3 Point2 456,654 456,654 456,654
' 4 Point3 789,987 789,987 789,987
' 5 ...
'''''''''''''''''''''''''''''''''''''''''
'
' Start Catia, Open a new CATPart, give it a good name
' Tools-> Macro-> Macros (Alt+F8)
' Select this script and then Run. When prompted select your .xls-file formatted in the above manner.
'
'''''''''''''''''''''''''''''''''''''''''
YourFile = CATIA.FileSelectionBox("Select file!", "*.xls", CatFileSelectionModeOpen)
Dim EXCEL As Object
Set EXCEL = CreateObject("Excel.Application")
EXCEL.Workbooks.Open YourFile
Dim X As Double
Dim Y As Double
Dim Z As Double
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Add()
Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory
Dim bNotFound as boolean
Dim i As Integer
i = 2
While Not bNotFound
PointName = EXCEL.cells(i, 1).Value
X = EXCEL.cells(i, 2).Value
Y = EXCEL.cells(i, 3).Value
Z = EXCEL.cells(i, 4).Value
if (x+y+z) = 0.0 AND PointName = "" then
bNotFound = true
else
if not((x+y+z) = 0.0) then
Dim hybridShapePointCoord1 As HybridShapePointCoord
Set hybridShapePointCoord1 = hybridShapeFactory1.AddNewPointCoord(X, Y, Z)
hybridBody1.AppendHybridShape hybridShapePointCoord1
part1.InWorkObject = hybridShapePointCoord1
hybridShapePointCoord1.Name = PointName
part1.Update
end if
end if
i = i+1
wend
EXCEL.Application.Quit
End Sub
I would like to create axis systems in the same manner.
The format should be as in the below example
' A B C D E F G
' 1 Name X Y Z rX rY rZ
' 2 Axis1 123,321 123,321 123,321 45 90 120
' 3 Axis2 456,654 456,654 456,654 45 90 120
' 4 Axis3 789,987 789,987 789,987 45 90 120
Can anyone help me creating a script?
Reards
RobertW
Sub CATMain()
'''''''''''''''''''''''''''''''''''''
' ÅF Robotic Engineering Olofström '
'''''''''''''''''''''''''''''''''''''
' A B C D
' 1 Name X Y Z
' 2 Point1 123,321 123,321 123,321
' 3 Point2 456,654 456,654 456,654
' 4 Point3 789,987 789,987 789,987
' 5 ...
'''''''''''''''''''''''''''''''''''''''''
'
' Start Catia, Open a new CATPart, give it a good name
' Tools-> Macro-> Macros (Alt+F8)
' Select this script and then Run. When prompted select your .xls-file formatted in the above manner.
'
'''''''''''''''''''''''''''''''''''''''''
YourFile = CATIA.FileSelectionBox("Select file!", "*.xls", CatFileSelectionModeOpen)
Dim EXCEL As Object
Set EXCEL = CreateObject("Excel.Application")
EXCEL.Workbooks.Open YourFile
Dim X As Double
Dim Y As Double
Dim Z As Double
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Add()
Dim hybridShapeFactory1 As HybridShapeFactory
Set hybridShapeFactory1 = part1.HybridShapeFactory
Dim bNotFound as boolean
Dim i As Integer
i = 2
While Not bNotFound
PointName = EXCEL.cells(i, 1).Value
X = EXCEL.cells(i, 2).Value
Y = EXCEL.cells(i, 3).Value
Z = EXCEL.cells(i, 4).Value
if (x+y+z) = 0.0 AND PointName = "" then
bNotFound = true
else
if not((x+y+z) = 0.0) then
Dim hybridShapePointCoord1 As HybridShapePointCoord
Set hybridShapePointCoord1 = hybridShapeFactory1.AddNewPointCoord(X, Y, Z)
hybridBody1.AppendHybridShape hybridShapePointCoord1
part1.InWorkObject = hybridShapePointCoord1
hybridShapePointCoord1.Name = PointName
part1.Update
end if
end if
i = i+1
wend
EXCEL.Application.Quit
End Sub