×
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

how to import x,y components of spline??

how to import x,y components of spline??

how to import x,y components of spline??

(OP)
Hi all,

Is there any way to import an Excel spreadsheet into solid works?  I have a series of generated x,y generated points for a closed curve which I want to build into a cam.  Any suggestions?

Thanks!
Tony

RE: how to import x,y components of spline??

You can use VB or VBA within SolidWorks to extract the values from Excel and generate the spline. Here is some code to help with the data extraction:

Option Explicit
Option Base 1

Sub Main()
    'SolidWorks Objects
    Dim swApp As Object
    Dim Part As Object
    'Excel Objects
    Dim xlApp As Object
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim iRow As Long
    Dim ptX() As Long, ptY() As Long
    Dim sMsg As String
    
    'Attach to Solidworks
    Set swApp = CreateObject("SldWorks.Application")
    Set Part = swApp.ActiveDoc
    
    'Open Excel and the Data Workbook
    Set xlApp = CreateObject("Excel.Application")
    Workbooks.Open FileName:="C:\Data.xls", ReadOnly:=True
    Workbooks.Application.Visible = True
    Set wb = xlApp.ActiveWorkbook
    Set ws = wb.Sheets("Sheet1")
    
    'Extract the data (X in col A, Y in Col B)
    iRow = 1    'first row of data
    Do While Len(ws.Range("A" & iRow).Text) > 0
        ReDim Preserve ptX(iRow)
        ReDim Preserve ptY(iRow)
        ptX(iRow) = ws.Range("A" & iRow).Value
        ptY(iRow) = ws.Range("B" & iRow).Value
        iRow = iRow + 1
    Loop
    
    'Close Excel
    xlApp.Quit
    
    'Report the info back to the user
    For iRow = LBound(ptX) To UBound(ptX)
        sMsg = sMsg & "Point " & iRow & ": (" & ptX(iRow) & ", " & ptY(iRow) & ")" & vbCrLf
    Next iRow
    swApp.SendMsgToUser sMsg
    
    Set ws = Nothing
    Set wb = Nothing
    Set xlApp = Nothing
    Set Part = Nothing
    Set swApp = Nothing
End Sub

Hope this helps!

DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

RE: how to import x,y components of spline??

BTW, that code was written in a SolidWorks 2001 Macro. You will need to add the MS Excel Object library to your project references (Tools>References).

DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.

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