Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Demystifying The Solid Works Api

9,099 views

Published on

SolidWorks World 2010 presentation by Paul Gimbel of Razorleaf. This session provides an introduction to programming with the SolidWorks API and how to work with the SolidWorks Object Model. Not a programmer? No problem. This session was designed to inspire you and guide you to get started.

Published in: Technology, Business

Demystifying The Solid Works Api

  1. 1. Demystifying the SolidWorks API<br />Paul Gimbel, Business Process Sherpa<br />Razorleaf Corporation<br />
  2. 2. What You Will NOT Hear<br />This is an INTRODUCTION to the SolidWorks API<br />Examples – YES<br />Syntax Details – NO<br />Not a lesson on how to use the VBA or VSTA Interface<br />That’s a great idea for another session!<br />Not a programming class<br />Not designed for programmers<br />You won’t hear “Polymorphic Inheritence” used properly in a sentence<br />Slide 2 of 39,430,177<br />
  3. 3. My Main Goal<br />I want you to leave here saying:<br />“I can do that!”<br />“That even looks like fun”<br />“That could save me time”<br />“I could really go for a burrito”<br />
  4. 4. Who Is This Guy and Where Did He Come From?<br />Razorleaf Corporation<br />SolidWorks Service Partner<br />Services ONLY (we’re not trying to sell you anything, we’re neutral)<br />Data Management (EPDM, SmarTeam, Aras)<br />Design Automation (DriveWorks, Tacton)<br />Workflow Automation (Microsoft SharePoint and Tools)<br />Paul Gimbel (aka “The Sherpa”)<br />10+ years as Demo Jock, Applications Engineer, Trainer, Support Tech<br />5 years as Design Automation Implementer<br />Specializing in SolidWorks, DriveWorks, Tacton, Custom Programming<br />(THERE! Now I can report this trip as reimbursable.)<br />The <br />Sherpa<br />
  5. 5. Where Can I Find Programming?What Languages Can I Use?<br />Macros: Scripts called from inside of SolidWorks to do things automatically<br />Macro Features: Scripts run when at a point in the Feature Manager™<br />Add-Ins: Programs called from inside of SolidWorks through a custom UI<br />Companion Application: Another program’s macros can call SolidWorks<br />Standalone Application: A program that you wrote can call SolidWorks <br />FREE Visual Studio Express - http://www.microsoft.com/express/product/<br />(Use Coupon Code “RAZORLEAF”)<br />
  6. 6. Why VB.NET?<br />This presentation uses VB.NET (VSTA) Macros<br />Macro Recorder (2010) supports VBA, VB.NET, C#.NET<br />All built into SolidWorks <br />VBA and VSTA (Visual Studio Tools for Applications) development environments are included with SolidWorks<br />VB.NET is the current version of VB<br />VBA is based on VB6 (1998 technology, Support ended 2008)<br />NOBODY uses VBA anymore…well, except Microsoft Office<br />Even AutoDesk dropped VBA out of AutoCAD products in January 2010<br />Tons of examples are out there in VB, more than any other language<br />Most SolidWorks examples are in VBA (since they’re old)<br />Not too difficult to convert from VBA to VB.NET<br />
  7. 7. Macro Myths<br />Macros are in VBA<br />No Forms/Dialogs<br />Cannot be automated<br />Require you to preselect<br />Cannot handle advanced functionality (like classes)<br />
  8. 8. The Ultimate Process For Non-Programmers<br />Determine what you want your program/code snippet to do<br />Think of some “keywords” to describe it (if you know the functions you need to use, you’re ahead of the game)<br />http://www.google.com (add “VB” or “Visual Basic”)<br />Ctrl-C<br />Ctrl-V<br />Tweak<br />Test<br />Tweak<br />Test<br />Repeat steps 6-10 ad nauseum<br />Also check out<br />www.krugle.org and<br />www.sourceforge.net<br />Also look to VBA/VSTA and SW API Help files. <br />They’re actually somewhat helpful with good examples. <br />I know! I was shocked, too.<br />
  9. 9. Object-Oriented Programming**<br />“Everything you need to do in the SolidWorks API has to be done by or to an object.”<br />Class – A definition (blueprint) of something (think: blank spec for a washer or bolt)<br />Interface – A more generic definition incorporating multiple classes (ex. Hardware)<br />Object – A specific instance of a class (completed spec - ex. 1/4-20 x 3 SHCS)<br />Property – A parameter value that an object has (ex. Diameter)<br />Method – Something (sub or function) that an object can do (ex. Install)<br />Accessor – A method used to get an object (ex. GetFeature, GetChildren)<br />Dot(.) –Separates an object from its property or method or “child” objects<br />Ex. Bolt.Length or Bolt.Thread.item(“Lead”).Pitch<br />Instantiate – To make a real thing as defined by a class<br />Ex. Upper Flange Bolt #3 or Rear Axle Nut<br />Those are then called “instances” and “objects”<br />**To appease any true code junkies out there. VBA doesn’t REALLY support full OOP with inheritance and polymorphism, but this is a DEMYSTIFYING session. I don’t want to MYSTIFY this stuff any more than it is.<br />
  10. 10. SolidWorks Objects<br />“Everything you need to do in the SolidWorks API has to be done by or to an object.”<br />Everything in SolidWorks (even SolidWorks itself) has an object<br />The SolidWorks Object Model is a hierarchy of objects/classes/interfaces<br />You use an object higher in the tree to fetch an object “beneath” it (accessors)<br />Be prepared to go several steps down (objects beget objects beget objects…)<br />Be VERY SPECIFIC as to what type of objects you have (fully qualified)<br />Easier to read<br />Easier to write (Microsoft will help you)<br />Learn your way around the HELP file to figure out the object path you need<br />Throwing darts is most effective in many cases<br />
  11. 11. The SolidWorks API Object Example (VBA)<br />Early Bound Object Declarations aka “Fully Qualified” (+5 Style Points)<br />Object assignment (instantiation) requires the keyword Set in VBA only<br />HoleDepth and HoleDiameter are Properties<br />of the WizardHoleFeatureData2 object<br />Example: Creating a Hole Wizard Hole<br />Dim swApp As SldWorks.SldWorks<br />Dim swModel As SldWorks.ModelDoc2<br />Dim swFeatMgr As SldWorks.FeatureManager<br />Dim swFeat As SldWorks.Feature<br />Dim swWzdHole As WizardHoleFeatureData2<br />Set swApp = Application.SldWorks<br />Set swModel = swApp.ActiveDoc<br />Set swFeatMgr = swModel.FeatureManager<br />…more code here…<br />Set swWzdHole = swFeatMgr.CreateDefinition(swFmHoleWzd)<br />swWzdHole.HoleDepth = 0.15<br />swWzdHole.HoleDiameter = 0.0555<br />…<br />Set swFeat = swFeatMgr.CreateFeature(swWzdHole)<br />…more code here…<br />CreateDefinition and CreateFeature are Methods (functions)<br />
  12. 12. Seek Professional HelpAn Interface Definition in the API Help<br />
  13. 13. Seek Professional HelpAn Interface Definition in the API Help<br /> Members = Properties and Methods<br />
  14. 14. Seek Professional HelpAn Interface Definition in the API Help<br />Properties have Get and/or Set<br /> x = object.property (Get)<br />object.property = x (Set)<br />Methods are actions an object performs<br />
  15. 15. Seek Professional HelpAn Interface Definition in the API Help<br />This has Get only. It’s an accessor.<br />
  16. 16. Seek Professional HelpAn Interface Definition in the API Help<br />This is no longer a property. It now uses methods to get and set it.<br />(And forget it)<br />
  17. 17. Seek Professional HelpAn Interface Definition in the API Help<br />Old functions never die…<br />
  18. 18. The SolidWorks API Development Process<br />
  19. 19. API Sample #1<br />Cycle Through All Configurations of a Part<br />
  20. 20. What The Macro Does<br />Grabs the current open part document (Works only for parts)<br />Grabs a list of all of the configuration names<br />Loops through the configurations one at a time<br />Changes the Material of the configuration<br />Saves a PDF of the configuration<br />Sets a configuration-specific custom property value<br />
  21. 21. Important Concepts – Example 1<br />Programmatic Framework<br />Accessing Objects<br />ModelDoc/PartDoc Objects<br />Accessing / Looping Through Configurations<br />Editing Material Properties<br />SaveAs – Exporting File Formats<br />Adding Custom Properties<br />
  22. 22. The SolidWorks API Development Process<br />
  23. 23. Macro Record (VB.NET) – 1 of 2<br />Legend<br />Imports SolidWorks.Interop.sldworks<br />Imports SolidWorks.Interop.swconst<br />Imports System<br />Partial Class SolidWorksMacro<br />  Public Sub main()<br />  Dim swDoc As ModelDoc2 = Nothing<br /> Dim swPart As PartDoc = Nothing<br /> Dim swDrawing As DrawingDoc = Nothing<br /> Dim swAssembly As AssemblyDoc = Nothing<br /> Dim boolstatus As Boolean = false<br /> Dim longstatus As Integer = 0<br /> Dim longwarnings As Integer = 0<br />swDoc = CType(swApp.ActiveDoc,ModelDoc2)<br />boolstatus = swDoc.Extension.SelectByID2(&quot;Unknown&quot;, &quot;BROWSERITEM&quot;, 0, 0, 0, false, 0, Nothing, 0)<br /> swDoc.ClearSelection2(true)<br />swPart = CType(swDoc,PartDoc)<br /> swPart.SetMaterialPropertyName2(&quot;Copper&quot;, &quot;C:/Program Files/SW/lang/english/sldmaterials/SolidWorks &quot;& _ <br /> &quot;Materials.sldmat&quot;, &quot;Copper&quot;)<br />useless Content<br />
  24. 24. Macro Record (VB.NET) – 2 of 2<br /> swDoc.ClearSelection2(true)<br />boolstatus = swDoc.Extension.SelectByID2(&quot;Brass&quot;, &quot;CONFIGURATIONS&quot;, 0, 0, 0, false, 0, Nothing, 0)<br />boolstatus = swDoc.Extension.SelectByID2(&quot;Brass&quot;, &quot;CONFIGURATIONS&quot;, 0, 0, 0, false, 0, Nothing, 0)<br />boolstatus = swDoc.Extension.SelectByID2(&quot;Brass&quot;, &quot;CONFIGURATIONS&quot;, 0, 0, 0, false, 0, Nothing, 0)<br />boolstatus = swDoc.Extension.SelectByID2(&quot;Brass&quot;, &quot;CONFIGURATIONS&quot;, 0, 0, 0, false, 0, Nothing, 0)<br />boolstatus = swDoc.ShowConfiguration2(&quot;Brass&quot;)<br />boolstatus = swDoc.Extension.SelectByID2(&quot;Unknown&quot;, &quot;BROWSERITEM&quot;, 0, 0, 0, false, 0, Nothing, 0)<br /> swDoc.ClearSelection2(true)<br />End Sub<br /> <br />&apos;&apos;&apos; &lt;summary&gt;<br /> &apos;&apos;&apos; The SldWorksswApp variable is pre-assigned for you.<br /> &apos;&apos;&apos; &lt;/summary&gt;<br />Public swApp As SldWorks<br /> <br />End Class<br />The Summary explains what the macro does and how it works (that’s why it’s shoved at the end like an afterthought)<br />This is SUCH an important variable that SolidWorks makes it PUBLIC (then stuffs it at the end where nobody sees it)<br />
  25. 25. Basic Framework (VB.NET)<br />(Final code does NOT have these)<br />Imports SolidWorks.Interop.sldworks<br />Imports SolidWorks.Interop.swconst<br />Partial Class SolidWorksMacro<br /> <br />&apos;&apos;&apos; &lt;summary&gt;<br /> &apos;&apos;&apos; Put a description, tracking and revision information here<br /> &apos;&apos;&apos; &lt;/summary&gt;<br />Public swApp As SldWorks<br /> Public Sub main()<br />Your code goes here <br />End Sub ‘main<br />End Class ‘SolidWorksMacro<br />Shortcut<br />Shortcut<br />!!!ALWAYS Use <br />macro record <br />or <br />Tools&gt;Macro&gt;New!!!<br />
  26. 26. Basic Framework (VB.NET)<br />Imports SolidWorks.Interop.sldworks<br />Imports SolidWorks.Interop.swconst<br />Partial Class SolidWorksMacro<br /> <br />&apos;&apos;&apos; &lt;summary&gt;<br /> &apos;&apos;&apos; Put a description, tracking and revision information here<br /> &apos;&apos;&apos; &lt;/summary&gt;<br />Public swApp As SldWorks<br /> Public Sub main()<br />Your code goes here <br />End Sub ‘main<br />End Class ‘SolidWorksMacro<br />DO NOT RENAME HERE<br />PARTIAL means there’s other stuff you don’t see…LOTS of it.<br />
  27. 27. Renaming Classes<br />If you feel that you MUST rename things<br />Rename from the Project Explorer<br />It will make the update where it needs to<br />Don’t believe me there’s lots you can’t see? Just click on SHOW ALL.<br />
  28. 28. Basic Framework (VB.NET)<br />Imports SolidWorks.Interop.sldworks<br />Imports SolidWorks.Interop.swconst<br />Partial Class SolidWorksMacro<br /> <br />&apos;&apos;&apos; &lt;summary&gt;<br /> &apos;&apos;&apos; Put a description, tracking and revision information here<br /> &apos;&apos;&apos; &lt;/summary&gt;<br />Public swApp As SldWorks<br /> Public Sub main()<br />Your code goes here <br />End Sub ‘main<br />End Class ‘SolidWorksMacro<br />Move these up from the bottom of the class<br />
  29. 29. The SolidWorks API Development Process<br />
  30. 30. Do Your Research: HELP&gt;API HELP<br />
  31. 31. Keep Following The Trail<br />
  32. 32. We’ve Got a Lead!<br />Variants have (rightly) been BANNED from .NET<br />
  33. 33. OK, Now To Find The Method<br />
  34. 34. OK, Now To Find The Method<br />!!<br />!!<br />!!<br />!!<br />
  35. 35. Performance Characteristics of Key Muppets on Syndicated Educational Television Programs<br />Mandatory Charts (Gratuitous Chart of Fictitious Data)(per Microsoft PowerPoint code 2009 Section XXIV Subsection 441.K.9.ii.v)<br />
  36. 36. The SolidWorks API Development Process<br />
  37. 37. Instantiating an Object Class<br />Visual Basic.NET requires you to declare your variables<br />Declare…<br />PUBLICvariablenameASclassname<br />DIMvariablenameASclassname<br />Assign…<br />variablename = otherVariable.accessor()<br />Sometimes you need to guarantee the class<br />variablename = Ctype(oVar.accessor, Class)<br />variablename = DirectCast(oVar, Class)<br />
  38. 38. Variables! Get Yer Variables Right Here!<br />PUBLIC declare variables that can be used outside of the module<br />Useful for your SldWorks.SldWorks and ModelDoc objects<br />Macro Recorder puts these at the bottom, we recommend the top<br />DIM or PRIVATE declares a variable for use within a function or sub<br />Imports SolidWorks.Interop.Sldworks<br />Partial Class SolidWorksMacro<br />&apos;&apos;&apos;&lt;Summary&gt; <br /> &apos;&apos;&apos;Fill this in at some point<br /> &apos;&apos;&apos;&lt;/Summary&gt;<br /> &apos;Declare the SolidWorks application as global so it can be used throughout the class<br />PublicswApp As SldWorks&apos;SW Application Object<br />PublicSub main()<br />DimbStatusAs Boolean = False ‘Used as SolidWorks return for most functions<br />DimiErrorsAs Integer = 0<br />DimiWarningsAs Integer = 0<br />DimConfigNames() AsString‘The list of names that we’re going to get back<br />Declare and define in one step<br />You can define as you go<br />
  39. 39. You’ve Declared, Now Define<br />SET Keyword is not required for VB.NET or C#.NET (a must in VBA)<br />Macro Record or Tools&gt;Macro&gt;New will get your SolidWorks object for you<br />3 Methods of instantiating your SldWorks.SldWorks Object (VBA)<br />swApp = Application.SldWorks<br />Grabs existing application (open session REQUIRED)<br />OK to use in macros<br />swApp = GetObject( , “SldWorks.Application”)<br />First parameter is a pathname of file to open<br />Second parameter is object class<br />Must have one or the other<br />If no pathname is specified and SolidWorks is not open, error will occur<br />swApp = CreateObject(“SldWorks.Application”)<br />Grabs open SolidWorks application<br />If no SolidWorks application is open, starts a SolidWorks instance<br />
  40. 40. Use swApp.ActiveDoc to grab currently open document<br />or ActivateDoc or OpenDoc7 or LoadFile4 or…<br />Ctype guarantees that we’re getting a ModelDoc2 object<br />Check API for return, some return “object”<br />ALWAYS TEST FOR PRESENCE OF AN OBJECT<br />&apos;Grab the object for the Active SolidWorks Model<br />DimswDocAs ModelDoc2 <br />swDoc = CType(swApp.ActiveDoc, ModelDoc2)<br /> &apos;Make sure that we have a document object<br /> &apos;If we have no model document object to work with, we cannot go on<br />IfswDocIs Nothing Then Exit Sub<br />Got ModelDoc2?<br />got 3D?<br />Test Early, Test Often<br />
  41. 41. What is ModelDoc2?...Part? Assembly? Drawing? Yup.<br />PartDoc Object<br />MirrorPart<br />SetMaterialPropertyName2<br />AssemblyDoc Object<br />AddComponent<br />EditMate<br />DrawingDoc Object<br />ActivateView<br />InsertWeldSymbol<br />ModelDoc2 Object<br /><ul><li>CustomInfo
  42. 42. CreateLine
  43. 43. EditConfiguration
  44. 44. FeatureCut
  45. 45. FirstFeature
  46. 46. ForceRebuild
  47. 47. InsertNote
  48. 48. Parameter
  49. 49. SaveAs
  50. 50. SetUnits
  51. 51. SketchFillet
  52. 52. …everything else useful</li></ul>ModelDoc2.Extension<br /><ul><li>CreateMeasure
  53. 53. GetAnnotations
  54. 54. InsertBomTable
  55. 55. SaveAs
  56. 56. SetUserPreferencex
  57. 57. …and lots more</li></li></ul><li>Use ModelDoc2 to Get Configuration Names<br />GetConfigurationNames returns an array of strings with our configuration names<br />Test to make sure that we have names<br />For Each…Next loop cycles through entries in an array<br />We dimension new variables “inline” as we go<br />&apos;Get the list of configuration names. This will be blank where it&apos;s not appropriate.<br />ConfigNames = swDoc.GetConfigurationNames<br />IfConfigNames.Length &gt;= 1 Then<br />For Each ConfigNameAs String In ConfigNames<br />&apos;Switch to the current configuration<br />bStatus = swDoc.ShowConfiguration2(ConfigName)<br />&apos;Rebuild the Model<br />bStatus = swDoc.ForceRebuild3(True)<br />Must be an array or collection of strings to use For Each …In…<br />These methods return a boolean (True/False) indicating success. We can (and should) test it.<br />(NextConfigName– will be coming later)<br />
  58. 58. The SolidWorks API Development Process<br />
  59. 59. Get PartDoc and Change Materials<br /><ul><li>We know that Material requires the PartDoc Object
  60. 60. PartDoc comes directly from ModelDoc2 (DirectCast)
  61. 61. So do AssemblyDoc and DrawingDoc
  62. 62. If there’s a doubt, use Ctype (IF typeofswPart IS PartDoc…)
  63. 63. WARNING!! You may suffer SEVERAL MILLISECONDS performance degradation!!</li></ul>&apos;Setting the Material is a method of the PartDoc object. We get that object by recasting the ModelDoc2 object.<br />&apos;WE ONLY USE DIRECTCAST BECAUSE WE’VE TESTED swDoc.GetType. WE ARE CERTAIN IT IS A PART!!!<br />DimswPartAsPartDoc = DirectCast(swDoc, PartDoc)<br />…Back in the loop…<br />&apos;Set the material property for this configuration. This assumes that the configuration name matches an existing material.<br />swPart.SetMaterialPropertyName2(ConfigName, “M:/RazorleafMatlLib/Materials.sldmat&quot;, ConfigName)<br />We want to do this outside the loop so we only do it once<br />
  64. 64. Save the Model Out As a PDF<br />&apos;Do a zoom to fit<br />swDoc.ViewZoomtofit2()<br />&apos;Retrieve the full pathname including the file name<br />DimsFileNameAsString = swDoc.GetPathName<br />&apos;Remove the extension<br />sFileName = sFileName.Remove(sFileName.LastIndexOf(&quot;.&quot;)) &apos;remove all text after the last dot<br />bStatus = swDoc.Extension.SaveAs(sFileName & &quot;_&quot; & ConfigNames(index) & &quot;.pdf&quot;, _<br />swSaveAsVersion_e.swSaveAsCurrentVersion, _<br />swSaveAsOptions_e.swSaveAsOptions_Silent, _<br /> Nothing, iErrors, iWarnings)<br />.NET string members, check ‘em out!<br />_ means “Continued on next line”<br /> Must have a space before it<br />enumerations<br />More return values, listed as ByRef in the Class Definition<br />
  65. 65. Enumerations<br />Parameter values can be integer or long in many cases<br />What is the integer for SolidWorks 2009?<br />Enumerations replace numbers<br />IMPORTS SolidWorks.Interop.swconst<br />That’s the Type Constant Library<br />My code fully qualifies<br />Intellisense will help you if you fully qualify<br />Enumerations are more readable <br />ByVal means input<br />ByRef means output<br />
  66. 66. Set Configuration-Specific Custom Property<br /><ul><li>AddCustomInfo3 allows you to specify a configuration
  67. 67. Be sure to comment your loop and IF closers</li></ul> swDoc.AddCustomInfo3(ConfigName, &quot;Material Code&quot;, _<br />swCustomInfoType_e.swCustomInfoText, ConfigName.Remove(4))<br />NextConfigName&apos;move to the next configuration<br />End If &apos;there are one or more configurations in the document<br />End Sub ‘main<br />End Class ‘SolidWorksMacro<br />Another kewl .NET string function<br />Documenting here makes blocks easier to follow and troubleshoot<br />
  68. 68. Configuration Master 5000 <br />Complete Code<br />
  69. 69. Final Code: Configuration Master 5000 (Part 1 of 5)<br />Partial Class SolidWorksMacro<br />&apos;&apos;&apos;&lt;Summary&gt;<br /> &apos;&apos;&apos;Sample Code for SolidWorks World 2010: Demystifying the SolidWorks API<br /> &apos;&apos;&apos;Razorleaf Corporation -- Paul Gimbel -- January 20, 2010<br /> &apos;&apos;&apos;This macro loops through all of the configurations of a part<br /> &apos;&apos;&apos;For each configuration, it saves a PDF, changes the material of the configuration and adds a configuration-specific custom property<br /> &apos;&apos;&apos;See the Powerpoint Presentation (available from www.razorleaf.com) for complete documentation of the code<br /> &apos;&apos;&apos;&lt;/Summary&gt;<br /> &apos;Declare the SolidWorks application as a global variable so it can be used throughout the class<br />PublicswApp As SolidWorks.Interop.sldworks.SldWorks &apos;SolidWorks Application Object<br />PublicSub main()<br />DimbStatusAs Boolean = False<br />DimiErrorsAs Integer = 0<br />DimiWarningsAs Integer = 0<br />DimConfigNames() AsString<br />
  70. 70. Final Code: Configuration Master 5000 (Part 2 of 5)<br /> &apos;Grab the object for the Active SolidWorks Model<br />DimswDocAs SolidWorks.Interop.sldworks.ModelDoc2 = CType(swApp.ActiveDoc, SolidWorks.Interop.sldworks.ModelDoc2)<br /> &apos;Make sure that we got a document object<br />IfswDocIs Nothing Then Exit Sub &apos;We have no model document to work with, we cannot go on<br /> &apos;This macro is only for part models. Check what type of document we have.<br />IfswDoc.GetType &lt;&gt; SolidWorks.Interop.swconst.swDocumentTypes_e.swDocPARTThen Exit Sub<br /> &apos;Get the list of configuration names. This will be blank where it&apos;s not appropriate.<br />ConfigNames = swDoc.GetConfigurationNames<br /> &apos;Setting the Material is a method of the PartDoc object. We get that object by recasting the ModelDoc2 object.<br /> &apos;WE ONLY USE DIRECTCAST BECAUSE WE HAVE ALREADY TESTED swDoc.GetType. WE ARE CERTAIN IT IS A PART!!!<br />DimswPartAsSolidWorks.Interop.sldworks.PartDoc = DirectCast(swDoc, SolidWorks.Interop.sldworks.PartDoc)<br /> If ConfigNames.Length &gt;= 1 Then<br />For Each ConfigNameAs String In ConfigNames<br /> &apos;Switch to the current configuration<br />bStatus = swDoc.ShowConfiguration2(ConfigNames(index))<br />
  71. 71. Final Code: Configuration Master 5000 (Part 3 of 5)<br /> &apos;&apos;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<br /> &apos;&apos;Drive the material to be equal to the configuration name<br /> &apos;&apos;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<br /> &apos;Set the material property for this configuration. This assumes that the configuration name matches an existing material.<br /> swPart.SetMaterialPropertyName2(ConfigNames(index), _<br /> &quot;C:/Program Files/SolidWorks Corp/SolidWorks/lang/english/sldmaterials/SolidWorks &quot; & &quot;Materials.sldmat&quot;, _<br />ConfigNames(index))<br />
  72. 72. Final Code: Configuration Master 5000 (Part 4 of 5)<br /> &apos;&apos;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<br /> &apos;&apos;Save this configuration out as a PDF<br /> &apos;&apos;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<br /> &apos;Do a zoom to fit<br /> swDoc.ViewZoomtofit2()<br /> &apos;Retrieve the full pathname including the file name<br />DimsFileNameAsString = swDoc.GetPathName<br />&apos;Remove the extension<br />sFileName = sFileName.Remove(sFileName.LastIndexOf(&quot;.&quot;)) &apos;remove from the location of the last dot on to the end<br />bStatus = swDoc.Extension.SaveAs(sFileName & &quot;_&quot; & ConfigNames(index) & &quot;.pdf&quot;, _<br /> SolidWorks.Interop.swconst.swSaveAsVersion_e.swSaveAsCurrentVersion, _<br /> SolidWorks.Interop.swconst.swSaveAsOptions_e.swSaveAsOptions_Silent, _<br />Nothing, iErrors, iWarnings)<br />
  73. 73. Final Code: Configuration Master 5000 (Part 5 of 5)<br /> &apos;&apos;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<br /> &apos;&apos;Create a configuration specific custom property - <br /> &apos;&apos; Material Code = 1st 4 letters of the material<br /> &apos;&apos;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;<br /> &apos;Setting the Material is a method of the PartDoc object. We get that object by recasting the ModelDoc2 object.<br /> swDoc.AddCustomInfo3(ConfigNames(index), &quot;Material Code&quot;, _<br />SolidWorks.Interop.swconst.swCustomInfoType_e.swCustomInfoText, _<br />ConfigNames(index).Remove(4))<br />NextConfigName&apos;move to the next configuration<br />End If &apos;there are one or more configurations in the document<br />End Sub ‘main<br />End Class ‘SolidWorksMacro<br />
  74. 74. The SolidWorks API Development Process<br />
  75. 75. API Example #2<br />Suppressing Pattern Instances<br />
  76. 76. Delete Pattern Instances<br />Part has one or more linear patterns<br />Custom property stores a text string of Xs and Os<br />X means there will be an instance here<br />O means that instance will be removed<br />Main Errors to check for:<br />No pattern features<br />No instance to suppress<br />Text string length ≠ Number of pattern instances<br />XOOXXOXOOXOXOOXOXOOXOXOO<br />
  77. 77. Important Concepts – Example 2<br />Accessing Feature objects<br />Looping through all features in a part<br />Handling FeatureData objects<br />Reading custom properties<br />
  78. 78. The SolidWorks API Development Process<br />
  79. 79. Recorded Macro: Remove Pattern Instances<br />Legend<br /> Public Sub main()<br /> Dim swDoc As ModelDoc2 = Nothing<br /> Dim swPart As PartDoc = Nothing<br /> Dim swDrawing As DrawingDoc = Nothing<br /> Dim swAssembly As AssemblyDoc = Nothing<br /> Dim boolstatus As Boolean = false<br /> Dim longstatus As Integer = 0<br /> Dim longwarnings As Integer = 0<br />swDoc = CType(swApp.ActiveDoc,ModelDoc2)<br /> Dim myModelView As ModelView = Nothing<br />myModelView = CType(swDoc.ActiveView,ModelView)<br />myModelView.FrameState = CType(swWindowState_e.swWindowMaximized,Integer)<br />boolstatus = swDoc.Extension.SelectByID2(&quot;HolePattern&quot;, &quot;BODYFEATURE&quot;, …)<br /> swDoc.ClearSelection2(true)<br />boolstatus = swDoc.Extension.SelectByID2(&quot;&quot;, &quot;EDGE&quot;, -0.04, 0.0127,…)<br />boolstatus = swDoc.Extension.SelectByID2(&quot;&quot;, &quot;EDGE&quot;, -0.1016, …)<br />swDoc.ActivateSelectedFeature()<br /> End Sub<br />Helpful Content<br />
  80. 80. The SolidWorks API Development Process<br />
  81. 81. Seek the Path of Enlightenment<br />How do we get the info we need out of the object?<br />How do we get the object?<br />
  82. 82. Find The Right Property or Method<br />
  83. 83. OK, So How Do We Get The Object, Then?<br />Accessors List<br />
  84. 84. IFeature.ILinearPatternFeatureData.SkippedItemArray<br />Let’s limit it to just ModelDoc2 and PartDoc<br />Once you have a feature, you can use it to get the next one<br />
  85. 85. The Full Object Path<br />ModelDoc2<br />Feature<br />Feature IS Linear Pattern<br />Feature IS NOT Linear Pattern<br />LinearPattern<br />FeatureData<br />
  86. 86. The SolidWorks API Development Process<br />
  87. 87. Set up the Framework and Grab the ModelDoc2<br />IMPORTS SolidWorks.Interop.sldworks<br />IMPORTS SolidWorks.Interop.swconst<br />Partial Class SolidWorksMacro<br />&apos;&apos;&apos; &lt;summary&gt;<br /> &apos;&apos;&apos; Don’t forget to put this in at some point!!<br /> &apos;&apos;&apos; &lt;/summary&gt;<br />PublicswAppAsSldWorks<br />Public Sub main()<br />‘A nice description here goes a long way!<br />&apos;Get currently open document<br />DimswPartAs ModelDoc2 = CType(swApp.ActiveDoc, ModelDoc2)<br />&apos;Make sure that we have an object<br />IfswDocIs Nothing Then Exit Sub<br /> &apos;This macro is only for part models. Check our document type.<br />IfswDoc.GetType &lt;&gt; swDocumentTypes_e.swDocPARTThen Exit Sub<br />
  88. 88. The SolidWorks API Development Process<br />
  89. 89. Test for Proper Conditions and Get Feature Object<br />&apos;Fetch the custom property list<br />DimsInputListAs String = swDoc.GetCustomInfoValue(&quot;&quot;, &quot;SkipList&quot;)<br />&apos;If the list does not exist, exit out of the function. We do not need to run the macro.<br /> If sInputList.Length &lt; 1 Then Exit Sub<br /> &apos;Get the first feature in the part. <br /> &apos;NOTE!! THIS DOES NOT MEAN THE BASE EXTRUSION. <br /> &apos;There are reference features.<br />DimswFeatureAs Feature <br />swFeature = swDoc.FirstFeature()<br />Declare as you define<br />Always put your tests up front - Try to run as little code as possible<br />Look how far down the tree the base extrusion is!<br />
  90. 90. Loop the Loop<br />&apos;We know from our research that we&apos;ll need the LinearPatternFeatureData<br /> &apos; object, the feature type, and some indices. <br /> &apos;We&apos;ll declare them outside of the loop so they only get declared once.<br />DimswFeatureDataAsLinearPatternFeatureData<br />DimsFeatureTypeAs String &apos;Type of feature<br />DimiRowsAs Integer &apos;Number of rows in the pattern<br />DimiColsAs Integer &apos;Number of columns in the pattern<br />DimTempStringAs String = &quot;&quot;<br /> Do While swFeatureIsNotNothing&apos;loop through the features<br /> …OUR CODE GOES HERE…<br />Loop<br />DO WHILE tests BEFORE running any code<br />(Do … Loop Until tests after)<br />Got an object? <br />IsNot Nothing will tell you<br />
  91. 91. Looping and Testing<br />Do While swFeatureIsNotNothing&apos;loop through the features<br />&apos;Check to see if this is a pattern feature<br />sFeatureType = swFeature.GetTypeName2<br />IfsFeatureType = &quot;LPattern&quot; Then&apos;we have a pattern to process<br />swFeatureData = swFeature.GetDefinition&apos;get the feature data<br />iRows = swFeatureData.D1TotalInstances<br />iCols = swFeatureData.D2TotalInstances<br /> &apos;Check to ensure that list matches pattern size<br />IfsInputList.Length = iRows * iColsThen&apos;we&apos;re good to go<br />… The actual work goes here…<br />End If &apos;The list length matches the pattern size<br />End If &apos;This is a linear pattern feature<br />Loop &apos;through the features<br />Browse API Help<br />to see properties<br />Test Early, Test Often<br />
  92. 92. Arrays and Collections<br />Array<br />Think of it as a bin system for values<br />Can be 1D, 2D or more<br />It’s a fixed size (you need to REDIM to change it)<br />Tough to move things around in<br />Collection<br />Think of it as a collection of stackable bins<br />Need another? Just add it!<br />Rearranging, sorting, searching…no prob, Bob!<br />Don’t know collections? Take the time to look them up!!<br />7<br />5<br />9<br />11<br />7<br />8<br />5<br />2<br />1<br />2<br />2<br />2<br />3<br />0<br />10<br />3<br />4<br />3<br />6<br />4<br />6<br />9<br />2<br />6<br />
  93. 93. Numbering Sequence for Linear Pattern Instances<br />SEED = 0 <br />(Row 1, Col 1)<br />5<br />10<br />15<br />20<br />(2, 1)=1<br />6<br />11<br />16<br />21<br />(3, 1)=2<br />7<br />12<br />17<br />22<br />(4, 1)=3<br />8<br />13<br />18<br />23<br />(5, 1)=4<br />9<br />14<br />19<br />24<br />
  94. 94. Create the Skipped Instance Array<br />&apos;Create a collection for the list of instances to be skipped<br />DimSkipColAs New System.Collections.Generic.List(OfInteger)<br />&apos;Go through the characters in the string finding the O&apos;s and add that index<br />For Index As Integer = 0 TosInputList.Length - 1<br /> IfsInputList.Substring(Index, 1).Equals _<br /> (&quot;O&quot;, StringComparison.CurrentCultureIgnoreCase) Then<br /> &apos;add this to the list of excluded items<br />SkipCol.Add(Index)<br /> End If &apos;we need to add this entry to the skipped list<br />Next Index &apos;move to the next character in the string<br />Substrings start at 0<br />String method .Equals<br />How can I remember that?!!? You don’t. Intellisense gives it to you!<br />The input list “XXOOXOXO”…<br />…results in the collection: (2,3,5,7)<br />0<br />1<br />2<br />3<br />4<br />5<br />6<br />7<br />
  95. 95. Update the Feature and Error Handling<br /> &apos;pass the collection as an array to the LinearPatternFeatureData object<br />swFeatureData.SkippedItemArray = SkipCol.ToArray()<br /> &apos;Tell SolidWorks to update the LinearPattern with the new information<br />swFeature.ModifyDefinition(swFeatureData, swDoc, Nothing)<br /> &apos;Rebuild the model<br /> swPart.ForceRebuild3(False)<br />Else&apos;the input size doesn&apos;t match the pattern size<br />DIMsMessageAs String = &quot;Pattern Size &quot;& (iRows * iCols) &&quot;doesn’t match input size &quot;&sInputList.Length<br />System.Windows.Forms.MessageBox.Show(sMessage)<br /> swPart.AddCustomInfo3(&quot;&quot;, &quot;Code Errors&quot;, 30, sMessage)<br />End If&apos;the input size matches the pattern size<br />One of many collection methods<br />These methods are subs, no returns<br />& joins strings and values<br />“I’m “ & iAge & “ years old” <br />= “I am 4257 years old” <br />
  96. 96. The Amazing Disappearing Pattern Instance trick<br />Complete Code<br />
  97. 97. Finished Code (Part 1 of 4)<br />Partial Class SolidWorksMacro<br />&apos;&apos;&apos; &lt;summary&gt;<br /> &apos;&apos;&apos;Sample Code #2 for SolidWorks World 2010: Demystifying the SolidWorks API<br /> &apos;&apos;&apos;Razorleaf Corporation -- Paul Gimbel -- January 20, 2010<br /> &apos;&apos;&apos;This macro removes instances within a linear pattern based on a string input of X&apos;s and O&apos;s stored in a custom property.<br /> &apos;&apos;&apos;The code loops through all of the features of a part looking for linear patterns.<br /> &apos;&apos;&apos;For each linear pattern that it finds, it compares the input string length to the pattern size.<br /> &apos;&apos;&apos;If the string matches the pattern, the code builds the SkippedInstanceArray and updates the pattern.<br /> &apos;&apos;&apos;See the Powerpoint Presentation (available from www.razorleaf.com) for complete documentation of the code<br /> &apos;&apos;&apos; &lt;/summary&gt;<br />DimswAppAsSolidWorks.Interop.sldworks.SldWorks<br />Public Sub main()<br />&apos;Reads a list stored as a string from a custom property named &quot;SkipList&quot; (populated by DriveWorks)<br /> &apos;This list will contain an &quot;X&quot; if the pattern instance is to be there and an &quot;O&quot; (Letter Oh) if it is to be removed<br /> &apos;The list walks down a column, then starts at the next column, just as SolidWorks does<br /> &apos;When Skipping, the instances are numbered as such (Row,Col):<br /> &apos; (1,1) = 0, (2,1) = 1, (3,1) = 2<br /> &apos; For a 3x3 array, (1,2) = 3, (2,2) = 4 and so on.<br />&apos;Get currently open document<br />DimswPartAs SolidWorks.Interop.sldworks.ModelDoc2 = CType(swApp.ActiveDoc, SolidWorks.Interop.sldworks.ModelDoc2)<br />
  98. 98. Finished Code (Part 2 of 4)<br />&apos;Fetch the custom property list<br />DimsInputListAs String = swPart.GetCustomInfoValue(&quot;&quot;, &quot;SkipList&quot;)<br />&apos;If the list does not exist, exit out of the function. We do not need to run the macro.<br /> If sInputList.Length &lt; 1 Then Exit Sub<br />&apos;Get the first feature in the part. NOTE!! THIS DOES NOT MEAN THE BASE EXTRUSION. There are reference features.<br />DimswFeatureAsSolidWorks.Interop.sldworks.Feature = swPart.FirstFeature()<br />&apos;We know from our research that we&apos;ll need the LinearPatternFeatureData object, the feature type, and some indices. <br /> &apos;We&apos;ll declare them outside of the loop so that they only get declared once.<br />DimswFeatureDataAsSolidWorks.Interop.sldworks.LinearPatternFeatureData<br />DimsFeatureTypeAs String &apos;Type of feature to test to see if it&apos;s a linear pattern<br />DimiRowsAs Integer &apos;Number of rows in the pattern<br />DimiColsAs Integer &apos;Number of columns in the pattern<br />DimTempStringAs String = &quot;&quot;<br />Do While swFeatureIsNotNothing&apos;loop through the features checking to see if the feature is a pattern<br />&apos;Check to see if this is a pattern feature<br />sFeatureType = swFeature.GetTypeName2<br />IfsFeatureType = &quot;LPattern&quot; Then&apos;we have a pattern to process<br />swFeatureData = swFeature.GetDefinition&apos;get the feature information object<br />iRows = swFeatureData.D1TotalInstances &apos;get the information that we want<br />iCols = swFeatureData.D2TotalInstances<br /> &apos;Check to ensure that list matches pattern size<br />IfsInputList.Length = iRows * iColsThen&apos;we&apos;re good to go<br />
  99. 99. Finished Code (Part 3 of 4)<br />&apos;Create a collection for the list of instances to be skipped<br />DimSkipColAs New System.Collections.Generic.List(OfInteger)<br />&apos;Go through the collection finding the O&apos;s and add the index of that character to the collection<br />For Index As Integer = 0 TosInputList.Length - 1 &apos;cycle through the characters in the string<br />IfsInputList.Substring(Index, 1).Equals(&quot;O&quot;, StringComparison.CurrentCultureIgnoreCase) Then<br />&apos;add this to the list of excluded items<br />SkipCol.Add(Index)<br />TempString = TempString & CStr(Index)<br />End If &apos;we need to add this entry to the skipped list<br />Next Index &apos;move to the next character in the string<br />&apos;Convert the collection into an array and pass it to the LinearPatternFeatureData object<br />swFeatureData.SkippedItemArray = SkipCol.ToArray()<br />&apos;Tell SolidWorks to update the LinearPattern with the new information<br />swFeature.ModifyDefinition(pFeatureData, pPart, Nothing)<br />Else&apos;the input size doesn&apos;t match the pattern size<br />&apos;During testing you can have it pop up a message box<br /> &apos;System.Windows.Forms.MessageBox.Show _<br /> &apos; (&quot;Pattern Size (&quot; & iRows * iCols & &quot;) does not match input size (&quot; & Len(sInputList) & &quot;)&quot;)<br /> &apos;During Production, have it write the error to a custom property<br /> swPart.AddCustomInfo3(&quot;&quot;, &quot;Code Errors&quot;, 30, &quot;Pattern Size (&quot; & iRows * iCols & &quot;) does not match input size (&quot; & sInputList.Length & &quot;)&quot;)<br />
  100. 100. Finished Code (Part 4 of 4)<br />End If &apos;there are the correct number of entries in the list<br />End If &apos;this is a pattern feature<br />&apos;Go fetch the next feature<br />swFeature = swFeature.GetNextFeature<br />Loop&apos;while pFeatureIsNot Nothing<br />End Sub &apos;main<br />End Class &apos;PARTIAL SolidWorksMacro<br />
  101. 101. PROGRAMMING Best Practices<br />What Not To Wear: SolidWorks API Edition<br />
  102. 102. Programming Tips For SolidWorks<br />DOCUMENT THE $#^@ OUT OF EVERYTHING!!!<br />Anything after an apostrophe in VB (‘) or (//) in C# is a comment…use them!!<br />Intellisense…good. Typing…bad.<br />If you don’t see the option that you need, something’s wrong.<br />Test for Errors<br />Don’t run code if you don’t have to<br />Runtime errors make you look like a doofus<br />Compile and Test Often<br />Programmatic sanity checks<br />Insert Test Code (Debug.Print, msgbox, extraneous IF’s you can comment out)<br />Use Debug Tools<br />Step Into, Step Over, Watches, Breakpoints, Immediate window, Stack trace, …<br />Errors/Warnings window at the bottom IS YOUR FRIEND!!<br />
  103. 103. Documenting Your Code - Comments<br />VB will ignore anything after an apostrophe (‘)<br />C# will ignore anything after two forward slashes (//)<br />The editor will turn all comments green<br />Turn your code into complete sentences<br />IfswSensor.SensorType = swSensorDimensionThen‘find the dimension<br />Else‘we need to see if this is a mass property sensor<br />End If ‘this is a dimension sensor<br />Keep track of the end of nested loops and if statements (don’t miss them!)<br />End If ‘the width is over the threshold value<br />End If ‘the width is greater than the length<br />Create section headers (Visual Studio has tools for this as well)<br />‘Set all of the hole wizard feature parameters<br />
  104. 104. Early Binding and Fully Qualifying – Great Practices<br />Option Explicit in VBA (implicit in VB.NET and C#.NET)<br />DIMswFeatureAs Object<br />Perfectly legal (with IMPORTS), but sloppy<br />DIMswFeatureAsSolidWorks.Interop.sldWorks.Feature = swPart.GetFirstFeature<br />Better documented<br />Will catch more errors<br />Enables Intellisense<br />
  105. 105. Error Trapping<br />End Users do NOT take errors well<br />Small errors can snowball<br />TRY…CATCH<br />OnErrorGotoerrhandler<br />errhandler:<br />Iferr.number &gt; 0 Then‘we have an error, deal with it<br />msgbox(“You have a problem with ” & err.description)<br />EndIf‘we have an error<br />ALWAYS test for objects<br />IfswFeatureIsNotNOTHINGThen‘we have a feature, go<br />Watch for data types and illegal values (negatives, zeroes, “artichoke”, etc.)<br />Look for anything that will make your code or SolidWorks barf<br />
  106. 106. Go Hungarian!<br />Hungarian Notation places the data type at the front of the variable name<br />Examples:<br />Dim iCounter as Integer<br />Dim bResult as Boolean<br />Dim dLength as Double<br />Dim swApp as SolidWorks.Interop.SldWorks.SldWorks<br />(here “sw” indicates it’s a SolidWorks object)<br />Microsoft (and Bob) now recommends against it – The Sherpa recommends it!!<br />But Visual Studio Intellisense tells you the data type, it’s redundant<br />VBA doesn’t have that feature<br />Neither does my printer<br />What if the data type changes!??!!?<br />Find/Replace – It’s 5 clicks<br />If you always declare your variables, it’s documented<br />So I have to scroll to the top every time?<br />Violent objection?<br />Don’t use it.<br />Arguments Against HN<br />
  107. 107. Code You Should Know<br />Loops (DO, WHILE, FOR, FOR EACH)<br />IF…THEN…ELSEIF…ELSE (with AND, OR, NOT)<br />SELECT CASE<br />WITH Blocks<br />Msgbox<br />String Manipulation (.Length , .Remove, .Substring, .Trim, …)<br />CHR()<br />Collections and Arrays<br />Exit Sub (-5 Style Points, but it’s cheap and easy)<br />Err Object<br />Math (ABS, Trig, SQRT, Int)<br />File I/O (Write, Print, Input, LineInput, Open Append/Output, Close)<br />DB Access (ODBC, ADODB, DAO)<br />
  108. 108. What Else can the API do?<br />API and Beyooooooooooond<br />
  109. 109. API Areas<br />APIs exist for tons of SolidWorks Modules<br />Automating Design Validation - Tomorrow @ 1:30<br />Integrate with other programs<br />Automating With Excel – Wednesday @ 1:30<br />MathCAD or custom calculation engines<br />Read from/Write to your ERP or other system<br />Allow less-sophisticated users to use advanced features<br />Build an interface for non-SolidWorks users that drives SolidWorks <br />Cut mouse clicks out of your day<br />Automate iterative processes<br />Build the model, run a test, use results to rebuild, run a test, again…<br />
  110. 110. Macro Features - How Will YOU Use Them?<br />Two Steps: 1) Write the macro, 2) Write a macro to insert the macro<br />Macro feature appears in the SolidWorks Feature Manager™<br />Macro is executed based on its position in the Feature Manager™<br />Code is contained in an SWP file or a registered application* on your machine<br />*For the advanced: code must be in an exposed COM DLL or executable<br />Everyone must have access to this code to be able to use it<br />Your code contains 2-4 functions<br />What to do when the macro feature is created (optional)<br />What to do when the macro feature is rebuilt (mandatory)<br />What to do when the macro feature is edited (mandatory)<br />Can feature be deleted, suppressed or edited (VBA = optional, COM = mandatory) <br />If you use multiple (older) versions of SolidWorks and wish to use Macro Features, check out the API Help article on Macro Features and Strong Name Versioning<br />
  111. 111. Questions? Comments? Suggestions? Amusing Pet Stories?<br />If you have questions you would like to discuss, please find me<br />Now…At any time during the conference…or After the conference<br />Presentation available on www.razorleaf.com<br />Free newsletter with tech tips, industry insiders, free code, and more…<br />Catch me in my upcoming tour dates!!<br />Tuesday @ 1:30 – Automating Design Validation with the SolidWorks API<br />Wednesday @ 1:30 – Automating Your Designs with Excel and the SW API<br />The <br />Sherpa<br />Paul Gimbel<br />Business Process Sherpa<br />paul.gimbel@razorleaf.com<br /> www.razorleaf.com<br />TheProcesSherpa on Twitter<br />
  112. 112. SURVEY TIME!!!<br />Paul Gimbel, Razorleaf Corporation<br />paul.gimbel@razorleaf.com<br />@TheProcesSherpa on Twitter<br /><ul><li>PLEASE PLEASEPLEASE fill out your survey
  113. 113. It takes practically no time at all
  114. 114. I HONESTLY want your feedback and I do apply it
  115. 115. Let’s see if the SolidWorks folks read these:</li></ul>PLEASE PLEASEPLEASE fill out your survey<br />It takes practically no time at all<br />I HONESTLY want your feedback and I DO apply it<br />Let’s see if the SolidWorks folks read these:<br />In the comments section, PLEASE end with:<br />“Wow, he was right. These burritos are quite tasty!”<br />

×