Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

script to write x,y,z cordinates to a text file

Status
Not open for further replies.

bogger

Automotive
Sep 17, 2003
3
US
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
 
Replies continue below

Recommended for you

Try this
I will show an example for the xCoord this will be placed after you set it's value prior to writing it.
Code:
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
 
Hi,

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)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top