script to write x,y,z cordinates to a text file
script to write x,y,z cordinates to a text file
(OP)
I was hoping someone could help me finish this script. I can't get it to limit the out put to only a 4 place decimal
thanks in advance
I'm trying to make a script to output points to a txt file, I would like to have it output x,y,z locations to a 4 place decimal can someone look at this and help me with a solution??
Thanks in advance
Language = "VBSCRIPT"
Sub CATMain()
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Set fs = CreateObject("Scripting.FileSystemObject")
Set A = fs.CreateTextFile("c:\temp\ponits.txt", True)
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item("Points")
Dim hybridShapes1 As hybridShapes
Set hybridShapes1 = hybridBody1.hybridShapes
Dim Number
Number = hybridBody1.hybridShapes.Count
'MsgBox (Number)
For i = 1 To Number
Dim hybridShapePointCoord1 As HybridShape
Set hybridShapePointCoord1 = hybridShapes1.Item(i)
Dim length2 As Length
Set length2 = hybridShapePointCoord1.X
Set length2 = hybridShapePointCoord1.Y
Set length2 = hybridShapePointCoord1.Z
xCoord = (hybridShapePointCoord1.X.Value / 25.4)
yCoord = (hybridShapePointCoord1.Y.Value / 25.4)
zCoord = (hybridShapePointCoord1.Z.Value / 25.4)
A.WriteLine (xCoord & ", " & yCoord & ", " & zCoord)
Next
'part1.Update
A.Close
MsgBox "File Writen"
End Sub
thanks in advance
I'm trying to make a script to output points to a txt file, I would like to have it output x,y,z locations to a 4 place decimal can someone look at this and help me with a solution??
Thanks in advance
Language = "VBSCRIPT"
Sub CATMain()
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Set fs = CreateObject("Scripting.FileSystemObject")
Set A = fs.CreateTextFile("c:\temp\ponits.txt", True)
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item("Points")
Dim hybridShapes1 As hybridShapes
Set hybridShapes1 = hybridBody1.hybridShapes
Dim Number
Number = hybridBody1.hybridShapes.Count
'MsgBox (Number)
For i = 1 To Number
Dim hybridShapePointCoord1 As HybridShape
Set hybridShapePointCoord1 = hybridShapes1.Item(i)
Dim length2 As Length
Set length2 = hybridShapePointCoord1.X
Set length2 = hybridShapePointCoord1.Y
Set length2 = hybridShapePointCoord1.Z
xCoord = (hybridShapePointCoord1.X.Value / 25.4)
yCoord = (hybridShapePointCoord1.Y.Value / 25.4)
zCoord = (hybridShapePointCoord1.Z.Value / 25.4)
A.WriteLine (xCoord & ", " & yCoord & ", " & zCoord)
Next
'part1.Update
A.Close
MsgBox "File Writen"
End Sub





RE: script to write x,y,z cordinates to a text file
I will show an example for the xCoord this will be placed after you set it's value prior to writing it.
xStr = CStr(xCoord) 'converts to string
xSplt = Split(xStr, ".") 'splits string by .
xVal = Mid(xSplt(1), 0, 4) 'grabs the first 4 numbers after the .
A.WriteLine(xVal & ", " & yVal & ", " & zVal)
HTH,
puck
RE: script to write x,y,z cordinates to a text file
sorry that this is a bit late, but a simpler method would be to use the format function.
e.g.
format(3.3333333,"0.0000")
=> 3.3333
so you would need...
xCoord = format(xCoord,"0.0000")
yCoord = format(yCoord,"0.0000")
zCoord = format(zCoord,"0.0000")
A.WriteLine (xCoord & ", " & yCoord & ", " & zCoord)