×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

Try this
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

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)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources