In this example, the SnS plug-in is assumed to have been used to specify the material, restraints, and loads for the simulation. SnSScript is then called by the following script to solve the simulation at different resolutions. The results are written to a text file for import into a spreadsheet.
Option Explicit Call Main() Sub Main() Dim FileLocation : FileLocation = "C:\Users\Michael\Desktop\RSFile.txt" Dim objFSO, objFile, strObject, objSnSPlugIn, resolution Dim disp, vonm, bottomPt Set objSnSPlugIn = Rhino.GetPluginObject("SnSScript") 'Open a file to receive the computed values and write the header Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(FileLocation, 2, True) Call objFile.Write("Resolution,Displacement,vonMises" & vbCrLf) 'Specify location to sample the von Mises stress bottomPt = Array(3.5, 0, 0) 'Have user select the solid to analyze strObject = Rhino.GetObject("Select a solid") 'Iterate through resolutions, solve at each resolution and 'write solution values to the file. For resolution=50 To 1000 Step 50 objSnSPlugIn.Solve strObject, resolution disp = objSnSPlugIn.QuerySolutionMax(strObject, "DSPT") vonm = objSnSPlugIn.QuerySolutionValue(strObject, "VONM", bottomPt) Call objFile.Write(resolution & "," & disp & "," & vonm & vbCrLf) Next Call objFile.Close() End Sub
Line # | Description |
---|---|
1 | Only scripts with Option Explicit specified can be debugged in the RhinoScript editor (Monkey). |
4-6 | Declare variables before use. Here FileLocation refers to a text file to be created on the desktop. |
8 | Obtain a reference to the SnSScript plug-in, exit if an error occurs. |
11-13 | Open a text file and write a comma-delimited header to it. We can open this later in a spreadsheet. |
16 | Specify a point on the object where the stress is to be sampled. |
19 | Prompt the user to select a solid for the convergence study. The solid is identified by its GUID stored in strObject. |
23 | Iterate through resolutions of 50 to 1000 elements. |
24 | Solve for the stress at the current resolution. |
25-26 | Query the maximum displacement and the von Mises stress at the coordinates (3.5,0,0). |
27 | Write the query results to the file. |
29 | Close the text file. |
After importing the text file into a spreadsheet, the results are easily graphed: