Automated Design Validation The Solid Works Api

6,997 views
6,929 views

Published on

This SolidWorks World 2010 presentation by Paul Gimbel from Razorleaf Corporation explores using the SolidWorks API and the tools available within SolidWorks and SolidWorks Simulation to validate automatically generated, and manually configured designs.

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,997
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
211
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • I was a little worried about the title for this one. I tried to word it carefully, because when people hear design validation, they immediately think FEA. Are we going to cover SolidWorks Simulation, yes. We will, but we will also cover other stuff. This is listed as an advanced session because it does assume that you know SolidWorks and it assumes that you know your way around SolidWorks Simulation and it assumes that you understand the basics of the SolidWorks API. If you came to my session yesterday on the API, and you got it, then I think you should be fine as well. The presentation will be made available as quickly as I can on the Razorleaf web site.
  • Here’s the obligatory and cliché review of me and my company. Razorleaf is a services-only company providing implementation and customization, training and support for PDM including EPDM, SmarTeam, Aras, and Matrix, as well as Design Automation (that’s my specialty) including DriveWorks, Tacton, and custom solutions. As I said, services-only, so I won’t be trying to sell you anything, don’t worry.I am Paul Gimbel, known in the SolidWorks community as simply “The Sherpa.” I’ve been to every SolidWorks World, presented at quite a few of them. A trainer and demojock since the original, SolidWorks 95. So yes, I’m old, and starting to look it.
  • So let’s start out with a little bit of a philosophical question. What is design validation? Well, what I mean is ensuring that your design meets the requirements of the job. That could mean form/fit/function, it could mean that it meets minimum weight requirements, like a Tour de France bike, it lives up to performance requirements like the electric hot rod. The requirements could encompass any number of things. Not just will it break.
  • The first way that we were taught to validate is to use formulae. This is the most accurate way to determine values because there’s no approximation. If Roark’s guide to Stress and Strain says that beam will deflect f*h/4 at x/3 from the end, that’s what it’s going to do and where it’s going to do it. But we can’t always come up with an equation, especially for tough geometries. In a lot of industries, there are code calculations that must be met. When I was designing pressure vessels, we had to ship every unit with a copy of the calcs from Section VIII of the B&PV Code. Simulations can be used to validate. Iterations can be used to optimize. Digital Prototyping is the next level and physical prototyping after that. What we learn from programming, though, is don’t bother building a physical prototype and testing it if the standard calculations prove that it’s going to fail. So test early, and test often.
  • Now the other half of the title is Automating. As I said in my intro, I specialize in Design Automation with tools like Tacton and DriveWorks. In these cases, we are rarely interacting with SolidWorks. In most cases, we are having sales folks put info into a system that will have a server automate the design and solid model and 2D drawing construction. So in these cases, we cannot have anything interactive. We can’t have anything that requires the user to have SolidWorks. And in a lot of these cases, there may be a 3rd party product involved. But I’ll tell you right now, none of the design automation solutions that I know of are designed to give you the option to use any of the tools that I’m going to show you today.
  • So there are a bunch of different things that we can do that would fall under this validation umbrella. SolidWorks Simulation, certainly, but I’m a firm believer that before you even get to simulation, there are a bunch of validations that you should be doing that could validate portions of your design to the point that you wouldn’t need to run simulation on those areas. Sensors are a new tool that was pioneered, well, by CATIA. They allow SolidWorks to pop up warnings to the user when criteria are met. They were introduced into SW2009 and I’m sure that they will be improved in further releases of EnoviaWorks. Interference is a validation that we take for granted because we can see them. In automation, though, we can’t. Quite often we need to measure clearances, as well. Mass Props are a big one, too. All, well almost all, of these are basic functionality. But they’re functions that are simply skipped over in an automated environment. Simulation is generally used for two purposes: To generate reports proving/disproving validity, or generating numbers that will be used to modify the design.Other tools outside of SolidWorks should be considered as well. Calculation programs like MathCAD or Maple, or even systems that validate against empirical or tabular data. Only these sizes of o-ring are available. Well, if we’re automatically designing a groove, we need to make sure that the ID is within the stretchy-stretchy range of a standard O-ring. Why not have SolidWorks look it up in a SQL or Access or Excel table? It’s actually not that hard.
  • Let’s take a look at some of these tools and how to automate them for the sake of design validation.
  • OK, this is the list that I would like to address first. Some of them are going to be pretty quick.
  • You can add driven dimensions in a sketch and you can add reference dimensions in any 3D view. When you do this, you will get a reference dimension. Like any other dimension, it has a name. But unlike driving dimensions, you cannot change the name of a reference dimension. Even a driven dimension cannot be changed. Cheap workaround for driven dims is to make it driving, ignore the overdefined messages, change the name, then change it back to driven. Changing ref dimensions is a bit more difficult, and generally not all that important. In terms of the automation, with reference dimensions, all we generally do is to retrieve the value. That’s done fairly easily. Here we’re grabbing a parameter object directly (in other words without declaring a separate variable for a parameter object), and using the GetValue2 method.
  • The measure tool is a little more involved. These is a measure class. You create a measure object. You don’t retrieve it. The Accessor – CreateMeasure on the ModelDoc2.Extension object - actually creates a new object. You then set up the measure the way that you like it. Apply whatever settings you want. Arc options, number of decimal places, and so on. Then you tell it what to calculate, by passing it an array with objects of all of the selections to measure. If this parameter is nothing, then SolidWorks will use the current selection set. Once you calculate, then you can just pull your properties off of the measure object. Just remember that this can be highly dependent upon your view orientation.
  • Mass properties are very similar. You create a mass properties object from the ModelDoc2.Extension object using the CreateMassProperty method. The difference here is that the Create method actually includes a CALCULATE in there. There is no Separate Calculate method.
  • And as you would expect, section properties are totally different from mass properties. Section Properties are retrieved through the GetSectionProperties2 method. You must pass that method an object to get the section properties of, but what you get back is an array with 24 items. Naturally it would be silly of SolidWorks to create a class for something that only has 24 properties. But it’s ok. I’m not bitter.
  • What I DID do, however, was to develop my own enumeration for the results. I just paste this in the class with my code and I can refer to the results with intelligent names, as shown here with this Intellisense capture.
  • Interference Detection is more like mass properties. The ToolsCheckInterference method simply opens the interference detection tool in the property manager. So that is generally not the one that you want. If you want to do things in an automated fashion, get the InterferenceDetectionManager object from your AssemblyDoc, set your properties, then use the GetInterferences method to kick off the calculation. There are actually a few other methods for the interference detection manager object that will also kick off the calculation. Watch what you’re getting back, though. When you GetInterferences, you are getting an array of interference objects. Those objects have their own properties. GetInterferenceCount just gives you back a number.
  • Interference Detection is more like mass properties. The ToolsCheckInterference method simply opens the interference detection tool in the property manager. So that is generally not the one that you want. If you want to do things in an automated fashion, get the InterferenceDetectionManager object from your AssemblyDoc, set your properties, then use the GetInterferences method to kick off the calculation. There are actually a few other methods for the interference detection manager object that will also kick off the calculation. Watch what you’re getting back, though. When you GetInterferences, you are getting an array of interference objects. Those objects have their own properties. GetInterferenceCount just gives you back a number.
  • This is one of my favorite functions in CATIA. I’m glad to see that it’s finally made its way over to SolidWorks. This could, potentially, do away with some of your need to code validation as it really does it for you. This is one of the few that I will review the functionality for, because it’s really underutilized. Sensors sit in your Feature Manager and allow you to put a watch on a value and have SolidWorks let you know when the value goes outside of the acceptable range. For parts, you can watch a dimension, like a clearance or overall length. You then give SolidWorks the REFERENCE DIMENSION to watch, and tell SolidWorks the conditions when/if to notify you. You can watch mass properties like those listed here and the simulation results listed there. Assemblies add proximity and interference detection sensors. For all of them, you specify how often to check the values. For Simulations, mass props and Interferences, that could be a significant performance issue.
  • Working with sensors in code is fairly easy, except for getting the features themselves. In earlier versions, only Dimension sensors would be picked up by the regular GetFirstFeature – GetNextFeature methodology. Other sensors just act as if they’re not there. Once you are able to get the correct object, you need to use GetSpecificFeature2, to actually get the sensor object. Once you have the sensor object, you can change the sensor type, and change the values that the sensor is watching for. You can also disable the alert and change the alert state. So your code can trip the sensor or clear the sensor as needed.
  • The other thing that’s really cool about Sensors is that there is an event notification associated with them. For those that are not familiar with events, they are triggers that you can use in your programs or macros to kick off some code when a particular event happens. The process is pretty simple. You need to define a class that declares the object WITHEVENTS. It’s important to note which SolidWorks object has the notification that you want. The sensor events are on the PartDoc and AssemblyDoc objects. Also in this class, you want to define the code to be executed when the event is triggered. You do this by defining a function with the name of your object, underscore, the name of the event. Be sure that you lookup the parameters for the event and map those to your new function with the correct data types. That’s it for the class. Then, in your main code, just instantiate that class, and pass the active object, whether it’s a partdoc, assemblydoc, or even the SolidWorks app itself. From that point on, the events will be monitored.
  • The other thing that’s really cool about Sensors is that there is an event notification associated with them. For those that are not familiar with events, they are triggers that you can use in your programs or macros to kick off some code when a particular event happens. The process is pretty simple. You need to define a class that declares the object WITHEVENTS. It’s important to note which SolidWorks object has the notification that you want. The sensor events are on the PartDoc and AssemblyDoc objects. Also in this class, you want to define the code to be executed when the event is triggered. You do this by defining a function with the name of your object, underscore, the name of the event. Be sure that you lookup the parameters for the event and map those to your new function with the correct data types. That’s it for the class. Then, in your main code, just instantiate that class, and pass the active object, whether it’s a partdoc, assemblydoc, or even the SolidWorks app itself. From that point on, the events will be monitored.
  • The other thing that’s really cool about Sensors is that there is an event notification associated with them. For those that are not familiar with events, they are triggers that you can use in your programs or macros to kick off some code when a particular event happens. The process is pretty simple. You need to define a class that declares the object WITHEVENTS. It’s important to note which SolidWorks object has the notification that you want. The sensor events are on the PartDoc and AssemblyDoc objects. Also in this class, you want to define the code to be executed when the event is triggered. You do this by defining a function with the name of your object, underscore, the name of the event. Be sure that you lookup the parameters for the event and map those to your new function with the correct data types. That’s it for the class. Then, in your main code, just instantiate that class, and pass the active object, whether it’s a partdoc, assemblydoc, or even the SolidWorks app itself. From that point on, the events will be monitored.
  • The other thing that’s really cool about Sensors is that there is an event notification associated with them. For those that are not familiar with events, they are triggers that you can use in your programs or macros to kick off some code when a particular event happens. The process is pretty simple. You need to define a class that declares the object WITHEVENTS. It’s important to note which SolidWorks object has the notification that you want. The sensor events are on the PartDoc and AssemblyDoc objects. Also in this class, you want to define the code to be executed when the event is triggered. You do this by defining a function with the name of your object, underscore, the name of the event. Be sure that you lookup the parameters for the event and map those to your new function with the correct data types. That’s it for the class. Then, in your main code, just instantiate that class, and pass the active object, whether it’s a partdoc, assemblydoc, or even the SolidWorks app itself. From that point on, the events will be monitored.
  • The other thing that’s really cool about Sensors is that there is an event notification associated with them. For those that are not familiar with events, they are triggers that you can use in your programs or macros to kick off some code when a particular event happens. The process is pretty simple. You need to define a class that declares the object WITHEVENTS. It’s important to note which SolidWorks object has the notification that you want. The sensor events are on the PartDoc and AssemblyDoc objects. Also in this class, you want to define the code to be executed when the event is triggered. You do this by defining a function with the name of your object, underscore, the name of the event. Be sure that you lookup the parameters for the event and map those to your new function with the correct data types. That’s it for the class. Then, in your main code, just instantiate that class, and pass the active object, whether it’s a partdoc, assemblydoc, or even the SolidWorks app itself. From that point on, the events will be monitored.
  • The other thing that’s really cool about Sensors is that there is an event notification associated with them. For those that are not familiar with events, they are triggers that you can use in your programs or macros to kick off some code when a particular event happens. The process is pretty simple. You need to define a class that declares the object WITHEVENTS. It’s important to note which SolidWorks object has the notification that you want. The sensor events are on the PartDoc and AssemblyDoc objects. Also in this class, you want to define the code to be executed when the event is triggered. You do this by defining a function with the name of your object, underscore, the name of the event. Be sure that you lookup the parameters for the event and map those to your new function with the correct data types. That’s it for the class. Then, in your main code, just instantiate that class, and pass the active object, whether it’s a partdoc, assemblydoc, or even the SolidWorks app itself. From that point on, the events will be monitored.
  • OK, this is what most of you came to see.
  • OK, as you can tell, my thought on the subject is that you should save simulation for when you really need it because it is quite CPU intensive and takes a lot of time. Further, before you start coding simulation through the API, take a look at whether you can automate it naturally using a Sensor or create a simulation optimization to automatically do the iterating and updating of dimensions for you. The next thing to know is that you may not find the API Help quite as helpful as you do with standard SolidWorks functionality. The API is newer and has fewer examples, and many of the simulation areas, like Flow, will have their own SDKs (that’s a Software Development Kit) that you have to install and/or download separately. You will see these as options in the Installation screen. At least until SolidWorks goes cloud, then who knows where it will be.
  • The next step is that there are separate libraries that you will need to add to gain access to the SolidWorks Simulation classes. Here’s the big one right here, SolidWorks.Interop.cosworks.dll. And when you’re adding this dll, you may need to browse for it.
  • So what are good reasons to automate simulation? Well iteration is certainly a great reason. As I said, SolidWorks does provide optimization functionality, but you may not get the collected results that you want. If you want to graph the trends of several variables as the iterations run, for example…I’m optimizing the weight on this part by changing these two dimensions. You will want to know where the weight and the values of those two variables were in each iteration, but you may also want to watch where the CG goes. Or maybe you have other criteria. Iterate, but don’t let these two get closer than… Or optimize lateral stiffness while keeping weight above 6.5 pounds
  • Or maybe you’re not automating the simulation so much as using the API to BUILD the simulation for you. What if you need to create a whole mess of pin locations or hundreds of loads. Or maybe your conditions are unknown to you and need to be calculated. You can have DriveWorks or Tacton build a model for you and your code figure out the loading and restraint conditions.
  • OK, so here is the basic object model for simulation. You’ve got your application object, your SldWorks of the simulation world. That is the CosmosWorks Add-In object. That leads to a CosmosWorksModelDoc. I’m sure it’ll be ModelDoc2 in no time. From there, you grab the study manager which begets your individual study objects. You can create these objects or you can latch onto an existing study. I would suggest the latter. Within your study, you will find objects for your loads and restraints, they actually function a lot like features in SolidWorks API examples. Then you will run that study and grab your results object.
  • So let’s take a look in a bit more detail. First is your declaration and assignment (I’m very fond of doing them in a single statement, by the way), of your CosmosWorks Add-In. The add-in should be turned on through Tools Add-Ins. Do not try to use your code to enable that. Once you have that, you fetch your ModelDoc. And there’s an ActiveDoc accessor, just like in the SldWorks object for just that purpose. One more step, and that’s the CWStudyManager object. Very similar to grabbing the SelectionManager or FeatureManager object from a ModelDoc. Just an accessor called StudyManager. And of course, you folks are all ACE programmers so you’re going to test for object IS NOTHING after each statement right? Yeha, I thought so. Even if you’re not, just nod and make me feel better.
  • Here we ramp it up a bit. We need to grab or create a study. I do not recommend creating studies. That is everyone’s first impulse. But one thing that you learn doing design implementations is that the more you can preset, the better. So I would recommend finding an existing study. The best way to do that is to grab the studycount. Then you can test that study count to make sure that it is what you expect it to be. Test early, test often. From there, you can cycle through the studies if you want to or you can grab a study by index. There is no explicit, get study by name accessor. So grab them by index and check the name.
  • Adding the material to the STUDY object (note where it is, it’s on the STUDY object) is also a critical step and it’s a bit of a traversal. You need to grab the SolidManger object from the Study, then the SolidComponent from that, then the SolidBody from that. Setting the material here is very similar to setting the material for a SolidWorks model. You need to specify the full path to the material library.
  • So if you’re looking for the actual valuable objects that you’re going to need, those will be down one more level. All of the options for your study will be in a separate StudyOptions object. Different objects for different types of analysis. Again, in the SolidWorks API Help, you will not see all of your study types. The help files and the sample files are all in those SDKs. If you didn’t fork up the dough for the modules, they don’t want you to have the help files. Notice here that most of the methods are properties. There are very few methods, with the exception of the bigunCreateMesh and the grandpappy, RunAnalysis. And speaking of mesh, you will find yet another option for your mesh.Another tip, use that intellisense for all of your enumerations, and there are tons. So type in CosmosWorksLib dot and you will get the full list of enumerations to choose from.
  • So in the mesh, you do have options to control ElementSize and tolerance. One method here that is critical to note is the Study object’s UpdateAllComponents method. Simulation and SolidWorks do have a small disconnect in them. If you want your SolidWorks model updates to be pushed to the analysis, then you’re going to need to kick off that method. ALWAYS DO IT BEFORE YOU CREATE YOUR MESH AND RUN THE ANALYSIS.
  • So once you have run your analysis, it’s time to get the results. Getting results is a bit more challenging. Think about the results. We have reams of green bar paper worth of values to choose from and in SolidWorks, what do we do? We look at pictures. Automation can’t really do that all too well. So here’s how we go about getting our numeric results. The first step is to grab your results object. It is a generic results object for standard simulations. Flow and motion are different.
  • Unfortunately, the results will typically come back as an array. A very poorly documented array. It is important that you check the values in this array very carefully before you use them.
  • So the big question on everyone’s mind is, how do you get SolidWorks to save out the BMPs and JPEGs and AVIs for the deflection and stress results? Well, the bad news is that there really is no way to do that. You can activate them and get a list of them, and even delete them. But saving them or publishing a report cannot be done from the API at this point.
  • So where else in the API should we be looking to get other validation code ideas?
  • Most of the add-ins for SolidWorks that are included in the Office suite have at least some level of API. The tools in SolidWorks Utilities that compare geometry and features are accessible. Analysis tools to look for invalid geometry and thickness inconsistencies, and even the molding parting line draft analysis are available via the API. The Xpress tools, however, do not have API functionality. These tools are all pretty interactive in their nature, using Microsoft wizard interfaces. So not having API access to these is not all that surprising.
  • Quite often, we see people that have outside validation tools. Perhaps an old piece of Fortran or BASIC code that was written so many years ago that nobody knows how or why it works, but it has become an integral part of the design process. These tools can be integrated into SolidWorks code through an external call, by declaring the external function, or by writing a .NET wrapper for that old code. The approach depends heavily upon the type of application and how it interacts with the system. There are also a lot of web-based calculation and lookup tools on the web that allow you to send code, typically as parameters in the URL or JAVA, and let the site do industry-specific calculations, conversions, or other such generics.
  • Automated Design Validation The Solid Works Api

    1. 1. Automated Design Validation with the SolidWorks API<br />Paul Gimbel, Business Process Sherpa<br />Razorleaf Corporation<br />
    2. 2. What You Will Hear In This Session<br />Automating SolidWorks Simulation programmatically<br />BUT THAT’S NOT IT<br />Tools within SolidWorks to do design validations<br />This an ADVANCED session<br />Assumes that you know SolidWorks user interface<br />Assumes that you know the basics of SolidWorks API programming<br />ALL CODE EXAMPLES IN VB.NET<br />Presentation will be available at www.razorleaf.com<br />
    3. 3. 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 />
    4. 4. What is Design Validation?<br />Ensuring that the suggested design meets requirements<br />Form/Fit/Function<br />Durability<br />Weight<br />Performance<br />Manufacturability<br />Maintenanceability<br />Packaging/Shipping Limitations<br />And so on…<br />It’s more than just fea!!<br />
    5. 5. What Forms Can Validation Take?<br />Equations<br />The most accurate method to determine values<br />Can be difficult to apply to complex geometries<br />Code Calculations<br />Many have to meet and publish them…it’s the law<br />Simulation<br />Iterative<br />Prototype<br />Digital<br />Somewhat time consuming<br />Physical <br />Expensive and time consuming<br />Lesson from Programming: <br />Rule out the easy stuff before you start sucking up CPU.<br />
    6. 6. How Does This Work With Design Automation?<br />Frequent Goal of Design Automation <br />Allow NON-SolidWorks USERS to design/configure valid products<br />Therefore:<br />Cannot use any interactive tools<br />Methods must not require SolidWorks on their machine<br />May use a 3rd party solution<br />
    7. 7. What Validation Tools and/or Techniques are there?Why Does Every Slide Have a Question in the Title?<br />Within SolidWorks<br /><ul><li>Sensors
    8. 8. Design Checker
    9. 9. Measure
    10. 10. Mass/Section Properties
    11. 11. Interference Detection
    12. 12. SimulationXPress
    13. 13. Any other XPress
    14. 14. Reference Dimensions!!</li></ul>With SolidWorks Simulation<br /><ul><li>Stress Analysis
    15. 15. Flow Analysis
    16. 16. Motion Simulation
    17. 17. Optimization</li></ul>Outside tools (commercially available and homegrown)<br />
    18. 18. Functionality Within SolidWorks<br />Gimme Free Stuff (well, what I already pay for)<br />
    19. 19. What Do I Get With My SolidWorks?<br /><ul><li>Reference Dimensions
    20. 20. Measure
    21. 21. Mass/Section Properties
    22. 22. Interference Detection
    23. 23. Sensors
    24. 24. Design Checker
    25. 25. SimulationXPress
    26. 26. Any other XPress</li></li></ul><li>What Do I Get With My SolidWorks?<br /><ul><li>Reference Dimensions
    27. 27. Measure
    28. 28. Mass/Section Properties
    29. 29. Interference Detection
    30. 30. Sensors
    31. 31. Design Checker
    32. 32. SimulationXPress
    33. 33. Any other XPress</li></li></ul><li>What Do I Get With My SolidWorks?<br /><ul><li>Reference Dimensions
    34. 34. Measure
    35. 35. Mass/Section Properties
    36. 36. Interference Detection
    37. 37. Sensors
    38. 38. Design Checker
    39. 39. SimulationXPress
    40. 40. Any other XPress</li></li></ul><li>Reference Dimensions (2D and 3D)<br />Watch the name of the reference dimension<br />Find it in the Property Mangler<br />Retrieve the DIMENSION object.GetValue2(“ConfigName”)<br />Imports SolidWorks.Interop.sldworks<br />Imports SolidWorks.Interop.swconst<br />PartialClassSolidWorksMacro<br />PublicswAppAsSldWorks<br />PublicSub main()<br />DimswDocAs ModelDoc2 = Nothing<br />swDoc = CType(swApp.ActiveDoc, ModelDoc2)<br />MsgBox(swDoc.Parameter(&quot;TXD1@Scheme2&quot;).GetValue2(&quot;Default&quot;))<br />MsgBox(swDoc.Parameter(“Gap@skSlot&quot;).GetValue2(&quot;Default&quot;))<br />EndSub<br />EndClass<br />No longer a property<br />Note: Code in yellow omitted from future slides.<br />
    41. 41. Measure Tool<br />Separate Measure object - swDoc.Extension.CreateMeasure<br />Must use Measure.CALCULATE(object)<br />If Object Is Nothing, SolidWorks will use the current selection set<br />Alternatively, you can use the Selection Manager object<br />Set options before you call the calculate method<br />Returns are fairly specific<br />DimswMeasAs Measure = Ctype(swDoc.Extension.CreateMeasure, Measure)<br />swMeas.ArcOption = _<br />swMeasureArcCircleOption_e.swMeasureArcCircle_MinimumDistance<br />swMeas.Calculate(Nothing)<br />MsgBox(swMeas.Distance)<br />Don’t forget to test all objects and results!<br />Check out the options here<br />
    42. 42. Mass Properties<br />Obtain MassProperty object<br />ModelDoc2.Extension.CreateMassProperty()<br />DimswMassPropAsMassProperty = _<br />CType(swDoc.Extension.CreateMassProperty(), MassProperty)<br />MsgBox(swMassProp.Mass)<br />boolstatus = swMassProp.SetAssignedMassProp(1.5, 0, 0, 0, 1, Nothing)<br />
    43. 43. Section Properties<br />Requires an Array of FACE or SKETCH object as input<br />ModelDoc2.Extension.GetSectionProperties2(objSections) <br />Returns a 24 item array<br />Need to look up which index corresponds to what you’re interested in<br />Use API Help topic IGetSectionProperties2<br />Clumsy throwback to VBA<br />DimswSelMgrAsSelectionMgr = swDoc.SelectionManager<br />DimswFaceAs Face = swSelMgr.GetSelectedObject6(0, 0)<br />DimswSectionProps(23) AsDouble<br />swSectionProps = swDoc.Extension.GetSectionProperties2(swFace)<br />MsgBox(&quot;Area (index 1) = &quot; & swSectionProps(1))<br />Don’t forget to test all objects and results!<br />
    44. 44. How’s THIS For Helpful?<br />
    45. 45. Dealing with Result Arrays Using Enumerations<br />PublicEnumSectionResults<br /> Area = 1<br />CentroidX = 2<br />CentroidY = 3<br />CentroidZ = 4<br />momentXX = 5<br />momentYY = 6<br />momentZZ = 7<br />momentXY = 8<br />momentZX = 9<br />momentYZ = 10<br />polarMoment = 11<br />principalAngle = 12<br />principalIx = 13<br />principalIy = 14<br />EndEnum&apos;SectionResults<br />Paste me!<br />PublicEnumSectionResults<br /> Area = 1<br />CentroidX = 2<br />CentroidY = 3<br />CentroidZ = 4<br />momentXX = 5<br />momentYY = 6<br />momentZZ = 7<br />momentXY = 8<br />momentZX = 9<br />momentYZ = 10<br />polarMoment = 11<br />principalAngle = 12<br />principalIx = 13<br />principalIy = 14<br />DirectionXx = 15<br />DirectionXy = 16<br />DirectionXz = 17<br />DirectionYx = 18<br />DirectionYy = 19<br />DirectionYz = 20<br />DirectionZx = 21<br />DirectionZy = 22<br />DirectionZz = 23<br />EndEnum&apos;SectionResults<br />
    46. 46. Interference/Collision Detection<br />swAssembly.ToolsCheckInterference() just opens the UI<br />Use the InterferenceDetectionMgr object to create an Interference Object<br />Establish object<br />swIntMgr = Ctype(AssemblyDoc.InterferenceDetectionManager, _ InterferenceDetectionMgr)<br />Set properties<br />swIntMgr.TreatCoincidenceAsInterference = True<br />Run Interference Check (any method except Done)<br />DimswInts() As Object = swIntMgr.GetInterferences<br />DimswIntAs Interference = Ctype(swInts(0), Interference)<br />Grab results<br />DimdVolumesAs Double = swInt.Volume<br />
    47. 47. Interference/Collision Detection<br />swAssembly.ToolsCheckInterference() just opens the UI<br />Use the InterferenceDetectionMgr object to create an Interference Object<br />Establish object<br />Ctype(AssemblyDoc.InterferenceDetectionManager, _ InterferenceDetectionMgr)<br />Set properties<br />swIntMgr.TreatCoincidenceAsInterference = True<br />Run Interference Check (any method except Done)<br />DimswInts() As Object = swIntMgr.GetInterferences<br />DimswIntAs Interference = Ctype(swInts(0), Interference)<br />Grab results<br />DimdVolumesAs Double = swInt.Volume<br />
    48. 48. Interference/Collision Detection<br />swAssembly.ToolsCheckInterference() just opens the UI<br />Use the InterferenceDetectionMgr object to create an Interference Object<br />Establish object<br />Ctype(AssemblyDoc.InterferenceDetectionManager, _ InterferenceDetectionMgr)<br />Set properties<br />swIntMgr.TreatCoincidenceAsInterference = True<br />Run Interference Check (any method except Done)<br />DimswInts() As Object = swIntMgr.GetInterferences<br />DimswIntAs Interference = Ctype(swInts(0), Interference)<br />Grab results<br />DimdVolumesAs Double = swInt.Volume<br />
    49. 49. Interference/Collision Detection – More Complete Code<br />DimswAssemblyAsAssemblyDoc = CType(swDoc, AssemblyDoc)<br />swDoc.Parameter(&quot;CrankAngle@RotationMate@Crank-Slider.SLDASM&quot;).Value = 150<br />DimboolstatusAsBoolean = swDoc.EditRebuild3()<br />DimswIMAsInterferenceDetectionMgr = swAssembly.InterferenceDetectionManager<br />DimiIntQtyAsInteger = swIM.GetInterferenceCount<br />IfiIntQty &gt;= 0 Then<br />DimswInts(iIntQty - 1) AsObject<br />swInts = swIM.GetInterferences<br />DimswIntAs Interference = CType(swInts(0), Interference)<br />MsgBox(swInt.Volume)<br />EndIf<br />Don’t forget to test all objects and results!<br />
    50. 50. Sensors<br />(PART)<br /><ul><li>Sensor types
    51. 51. Notice for interactive users
    52. 52. Potential performance issues
    53. 53. Suppress extraneous sensors
    54. 54. Set notification frequency</li></ul>(ASSY)<br />
    55. 55. Working with Sensors in Code<br />Get the sensor object from the Sensor Feature (use MD2.GetFirstFeature)<br />DimswSensorAsSensor = swFeature.GetSpecificFeature2<br />Critical sensor properties and methods<br />SelectCaseswSensor.SensorType<br />CaseswSensorType_e.swSensorSimulation<br />CaseswSensorType_e.swSensorMassProperty<br />CaseswSensorType_e.swSensorDimension<br />CaseswSensorType_e.swSensorInterfaceDetection<br />EndSelect<br />Be sure to Update the sensor with the UpdateSensor method<br />Check the AlertState to see if the sensor has picked up on a problem<br />Use the AlertType to see what kind of a problem<br />SW2009 SP2 and before only supported Dimension Sensors<br />
    56. 56. Using SolidWorks Events<br />Create a class <br />Declare a variable WITHEVENTS for the object that holds your events<br />PublicWithEventsswPartAsSolidWorks.interop.sldworks.PartDoc<br />Create a Function for whatever event you want to monitor<br />FunctionswPart_SensorAlertPreNotify(ByValswSensorAsObject, ByVal _<br />SensorAlertTypeAsInteger)AsInteger<br />Shell(&quot;http://www.twitter.com/?&apos;#SW Sensor!&apos;&quot;, AppWinStyle.Hide, False)<br />EndFunction &apos;swPart_SensorAlertPreNotify<br />In your main code – Activate the handler (RemoveHandler to discontinue)<br />AddHandlerswPart.SensorAlertPreNotify, AddressOf _<br />Me.swPart_SensorAlertPreNotify<br />Note who your event belongs to<br />Check out all available events in API Help<br />
    57. 57. Using SolidWorks Events<br />Create a class <br />Declare a variable WITHEVENTS for the object that holds your events<br />PublicWithEventsswPartAsSolidWorks.interop.sldworks.PartDoc<br />Create a Function for whatever event you want to monitor<br />FunctionswPart_SensorAlertPreNotify(ByValswSensorAsObject, ByVal _<br />SensorAlertTypeAsInteger) AsInteger<br /> Shell(&quot;http://www.twitter.com/?&apos;#SW Sensor!&apos;&quot;, AppWinStyle.Hide, False)<br />EndFunction &apos;swPart_SensorAlertPreNotify<br />In your main code – Activate the handler (RemoveHandler to discontinue)<br />AddHandlerswPart.SensorAlertPreNotify, AddressOf _<br />Me.swPart_SensorAlertPreNotify<br />(Don’t think you can ignore me)<br />Note who your event belongs to<br />Check out all available events in API Help<br />
    58. 58. Using SolidWorks Events<br />Create a class <br />Declare a variable WITHEVENTS for the object that holds your events<br />PublicWithEventsswPartAsSolidWorks.interop.sldworks.PartDoc<br />Create a Function for whatever event you want to monitor<br />FunctionswPart_SensorAlertPreNotify(ByValswSensorAsObject, ByVal _<br />SensorAlertTypeAsInteger) AsInteger<br /> Shell(&quot;http://www.twitter.com/?&apos;#SW Sensor!&apos;&quot;, AppWinStyle.Hide, False)<br />EndFunction &apos;swPart_SensorAlertPreNotify<br />In your main code – Activate the handler (RemoveHandler to discontinue)<br />AddHandlerswPart.SensorAlertPreNotify, AddressOf _<br />Me.swPart_SensorAlertPreNotify<br />(I’m not going away)<br />Note who your event belongs to<br />Check out all available events in API Help<br />
    59. 59. Using SolidWorks Events<br />Create a class <br />Declare a variable WITHEVENTS for the object that holds your events<br />PublicWithEventsswPartAsSolidWorks.interop.sldworks.PartDoc<br />Create a Function for whatever event you want to monitor<br />FunctionswPart_SensorAlertPreNotify(ByValswSensorAsObject, ByVal _<br />SensorAlertTypeAsInteger) AsInteger<br /> Shell(&quot;http://www.twitter.com/?&apos;#SW Sensor!&apos;&quot;, AppWinStyle.Hide, False)<br />EndFunction &apos;swPart_SensorAlertPreNotify<br />In your main code – Activate the handler (RemoveHandler to discontinue)<br />AddHandlerswPart.SensorAlertPreNotify, AddressOf _<br />Me.swPart_SensorAlertPreNotify<br />(I’m not going away)<br />Note who your event belongs to<br />Check out all available events in API Help<br />
    60. 60. Using SolidWorks Events<br />Create a class <br />Declare a variable WITHEVENTS for the object that holds your events<br />PublicWithEventsswPartAsSolidWorks.interop.sldworks.PartDoc<br />Create a Function for whatever event you want to monitor<br />FunctionswPart_SensorAlertPreNotify(ByValswSensorAsObject, ByVal _<br />SensorAlertTypeAsInteger) AsInteger<br /> Shell(&quot;http://www.twitter.com/?&apos;#SW Sensor!&apos;&quot;, AppWinStyle.Hide, False)<br />EndFunction &apos;swPart_SensorAlertPreNotify<br />In your main code – Activate the handler (RemoveHandler to discontinue)<br />AddHandlerswPart.SensorAlertPreNotify, AddressOf _<br />Me.swPart_SensorAlertPreNotify<br />(Keep it up. Your iPhone is next.)<br />Note who your event belongs to<br />Check out all available events in API Help<br />
    61. 61. Using SolidWorks Events<br />Create a class <br />Declare a variable WITHEVENTS for the object that holds your events<br />PublicWithEventsswPartAsSolidWorks.interop.sldworks.PartDoc<br />Create a Function for whatever event you want to monitor<br />FunctionswPart_SensorAlertPreNotify(ByValswSensorAsObject, ByVal _<br />SensorAlertTypeAsInteger) AsInteger<br /> Shell(&quot;http://www.twitter.com/?&apos;#SW Sensor!&apos;&quot;, AppWinStyle.Hide, False)<br />EndFunction &apos;swPart_SensorAlertPreNotify<br />In your main code – Activate the handler (RemoveHandler to discontinue)<br />AddHandlerswPart.SensorAlertPreNotify, AddressOf _<br />Me.swPart_SensorAlertPreNotify<br /> Fine! I’ll do it myself.<br />Rebooting in:<br />Note who your event belongs to<br />Check out all available events in API Help<br />
    62. 62. Applying Update 1 of 9,278,029….0% Complete<br />Do Not Turn Off Computer<br />
    63. 63. Applying Update 1 of 9,278,029….0.001% Complete<br />Don’t Even Think About It.<br />I’ll restart when I’m good and ready.<br />
    64. 64. Autonomous Edition<br />
    65. 65.
    66. 66. SolidWorks Simulation<br />At long last…<br />
    67. 67. Automating SolidWorks Simulation<br />Evaluate what you are trying to automate<br />Can it be done with sensors?<br />Can it be done with Optimization?<br />Not all of SolidWorks Simulation is documented in API Help<br />Extra SDKs or Installation options may be required (ex. Flow)<br />
    68. 68. Gimme an S, Gimme an R, Gimme an A, Gimme a C!<br />Must add SolidWorks 2010 Simulation Type Library as a reference to each project<br />You can also add SolidWorks.Interop.cosworks.dll<br />You will need to BROWSE for it …SolidWorksAPI edist<br />(cosworks? There’s your proof that all the product renames are marketing)<br />
    69. 69. Possible Applications<br />Record iterative results<br />Run iterations and send results out to Excel or other system<br />Allow code or outside tool control when to iterate and how<br />
    70. 70. Possible Applications<br />Attach / create / modify study components (loads, connections, etc.)<br />Create 400 pin locations in a regular (or slightly irregular) array<br />Create an unknown number of loads based on driven geometry<br />Allow 3rd party solutions to kick off simulation as part of automation<br />More complex iterative optimizations using your own optimization algorithm<br />Change what YOU want to change, how YOU want to change it<br />
    71. 71. Cosmos? Yes, Cosmos.<br />© COSMOS/and COSMOS/WORKS and their respective logos property of Structural Research Analysis Corporation 1997<br />Run Analysis<br />
    72. 72. RMB in the Project Explorer to add a Reference<br />You will not find it in the .NET tab<br />You MAY find it under COM<br />You will most likely need to browse for it<br />Adding The Reference<br />
    73. 73. The Process<br />Fetch the SolidWorks Simulation (CosmosWorks) Add-In object<br />DimcwAddInAsSolidWorks.interop.cosworks.CWAddInCallBack = _<br />swApp.GetAddInObject(&quot;CosmosWorks.CosmosWorks&quot;)<br />Fetch the cwModelDoc<br />DimCWorksAsObject = cwAddIn.CosmosWorks<br />DimcwDocAsCWModelDoc = Ctype(CWorks.ActiveDoc(), CWModelDoc)<br />Fetch the CWStudyManager object<br />DimcwStudyMgrAsCWStudyManager = cwDoc.StudyManager()<br />Imports SolidWorks.interop.cosworksis implied<br />
    74. 74. More of The Process<br />Fetch the CWStudy object<br />Test for study existence with StudyCount<br />DimcwStudyCountAsInteger = cwStudyMgr.StudyCount<br />DimcwCurStudyAsCWStudy<br />Dim iErrors As Integer<br />IFcwStudyCount &gt; 0 Then<br />cwCurStudy = CWStudyManager.GetStudy(0)<br />Else<br />cwCurStudy = CWStudyManager.CreateNewStudy2 _<br /> (“StudyName”, type, iErrors)<br />EndIf<br />TIP: Don’t create studies when you can preset and drive them<br />Imports SolidWorks.interop.cosworksis implied<br />
    75. 75. Add Material<br />Need to apply the material to the Solid Body Object<br />Study gets the SolidManager<br />SolidManager gets the SolidComponent<br />SolidComponent gets the SolidBody<br />Circle gets the square<br />DimcwSolidMgrAsCosmosWorksLib.CWSolidManager<br />cwSolidMgr = cwCurStudy.SolidManager<br />DimCompCountAsInteger = cwSolidMgr.ComponentCount<br />DimcwCompAsCWSolidComponent = cwSolidMgr.GetComponentAt(0, cwStudyErrors)<br />DimcwBodyAsCWSolidBody = cwComp.GetSolidBodyAt(0, cwStudyErrors)<br />cwStudyErrors = cwBody.SetLibraryMaterial(&quot;M:MyMatlLibRLMatl.sldmatlib&quot;, &quot;Unobtainium&quot;)<br />
    76. 76. Even More of The Process<br />All ReadOnly!!<br />Get the next Manager or Options object<br />All properties and options reside one level down<br />DimcwStaticOptionsAsCWStaticStudyOptions<br />cwStaticOptions = cwCurStudy.StaticStudyOptions<br />cwStaticOptions.SolverType = _<br />CosmosWorksLib.swsSolverType_e.swsSolverTypeFFEPlus<br />DimcwCurMeshAsCWMesh = cwCurStudy.Mesh<br />cwCurMesh.Quality = _<br />CosmosWorksLib.swsMeshQuality_e.swsMeshQualityHigh<br />Imports SolidWorks.interop.cosworksis implied<br />
    77. 77. Even Still More of The Process<br />Update components, mesh and run the analysis<br />Update is for any geometry changes since last run<br /> &apos;We&apos;ll typically calculate or get these as inputs<br />DimdElementSizeAsDouble = 0.0012<br />DimdToleranceAsDouble = 0.005<br />cwCurStudy.UpdateAllComponents()<br />cwCurStudy.CreateMesh(CosmosWorksLib.swsUnit_e.swsUnitEnglish, _<br />dElementSize, dTolerance)<br />cwCurStudy.RunAnalysis()<br />Imports SolidWorks.interop.cosworksis implied<br />
    78. 78. Mandatory Charts (Gratuitous Chart of Fictitious Data)(per Microsoft PowerPoint code 2009 Section XXIV Subsection 441.K.9.ii.v)<br />Activities Past Midnight<br />Reaction to Subtle Jokes In Slides by Demographic<br />
    79. 79. Even Yet Still More of The Process<br />Retrieve the Results object<br />Most Results methods return arrays<br />These are typically brought in with generic options<br />DimcwCurResultsAsCWResults<br />cwCurResults = cwCurStudy.Results<br />Dim cwResultsErrors As Integer<br />Dim cwStress As Object<br />cwStress = cwCurResults.GetMinMaxStress _<br /> (0, 0, 1, Nothing, 0, cwResultsErrors)<br />Imports SolidWorks.interop.cosworksis implied<br />
    80. 80. Dealing with Arrays<br />Return types are VERY vague<br />Always the possibility of a null return<br />Most samples stay generic<br />VBA dim as VARIANT<br />VB.NET/C#.NET dim as OBJECT<br />Run once or twice or check sample to find out return type<br />Fetch as generic object then recast the variable to get the array<br />ERROR TRAP THE SNOT OUT OF IT!!!<br />Make separate functions wherever possible to use Try…Catch blocks<br />Allows you to handle the errors differently<br />
    81. 81. Array Sample<br />TRY<br />‘Define as generic object<br />DimcwStressAsObject<br />‘Retrieve the object<br />cwStress = cwCurResults.GetMinMaxStress(0, 0, 1, Nothing, 0, cwResultErrors)<br />IfcwStressIsNotNothing<br />‘Declare your array<br />DimcwStressArray() AsDouble<br />‘Recast your generic object as an array<br />cwStressArray = CType(cwStress, Double())<br />IfcwStressArray.Length &gt; 0 Then<br />ForEachdStressAsDoubleIncwStressArray<br />NextdStress<br />EndIf‘Array.Length &gt; 0<br />EndIf‘we have a stress results object<br />
    82. 82. Array Sample<br />Catch<br />‘Handle the fact that we did not get usable stress results<br />End Catch<br />Try<br />‘Define as generic object<br />DimcwDisplacementAsObject<br />‘Retrieve the object<br />cwDisplacement = cwCurResults.GetMinMaxDisplacement(0, 0, Nothing, _<br />CosmosWorksLib.swsUnit_e.swsUnitEnglish, cwStudyErrors)<br />IfcwDisplacementIsNotNothing<br />‘Declare your array<br />DimcwDispArray() AsDouble<br />‘Recast your generic object as an array<br />cwStressArray = CType(cwStress, Double())<br />And so on…<br />
    83. 83. Getting Back Visual Results<br />“A picture is worth a thousand lines of code” <br />– Michaelangelo (…I think)<br />The absolute most beneficial feature of automating simulations!!!<br />API has the ability to activate plots, delete plots, and tell you how many there are and their names<br />There appears to be no way to Save plots or animations out to files.<br />End of slide<br />
    84. 84. Other Places to Explore<br />And finally…<br />
    85. 85. Other Validation Tools<br />Available via API <br />SolidWorks Utilities<br />Compare Document<br />Compare Feature<br />Compare Geometry<br />Geometry Analysis<br />Thickness Analysis<br />Design Checker<br />Check (Face, Edge, Body)<br />Parting Line Draft Analysis<br />NOT Available via API <br /><ul><li>SimulationXpress
    86. 86. FloXpress
    87. 87. DFMXpress
    88. 88. SustainabilityXpress
    89. 89. Deviation Analysis
    90. 90. TolAnalyst</li></li></ul><li>Outside Validation Tools<br />Calculations are too involved or not understood to recreate<br />External DLL code<br />May be VB, FORTAN, PASCAL, GW-BASIC, Assembly Code, Pig Latin<br />public declare function InitializeLibrary lib &quot;extn.dll&quot; alias &quot;_InitializeLibrary@12&quot; (byvalhWnd as long, byvalstrasstring, byvaldwordas long) as longShell<br />External EXE code<br />Shell(“PVCalc.EXE “ & dPressure & “,” & dWallThk, AppWinStyle.MinimizedNoFocus)<br />Web-based ASP tools<br />Less overhead to load/install<br />Most applications allow parameters to be passed in the header<br />
    91. 91. Questions? Comments? Suggestions? Soup Recipes?<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 and more…<br />Catch me in my upcoming tour dates!!<br />Wednesday @ 1:30 – Automating Your Designs with Excel and the SW API<br />Friday @ Miffy’s Muffin Palace – Drury Lane<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 />
    92. 92. Paul Gimbel, Razorleaf Corporation<br />paul.gimbel@razorleaf.com<br />@TheProcesSherpa on Twitter<br /><ul><li>PLEASE PLEASEPLEASE fill out your survey
    93. 93. It takes practically no time at all
    94. 94. I HONESTLY want your feedback and I do apply it
    95. 95. 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, add:<br />“OK, I’m stumped. <br />How did he pull my card out of THERE?”<br />SURVEY TIME!!!<br />

    ×