2 Replies Latest reply on Dec 29, 2012 6:11 PM by Artem Taturevych

    Tips: How to find the required API method

    Artem Taturevych

      Hi All,

       

      Just decided to post a 'scenario' of finding the required API method when writing your SolidWorks API based code.

       

      This thread is started to help developers (especially newbie developers) to quickly sort thing out.

       

      This 'scenario' based on my experience only. Any comments, additions are greatly appreciated.

       

      So this is the sequence of steps I usually follow to find the API method:

       

      1) Searching for the method/interface in the Index tab of API Help (I prefer to use local .chm help instead of web help).

       

      2) If not found, go to Search tab. This one usually shows a lot of results so it may be a problem to investigate them all.

       

      3) Searching for a keyword in Members names/description. For example I need to find a method to insert Design Table. If you type "design table" in Index tab you will only find a GetDesign table method. The issue is the Design Table in API named Family Table that's why index doesn't give me good results. However I can expect that method to insert design table should be either in IModelDoc2 or IModelDocExtension interfaces. So I'm opening the members of IModelDoc2 and clicking ctrl+F for a search and typing "design table" and from the results I see the following:

       

      InsertFamilyTableEdit Edits an open design table from Microsoft Excel.  

      InsertFamilyTableNew Inserts a new design table from Microsoft Excel into the part. 

       

      where my search string is in the description of the method. So I should use IModelDoc2::InsertFamilyTableNew to insert new design table through the API.

       

      4) Using the Accessors section of the API help. If I do know the interface I'm looking for I like to know how to reach this interface. For example I'm looking for the IDimension interface where I like to use the IDimension::SystemValue property to change the dimension value. If I look into the IDimension interface Accessors:

       

      Accessors

      IDisplayDimension::GetDimension2

      IFeature::Parameter and IFeature::IParameter

      IModelDoc2::Parameter and IModelDoc2::IParameter

       

      I should select which one is more suitable for me. For example I can just get it by name via the IModelDoc2::Parameter or get it from IDisplayDimension via IDisplayDimension::GetDimension2 where the IDisplayDimension could be retrieved from the selection.

       

      5) If no luck - the API may be just missed so I'm looking for the workaround through the SolidWorks commands: SldWorks::RunCommand and swCommands_e enumerator. You should know that commands do not support arguments so the only functionality you should expect to find there should be 'void' functionality.

       

      6) Using the SolidWorks forum and Knowledge Base. These are a pretty good resources to find the information. Probably may sense to escalate the priority of this item.

       

      7) Using of public search sites: Google, Bing, etc...

      __________________________

      Regards,

      Merry Christmas and Happy New Year!

      Artem Taturevych

      Application Engineer at Intercad

      http://intercad.com.au/

      Tel: +61 2 9454 4444

        • Re: Tips: How to find the required API method
          Keith Rice

          Good post, Artem.

           

          I will also add this: if you eventually find a particular method that you think should have been listed in one of the API Help-->Index categories, you can email apihelp.feedback@3ds.com with your suggestion and they will most likely implement it in the next version. (If you wish, you can click on the "Send comments" link at the top right to send this email.)

           

          As an example: in SolidWorks 2012, if you're in the local API Help and search for the "Design Binder" category and double click on it, you'll be taken to ISldWorks::RunAttachedMacro. There are, however, several other methods for adding and deleting files to the Design Binder:

           

          IModelDocExtension::GetAttachmentCount

          IModelDocExtension::GetAttachments

          IModelDocExtension::DeleteAttachment

          IModelDocExtension::InsertAttachment

           

          In my case, I was ignorant of these methods for a long time because none of their API Help pages contain the phrase "Design Binder" and therefore they did not appear in the search. So I emailed apihelp.feedback@3ds.com about this, and now in the 2013 API Help, if you double click Design Binder, you will see these additional methods. This is an easy way to help the community, in my opinion.

           

          Keith

          Video Tutorials for the SolidWorks API