Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

how to import x,y components of spline??

Status
Not open for further replies.

Guest
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
 
Replies continue below

Recommended for you

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:
Code:
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.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor