几何尺寸与公差论坛

 找回密码
 注册
查看: 789|回复: 0

【转帖】solidworks api= library

[复制链接]
发表于 2009-4-12 22:27:56 | 显示全部楼层 |阅读模式
solidworks api+ library
solidworks api+ library
i am currently writing a new library (dll to reference in .net) for the solidworks api. the new library will have an enhanced object called the sldworkex object, which will take care of all of the hard work for you. it managed the connection to solidworks for you, closing solidworks, can tell you the current version of solidworks as in integer, can open a file without the need to specifc the file type and adds the option to open visible or not, and much more.
expanding on that the library includes a modeldoc2ex, which can add/delete/set custom properties with ease managing the custompropertymanager for you so you don't have to hassle with it, as well as get all names, values, the total count any many other detials. it can save out the current model to any of the 28+ native formats that solidworks handles, again with no need to specific surplus data.
another object is the documentmanagerex, which again exposes the document manager and handles all of the connection for you so all you have to do is call functions to add/delete/set custom properties and get configurations etc...
all of the objects handle errors for you and return them in custom error objects with detailed descriptions. each *ex object provides the user with complete exposure to the underlying base object (sldworks, modeldoc2 etc...) so that you may still use any of the standard functions.
so, and example of use would be to add the angelsix.solidworksex.dll as a reference, and then do the following:
sldworksex swappex = new sldworksex();
if (!swappex.connect(false, true))
// error connecting so do whatever
// else show current version e.g. 2009
messagebox.show(swappex.version.tostring());
// open document, and get the modeldoc2ex object
modeldoc2ex swmodelex;
// default no options opens current configuration, silently, visible, and reports any error message to the opendocerrors string
swmodelex = swappex.open("c:\myfile.sldprt");
// if opening failed diplay message
if (swmodelex == null)
messagebox.show(swappex.opendocerrormessage);
// else set a custom property of the new part, selecting to overwrite if exist
bool b = swmodelex.setcustomproperty("description", "my description", true);
if (!b)
messagebox.show("failed to set custom property");
// show total custom properties including properties from all configurations
messagebox.show(swmodelex.custompropertycount(true).tostring());
// clear all custom properties
swmodelex.clearcustomproperties();
messagebox.show(swmodelex.custompropertycount(true).tostring());
// save as edrawing
if (!swmodelex.saveas("c:\mynewpart.eprt"))
messagebox.show(swappex.savedocerrormessage);
// close file
swmodelex.close();
// create new documentmanagerex
documentmanagerex dmex = new documentmanagerex();
dmex.opendoc("c:\mypart.sldprt");
dmex.setcustomproperty("description", "my description", true);
dmex.closedoc();
these are just a few examples of how tasks can be accomplished without the hassle involved for many using the standard api.
if you have any suggestions or ideas please post them and i will see about incorporating them.
the library will go on sale at angelsix in about a week or so once complete for £30 which buys you an unlimited use license for the individual/company using it for free or commercial use.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-23 18:37 , Processed in 0.035237 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表