POINT INPUT FROM EXCEL

Anyone know how to input spline points from an excel file that has X, Y Z coordinates listed.

From what I understand, you start by saving this as a .txt file but how

do you read it into an open sketch? Any help would be appreciated.

Reply to
tjones2
Loading thread data ...

Open part, "Insert-Curve-Curve through xyz points"

(don't need to open sketch)

Reply to
Markku Lehtola

This is a macro called "ptcloud". It reads a text file with points listed as:

x y z x y z...etc

and enters them into a sketch. I've tried it and it works, but I've forgotten how. Can somebody please provide instructions? Thanks.

Option Explicit

Dim swApp As Object Dim Part As Object Dim boolstatus As Boolean Dim longstatus As Long, longwarnings As Long Dim FeatureData As Object Dim Feature As Object Dim Component As Object Dim fs As Object Dim file As Object

Type Point x As Double y As Double z As Double End Type

Dim oldY As Double Dim pt As Point Dim SelectionPoints As New Collection Dim line As String Dim first As Boolean Dim i As Long

Sub main()

Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc

Set fs = CreateObject("Scripting.FileSystemObject") Set file = fs.OpenTextFile("C:\data.xyz") line = file.ReadLine()

swApp.ActiveDoc.ActiveView.FrameState = 1 oldY = 0 first = True

Do While file.AtEndOfStream True And line "" Dim p1 As Long Dim p2 As Long p1 = InStr(line, Chr(9)) pt.x = CDbl(Mid(line, 1, p1 - 1)) / 25000 p2 = InStr(p1 + 1, line, Chr(9)) pt.y = CDbl(Mid(line, p1 + 1, p2 - p1 - 1)) / 25000 pt.z = CDbl(Mid(line, p2 + 1)) / 250

If first Or pt.y oldY Then oldY = pt.y If Not first Then Part.InsertCurveFileEnd Part.InsertCurveFileBegin SelectionPoints.Add pt.x SelectionPoints.Add pt.y SelectionPoints.Add pt.z first = False End If

Part.InsertCurveFilePoint pt.x, pt.y, pt.z line = file.ReadLine()

Loop

Part.InsertCurveFileEnd file.Close

Part.ClearSelection2 True For i = 1 To SelectionPoints.Count / 3 Dim name As String name = "Curve" + Trim(Str(i)) boolstatus = Part.Extension.SelectByID(name, "REFERENCECURVES", SelectionPoints(i * 3 - 2), _ SelectionPoints(i * 3 - 1), SelectionPoints(i * 3), True, 1, Nothing) Next i

Part.InsertLoftRefSurface2 False, False, False, 1, 0, 0 End Sub

Reply to
JKimmel

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.