Upload
razorleaf-corporation
View
5.568
Download
4
Tags:
Embed Size (px)
DESCRIPTION
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.
Citation preview
Automated Design Validation with the SolidWorks APIPaul Gimbel, Business Process Sherpa
Razorleaf Corporation
What You Will Hear In This Session
• Automating SolidWorks Simulation programmatically
• BUT THAT’S NOT IT
• Tools within SolidWorks to do design validations
• This an ADVANCED session
Assumes that you know SolidWorks user interface
Assumes that you know the basics of SolidWorks API programming
• ALL CODE EXAMPLES IN VB.NET
Presentation will be available at www.razorleaf.com
Who Is This Guy and Where Did He Come From?
• Razorleaf Corporation SolidWorks Service Partner
Services ONLY (we’re not trying to sell you anything, we’re neutral)
Data Management (EPDM, SmarTeam, Aras)
Design Automation (DriveWorks, Tacton)
Workflow Automation (Microsoft SharePoint and Tools)
• Paul Gimbel (aka “The Sherpa”) 10+ years as Demo Jock, Applications Engineer, Trainer, Support Tech
5 years as Design Automation Implementer
Specializing in SolidWorks, DriveWorks, Tacton, Custom Programming
• (THERE! Now I can report this trip as reimbursable.)
The Sherpa
What is Design Validation?
Ensuring that the suggested design meets requirements
• Form/Fit/Function
• Durability
• Weight
• Performance
• Manufacturability
• Maintenanceability
• Packaging/Shipping Limitations
• And so on…
IT’S MORE THAN JUST
FEA!!
What Forms Can Validation Take?
• Equations
The most accurate method to determine values
Can be difficult to apply to complex geometries
• Code Calculations
Many have to meet and publish them…it’s the law
• Simulation
Iterative
• Prototype
Digital
−Somewhat time consuming
Physical
−Expensive and time consuming
Lesson from Programming:
Rule out the easy stuff before you start sucking up CPU.
How Does This Work With Design Automation?
Frequent Goal of Design Automation Allow NON-SolidWorks USERS to design/configure valid products
Therefore:
• Cannot use any interactive tools
• Methods must not require SolidWorks on their machine
• May use a 3rd party solution
What Validation Tools and/or Techniques are there?Why Does Every Slide Have a Question in the Title?
Within SolidWorks Sensors
Design Checker
Measure
Mass/Section Properties
Interference Detection
SimulationXPress
Any other XPress
Reference Dimensions!!
With SolidWorks Simulation Stress Analysis
Flow Analysis
Motion Simulation
Optimization
Outside tools (commercially available and homegrown)
FUNCTIONALITY WITHIN SOLIDWORKS
Gimme Free Stuff (well, what I already pay for)
What Do I Get With My SolidWorks?
Reference Dimensions
Measure
Mass/Section Properties
Interference Detection
Sensors
Design Checker
SimulationXPress
Any other XPress
What Do I Get With My SolidWorks?
Reference Dimensions
Measure
Mass/Section Properties
Interference Detection
Sensors
Design Checker
SimulationXPress
Any other XPress
What Do I Get With My SolidWorks?
Reference Dimensions
Measure
Mass/Section Properties
Interference Detection
Sensors
Design Checker
SimulationXPress
Any other XPress
Reference Dimensions (2D and 3D)
• Watch the name of the reference dimension
Find it in the Property Mangler
• Retrieve the DIMENSION object.GetValue2(“ConfigName”)
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Partial Class SolidWorksMacro
Public swApp As SldWorks
Public Sub main()
Dim swDoc As ModelDoc2 = Nothing
swDoc = CType(swApp.ActiveDoc, ModelDoc2)
MsgBox(swDoc.Parameter("TXD1@Scheme2").GetValue2("Default"))
MsgBox(swDoc.Parameter(“Gap@skSlot").GetValue2("Default"))
End Sub
End ClassNote: Code in yellow omitted from future slides.
No longer a property
Measure Tool
• Separate Measure object - swDoc.Extension.CreateMeasure
• Must use Measure.CALCULATE(object)
If Object Is Nothing, SolidWorks will use the current selection set
Alternatively, you can use the Selection Manager object
Set options before you call the calculate method
• Returns are fairly specific
Dim swMeas As Measure = Ctype(swDoc.Extension.CreateMeasure, Measure)
swMeas.ArcOption = _
swMeasureArcCircleOption_e.swMeasureArcCircle_MinimumDistance
swMeas.Calculate(Nothing)
MsgBox(swMeas.Distance)
Check out the options hereDon’t forget to test all objects and results!
Mass Properties
• Obtain MassProperty object
ModelDoc2.Extension.CreateMassProperty()
Dim swMassProp As MassProperty = _
CType(swDoc.Extension.CreateMassProperty(), MassProperty)
MsgBox(swMassProp.Mass)
boolstatus = swMassProp.SetAssignedMassProp(1.5, 0, 0, 0, 1, Nothing)
Section Properties
• Requires an Array of FACE or SKETCH object as input
ModelDoc2.Extension.GetSectionProperties2(objSections)
• Returns a 24 item array
Need to look up which index corresponds to what you’re interested in
−Use API Help topic IGetSectionProperties2
Clumsy throwback to VBA
Dim swSelMgr As SelectionMgr = swDoc.SelectionManager
Dim swFace As Face = swSelMgr.GetSelectedObject6(0, 0)
Dim swSectionProps(23) As Double
swSectionProps = swDoc.Extension.GetSectionProperties2(swFace)
MsgBox("Area (index 1) = " & swSectionProps(1))
Don’t forget to test all objects and results!
How’s THIS For Helpful?
Dealing with Result Arrays Using Enumerations
Public Enum SectionResults
Area = 1 CentroidX = 2 CentroidY = 3 CentroidZ = 4 momentXX = 5 momentYY = 6 momentZZ = 7 momentXY = 8 momentZX = 9 momentYZ = 10 polarMoment = 11 principalAngle = 12
principalIx = 13 principalIy = 14End Enum 'SectionResults
Public Enum SectionResults Area = 1 CentroidX = 2 CentroidY = 3 CentroidZ = 4 momentXX = 5 momentYY = 6 momentZZ = 7 momentXY = 8 momentZX = 9 momentYZ = 10 polarMoment = 11 principalAngle = 12 principalIx = 13 principalIy = 14 DirectionXx = 15 DirectionXy = 16 DirectionXz = 17 DirectionYx = 18 DirectionYy = 19 DirectionYz = 20 DirectionZx = 21 DirectionZy = 22 DirectionZz = 23End Enum 'SectionResults
Paste me!
Interference/Collision Detection
• swAssembly.ToolsCheckInterference() just opens the UI
• Use the InterferenceDetectionMgr object to create an Interference Object
• Establish object
swIntMgr = Ctype(AssemblyDoc.InterferenceDetectionManager, _ InterferenceDetectionMgr)
• Set properties
swIntMgr.TreatCoincidenceAsInterference = True
• Run Interference Check (any method except Done)
Dim swInts() As Object = swIntMgr.GetInterferences
Dim swInt As Interference = Ctype(swInts(0), Interference)
• Grab results
Dim dVolumes As Double = swInt.Volume
Interference/Collision Detection
• swAssembly.ToolsCheckInterference() just opens the UI
• Use the InterferenceDetectionMgr object to create an Interference Object
• Establish object
Ctype(AssemblyDoc.InterferenceDetectionManager, _ InterferenceDetectionMgr)
• Set properties
swIntMgr.TreatCoincidenceAsInterference = True
• Run Interference Check (any method except Done)
Dim swInts() As Object = swIntMgr.GetInterferences
Dim swInt As Interference = Ctype(swInts(0), Interference)
• Grab results
Dim dVolumes As Double = swInt.Volume
Interference/Collision Detection
• swAssembly.ToolsCheckInterference() just opens the UI
• Use the InterferenceDetectionMgr object to create an Interference Object
• Establish object
Ctype(AssemblyDoc.InterferenceDetectionManager, _ InterferenceDetectionMgr)
• Set properties
swIntMgr.TreatCoincidenceAsInterference = True
• Run Interference Check (any method except Done)
Dim swInts() As Object = swIntMgr.GetInterferences
Dim swInt As Interference = Ctype(swInts(0), Interference)
• Grab results
Dim dVolumes As Double = swInt.Volume
Interference/Collision Detection – More Complete Code
Dim swAssembly As AssemblyDoc = CType(swDoc, AssemblyDoc)
swDoc.Parameter("CrankAngle@[email protected]").Value = 150
Dim boolstatus As Boolean = swDoc.EditRebuild3()
Dim swIM As InterferenceDetectionMgr = swAssembly.InterferenceDetectionManager
Dim iIntQty As Integer = swIM.GetInterferenceCount
If iIntQty >= 0 Then
Dim swInts(iIntQty - 1) As Object
swInts = swIM.GetInterferences
Dim swInt As Interference = CType(swInts(0), Interference)
MsgBox(swInt.Volume)
End IfDon’t forget to test all objects and results!
Sensors(PART)
(ASSY)
• Sensor types
• Notice for interactive users
• Potential performance issues
• Suppress extraneous sensors
• Set notification frequency
Working with Sensors in Code
• Get the sensor object from the Sensor Feature (use MD2.GetFirstFeature)
Dim swSensor As Sensor = swFeature.GetSpecificFeature2
• Critical sensor properties and methods
Select Case swSensor.SensorType
Case swSensorType_e.swSensorSimulation
Case swSensorType_e.swSensorMassProperty
Case swSensorType_e.swSensorDimension
Case swSensorType_e.swSensorInterfaceDetection
End Select
• Be sure to Update the sensor with the UpdateSensor method
• Check the AlertState to see if the sensor has picked up on a problem
• Use the AlertType to see what kind of a problem
SW2009 SP2 and before only supported Dimension Sensors
Using SolidWorks Events
• Create a class
• Declare a variable WITHEVENTS for the object that holds your events
Public WithEvents swPart As SolidWorks.interop.sldworks.PartDoc
• Create a Function for whatever event you want to monitor
Function swPart_SensorAlertPreNotify(ByVal swSensor As Object, ByVal _
SensorAlertType As Integer) As Integer
Shell("http://www.twitter.com/?'#SW Sensor!'", AppWinStyle.Hide, False)
End Function 'swPart_SensorAlertPreNotify
• In your main code – Activate the handler (RemoveHandler to discontinue)
AddHandler swPart.SensorAlertPreNotify, AddressOf _
Me.swPart_SensorAlertPreNotify
Check out all available events in API Help
Note who your event belongs to
Using SolidWorks Events
• Create a class
• Declare a variable WITHEVENTS for the object that holds your events
Public WithEvents swPart As SolidWorks.interop.sldworks.PartDoc
• Create a Function for whatever event you want to monitor
Function swPart_SensorAlertPreNotify(ByVal swSensor As Object, ByVal _
SensorAlertType As Integer) As Integer
Shell("http://www.twitter.com/?'#SW Sensor!'", AppWinStyle.Hide, False)
End Function 'swPart_SensorAlertPreNotify
• In your main code – Activate the handler (RemoveHandler to discontinue)
AddHandler swPart.SensorAlertPreNotify, AddressOf _
Me.swPart_SensorAlertPreNotify
Check out all available events in API Help
Note who your event belongs to
(Don’t think you can ignore me)
Using SolidWorks Events
• Create a class
• Declare a variable WITHEVENTS for the object that holds your events
Public WithEvents swPart As SolidWorks.interop.sldworks.PartDoc
• Create a Function for whatever event you want to monitor
Function swPart_SensorAlertPreNotify(ByVal swSensor As Object, ByVal _
SensorAlertType As Integer) As Integer
Shell("http://www.twitter.com/?'#SW Sensor!'", AppWinStyle.Hide, False)
End Function 'swPart_SensorAlertPreNotify
• In your main code – Activate the handler (RemoveHandler to discontinue)
AddHandler swPart.SensorAlertPreNotify, AddressOf _
Me.swPart_SensorAlertPreNotify
Check out all available events in API Help
Note who your event belongs to
(I’m not going away)
Using SolidWorks Events
• Create a class
• Declare a variable WITHEVENTS for the object that holds your events
Public WithEvents swPart As SolidWorks.interop.sldworks.PartDoc
• Create a Function for whatever event you want to monitor
Function swPart_SensorAlertPreNotify(ByVal swSensor As Object, ByVal _
SensorAlertType As Integer) As Integer
Shell("http://www.twitter.com/?'#SW Sensor!'", AppWinStyle.Hide, False)
End Function 'swPart_SensorAlertPreNotify
• In your main code – Activate the handler (RemoveHandler to discontinue)
AddHandler swPart.SensorAlertPreNotify, AddressOf _
Me.swPart_SensorAlertPreNotify
Check out all available events in API Help
Note who your event belongs to
(I’m not going away)
Using SolidWorks Events
• Create a class
• Declare a variable WITHEVENTS for the object that holds your events
Public WithEvents swPart As SolidWorks.interop.sldworks.PartDoc
• Create a Function for whatever event you want to monitor
Function swPart_SensorAlertPreNotify(ByVal swSensor As Object, ByVal _
SensorAlertType As Integer) As Integer
Shell("http://www.twitter.com/?'#SW Sensor!'", AppWinStyle.Hide, False)
End Function 'swPart_SensorAlertPreNotify
• In your main code – Activate the handler (RemoveHandler to discontinue)
AddHandler swPart.SensorAlertPreNotify, AddressOf _
Me.swPart_SensorAlertPreNotify
Check out all available events in API Help
Note who your event belongs to
(Keep it up. Your iPhone is next.)
Using SolidWorks Events
• Create a class
• Declare a variable WITHEVENTS for the object that holds your events
Public WithEvents swPart As SolidWorks.interop.sldworks.PartDoc
• Create a Function for whatever event you want to monitor
Function swPart_SensorAlertPreNotify(ByVal swSensor As Object, ByVal _
SensorAlertType As Integer) As Integer
Shell("http://www.twitter.com/?'#SW Sensor!'", AppWinStyle.Hide, False)
End Function 'swPart_SensorAlertPreNotify
• In your main code – Activate the handler (RemoveHandler to discontinue)
AddHandler swPart.SensorAlertPreNotify, AddressOf _
Me.swPart_SensorAlertPreNotify
Check out all available events in API Help
Note who your event belongs to
Fine! I’ll do it myself.
Rebooting in:
Applying Update 1 of 9,278,029….0% Complete
Do Not Turn Off Computer
Applying Update 1 of 9,278,029….0.001% Complete
Don’t Even Think About It.
I’ll restart when I’m good and ready.
Autonomous Edition
SOLIDWORKS SIMULATIONAt long last…
Automating SolidWorks Simulation
• Evaluate what you are trying to automate
Can it be done with sensors?
Can it be done with Optimization?
• Not all of SolidWorks Simulation is documented in API Help
Extra SDKs or Installation options may be required (ex. Flow)
Gimme an S, Gimme an R, Gimme an A, Gimme a C!
• Must add SolidWorks 2010 Simulation Type Library as a reference to each project
You can also add SolidWorks.Interop.cosworks.dll−You will need to BROWSE for it …SolidWorks\API\redist
(cosworks? There’s your proof that all the product renames are marketing)
Possible Applications
• Record iterative results
Run iterations and send results out to Excel or other system
Allow code or outside tool control when to iterate and how
Possible Applications
• Attach / create / modify study components (loads, connections, etc.)
Create 400 pin locations in a regular (or slightly irregular) array
Create an unknown number of loads based on driven geometry
• Allow 3rd party solutions to kick off simulation as part of automation
• More complex iterative optimizations using your own optimization algorithm
Change what YOU want to change, how YOU want to change it
Cosmos? Yes, Cosmos.
Run Analysis© COSMOS/and COSMOS/WORKS and their respective logos property of Structural Research Analysis Corporation 1997
• RMB in the Project Explorer to add a Reference
• You will not find it in the .NET tab
• You MAY find it under COM
• You will most likely need to browse for it
Adding The Reference
The Process
Imports SolidWorks.interop.cosworks is implied
• Fetch the SolidWorks Simulation (CosmosWorks) Add-In object
Dim cwAddIn As SolidWorks.interop.cosworks.CWAddInCallBack = _swApp.GetAddInObject("CosmosWorks.CosmosWorks")
• Fetch the cwModelDoc
Dim CWorks As Object = cwAddIn.CosmosWorks
Dim cwDoc As CWModelDoc = Ctype(CWorks.ActiveDoc(), CWModelDoc)
• Fetch the CWStudyManager object
Dim cwStudyMgr As CWStudyManager = cwDoc.StudyManager()
More of The Process
• Fetch the CWStudy object
Test for study existence with StudyCount
Dim cwStudyCount As Integer = cwStudyMgr.StudyCount
Dim cwCurStudy As CWStudy
Dim iErrors As Integer
IF cwStudyCount > 0 Then
cwCurStudy = CWStudyManager.GetStudy(0)
Else
cwCurStudy = CWStudyManager.CreateNewStudy2 _
(“StudyName”, type, iErrors)
End If
TIP: Don’t create studies when you can preset and drive them
Imports SolidWorks.interop.cosworks is implied
Add Material
• Need to apply the material to the Solid Body Object
Study gets the SolidManager
SolidManager gets the SolidComponent
SolidComponent gets the SolidBody
Circle gets the square
Dim cwSolidMgr As CosmosWorksLib.CWSolidManager
cwSolidMgr = cwCurStudy.SolidManager
Dim CompCount As Integer = cwSolidMgr.ComponentCount
Dim cwComp As CWSolidComponent = cwSolidMgr.GetComponentAt(0, cwStudyErrors)
Dim cwBody As CWSolidBody = cwComp.GetSolidBodyAt(0, cwStudyErrors)
cwStudyErrors = cwBody.SetLibraryMaterial("M:\MyMatlLib\RLMatl.sldmatlib", "Unobtainium")
Even More of The Process
• Get the next Manager or Options object
All properties and options reside one level down
Dim cwStaticOptions As CWStaticStudyOptions
cwStaticOptions = cwCurStudy.StaticStudyOptions
cwStaticOptions.SolverType = _
CosmosWorksLib.swsSolverType_e.swsSolverTypeFFEPlus
Dim cwCurMesh As CWMesh = cwCurStudy.Mesh
cwCurMesh.Quality = _
CosmosWorksLib.swsMeshQuality_e.swsMeshQualityHigh
Imports SolidWorks.interop.cosworks is implied
All ReadOnly!!
Even Still More of The Process
• Update components, mesh and run the analysis
Update is for any geometry changes since last run
'We'll typically calculate or get these as inputs
Dim dElementSize As Double = 0.0012
Dim dTolerance As Double = 0.005
cwCurStudy.UpdateAllComponents()
cwCurStudy.CreateMesh(CosmosWorksLib.swsUnit_e.swsUnitEnglish, _
dElementSize, dTolerance)
cwCurStudy.RunAnalysis()
Imports SolidWorks.interop.cosworks is implied
Mandatory Charts (Gratuitous Chart of Fictitious Data)(per Microsoft PowerPoint code 2009 Section XXIV Subsection 441.K.9.ii.v)
EngineersMarketing
StudentsAccountants
0
10
20
30
40
50
60
70
80
90
100
Blink
Whisper
Grunt
Reaction to Subtle Jokes In Slides by
Demographic
Enginee
rs
Manag
ement
0%10%20%30%40%50%60%70%80%90%
100%
Telnet ChatDrinkOnline PokerDancingSleep
Activities Past Midnight
Even Yet Still More of The Process
• Retrieve the Results object
Most Results methods return arrays
These are typically brought in with generic options
Dim cwCurResults As CWResults
cwCurResults = cwCurStudy.Results
Dim cwResultsErrors As Integer
Dim cwStress As Object
cwStress = cwCurResults.GetMinMaxStress _
(0, 0, 1, Nothing, 0, cwResultsErrors)
Imports SolidWorks.interop.cosworks is implied
Dealing with Arrays
• Return types are VERY vague
• Always the possibility of a null return
• Most samples stay generic
VBA dim as VARIANT
VB.NET/C#.NET dim as OBJECT
• Run once or twice or check sample to find out return type
• Fetch as generic object then recast the variable to get the array
• ERROR TRAP THE SNOT OUT OF IT!!!
• Make separate functions wherever possible to use Try…Catch blocks
Allows you to handle the errors differently
Array Sample
TRY
‘Define as generic object
Dim cwStress As Object
‘Retrieve the object
cwStress = cwCurResults.GetMinMaxStress(0, 0, 1, Nothing, 0, cwResultErrors)
If cwStress IsNot Nothing
‘Declare your array
Dim cwStressArray() As Double
‘Recast your generic object as an array
cwStressArray = CType(cwStress, Double())
If cwStressArray.Length > 0 Then
For Each dStress As Double In cwStressArray
Next dStress
End If ‘Array.Length > 0
End If ‘we have a stress results object
Array Sample
Catch
‘Handle the fact that we did not get usable stress results
End Catch
Try
‘Define as generic object
Dim cwDisplacement As Object
‘Retrieve the object
cwDisplacement = cwCurResults.GetMinMaxDisplacement(0, 0, Nothing, _
CosmosWorksLib.swsUnit_e.swsUnitEnglish, cwStudyErrors)
If cwDisplacement IsNot Nothing
‘Declare your array
Dim cwDispArray() As Double
‘Recast your generic object as an array
cwStressArray = CType(cwStress, Double())
And so on…
Getting Back Visual Results
“A picture is worth a thousand lines of code”
– Michaelangelo (…I think)
• The absolute most beneficial feature of automating simulations!!!
• API has the ability to activate plots, delete plots, and tell you how many there are and their names
• There appears to be no way to Save plots or animations out to files.
End of slide
OTHER PLACES TO EXPLOREAnd finally…
Other Validation Tools
Available via API
• SolidWorks Utilities
Compare Document
Compare Feature
Compare Geometry
Geometry Analysis
Thickness Analysis
• Design Checker
• Check (Face, Edge, Body)
• Parting Line Draft Analysis
NOT Available via API
• SimulationXpress
• FloXpress
• DFMXpress
• SustainabilityXpress
• Deviation Analysis
• TolAnalyst
Outside Validation Tools
• Calculations are too involved or not understood to recreate
• External DLL code
May be VB, FORTAN, PASCAL, GW-BASIC, Assembly Code, Pig Latin
public declare function InitializeLibrary lib "extn.dll" alias "_InitializeLibrary@12" (byval hWnd as long, byval str as string, byval dword as long) as longShell
• External EXE code
Shell(“PVCalc.EXE “ & dPressure & “,” & dWallThk, AppWinStyle.MinimizedNoFocus)
• Web-based ASP tools
Less overhead to load/install
Most applications allow parameters to be passed in the header
Questions? Comments? Suggestions? Soup Recipes?
• If you have questions you would like to discuss, please find me
Now…At any time during the conference…or After the conference
• Presentation available on www.razorleaf.com
Free newsletter with tech tips, industry insiders and more…
• Catch me in my upcoming tour dates!!
Wednesday @ 1:30 – Automating Your Designs with Excel and the SW API
Friday @ Miffy’s Muffin Palace – Drury Lane
Paul GimbelBusiness
Process [email protected] www.razorleaf.com TheProcesSherpa on Twitter
The Sherpa
• PLEASE PLEASE PLEASE fill out your survey
• It takes practically no time at all
• I HONESTLY want your feedback and I do apply it
• Let’s see if the SolidWorks folks read these:
• PLEASE PLEASE PLEASE fill out your survey
• It takes practically no time at all
• I HONESTLY want your feedback and I do apply it
• Let’s see if the SolidWorks folks read these:
In the comments section, add:
“OK, I’m stumped. How did he pull my card out of THERE?”
SURVEY TIME!!!
Paul Gimbel, Razorleaf [email protected]
@TheProcesSherpa on Twitter