×
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 select dimensions and export to excel or access

How to select dimensions and export to excel or access

How to select dimensions and export to excel or access

(OP)

I am trying to write a macro that will allow me to Export only the selected dimensions to a table or database. Im new
to vba so much help would be greatly appreciated. Also I am using solidworks 2003.

RE: How to select dimensions and export to excel or access

Look in the API help under selection manager.

RE: How to select dimensions and export to excel or access

(OP)
i checked the api before i made the post. yet it was of no help consideriing i am new to vba. A little direction would be appreciated

RE: How to select dimensions and export to excel or access

Granted that the API help can be difficult to use, and I do not want to sound too critical because I was once (and still am too many times) in your shoes, but I did a search using Dimension as the keyword and came up with the "Get Component Via Display Dimension Example (VB)".  This is from SW2004 API help (I no longer have access to SW2003) so you may not have it.  While it is not exactly what you asked for it does show you how to get the dimension object which is only a couple steps away.  With that said, I did write a very very simple example.  It contains no checking to see if the objects are valid or dimensions were pre-selected.  And I am by no means an Excel VBA programmer so the API calls I use probably are not the best but they did get the job done.  The example is written using Early binding (see API help for definition).  What this means is you will have to select Tools, References from the VBA editor menu and check the following:

CODE

SldWorks 2003 Type Library (although it may be just SldWorks Type Library in SW2003)

SolidWorks Constant Type Library

Microsoft Excel 11.0 Object Library (again may be different for you, I have Office 2003 installed).

In the code window type (or cut and paste) the following code.

CODE

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swDim As SldWorks.Dimension
Dim xlApp As Excel.Application
Dim xlWorksheet As Excel.Worksheet
Dim AtIndex As Long

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager

Set xlApp = GetObject(, "excel.application")

Set xlWorksheet = xlApp.ActiveSheet

For AtIndex = 1 To swSelMgr.GetSelectedObjectCount

    Set swDim = swSelMgr.GetSelectedObject5(AtIndex).GetDimension
    
    xlWorksheet.Cells(1, AtIndex) = swDim.value
    
Next

End Sub

Now open a blank Excel workbook, select a few dimensions in SolidWorks and run the macro.  I hope this helps.

Some final thoughts.  Since you are new to SW API programming, I would suggest you do a search on "example" in the API help.  There are a lot of good examples that you can learn from.  You can also look in the FAQ's on this site as well as the SolidWorks web site for more examples.

SA

RE: How to select dimensions and export to excel or access

(OP)
thanks i appreciate the help

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