Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

How save datas using macro(API)? 1

Status
Not open for further replies.

PKaruzel

Mechanical
Mar 29, 2007
4
Welcome,
Does anybody know how save in simply text file some datas(for exemple: Selected Edge,Center of selected surface, or Area of selected surface) from part created in Solidworks using macro(API)?
 
Replies continue below

Recommended for you

PKaruzel,

See the Open statement in VBA help.

SA
 
Are you asking how to save data that you have already found, or are you asking first how to find that data and then how to save it? Writing output to a text file is rather simple. Getting the data you want from SolidWorks can be more complicated.
 
I mean my problem concerning second part of your question. I want to create macro,where after clicking button in window I will choose some surfaces in part created in Solidworks.Next this macro will write info about kind of surface which was selected,the center of selected surface,area, normal to this surface,root in text file.
I have to add that I'm beginner in VBA.
Thanks for any help!
 
Try going to the Main Menu/Help/SolidWorks and Add-Ins API Help Topics/Contents (tab)/SolidWorks API Help/Examples and Projects/Visual Basic (VB) Examples/R - T/Selections/... There are some example macros there that could help you get started.

You can also try looking in the Main Menu/<same as above>/Visual Basic (VB) Examples/L - Q/Mass Properties/... section.

For creating Text files, you'll have to use the VB Help. Try looking up Open, Input, or Line Input for some examples. If you don't have any luck then try searching the Internet for 'How to create text files from Excel VBA'. There are a lot more Excel examples available than SolidWorks about how to do non-SolidWorks specific tasks with VBA. You should be able to copy and paste most of that example code directly into a SolidWorks macro.

Ken
 
A member whose handle is Picia did a lot of work that sounds similar to what you're trying to do. You may want to read through all his threads here. There's quite a bit of code in them. You can see a list of all his threads and posts at:


Good luck!
 
You can use KenBolen's suggestions for finding out how to obtain the entity data from within SolidWorks.

To create the text file, look up how to use "FileSystemObject" on the web. Here's a start:


You will have to add the library "Microsoft Scripting Runtime" under References to get the FSO object to become available.
 
Thanks handleman,
Your macro you showed picia is just what I need for a future project. Saved me a lot of work. A star for you.


Bradley
SolidWorks Premim 2007 x64 SP3.1
PDM Works, Intel(R) Pentium(R) D CPU
3.00 GHz, 4 GB RAM, Virtual memory 12577 MB, nVidia 3400
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor