As far as any step-by-step for getting started, you could try out this small crash-course:
1. make sure you have installed the Maxwell.Script library - this is available from the same place you download the plugin installer
2. open SolidWorks, go to Tools > Macro > New
3. the VBA editor will open up, and there will be a code page like this:
Code: Select all
4. try editing the code to look like this:Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
End Sub
Code: Select all
5. that's your basic hello world example - click the 'Run Sub/UserForm' button in the VBA editor toolbar to run this code; you should just get a small message box (i.e. MsgBox) that pops upDim swApp As Object
Sub main()
Set swApp = Application.SldWorks
MsgBox "hello world."
End Sub
6. next, we'll connect to the current Maxwell Scene (assuming there is a document open). Start by going to Tools > References in the VBA editor's toolbar - we are going to load the Maxwell.Script library...
7. in the 'References' dialog which comes up, scroll down to the Maxwell.Script entry, check its' checkbox, and click OK
8. in the VBA menu go to View > Object Browser, then in the Object Browser's drop-down, select 'Maxwell_Script' - this will show you the objects which are available for you to code against...this is what you'll see:
9. finally, here is how some code would look which gets or sets some parameters in the current scene:
Code: Select all
That's a quick tutorial, and I apologize if you already knew some of it. If not, you can pick up a 'VBA for Dummies' book at the local bookstore which can pretty quickly teach you basic VBA syntax. VBA itself is really the same whether you're coding against SolidWorks, AutoCAD, MS Word/Excel, etc. There are also some VBA code examples in the SW documentation if you go to SolidWorks main menu > Help > API Help Topics item, then drill down into the contents to SolidWorks API Help > Examples and Projects > Visual Basic (VB) Examples - these can show you how to get your hands on objects in the SolidWorks model.Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
Dim maxwell As New Maxwell_Script.ScriptObject
If maxwell Is Nothing Then
MsgBox "unable to create Maxwell.Script.ScriptObject."
' bail
Exit Sub
End If
If Not maxwell.IsConnected Then
MsgBox "unable to connect to the current Scene (if there even is one)."
'bail
Exit Sub
End If
'get some camera params
MsgBox "the current camera is named '" & maxwell.Camera.Name & "'"
MsgBox "the current camera's fStop is " & maxwell.Camera.fStop
'get/set some environment params
maxwell.Environment.EnvironmentType = "PhysicalSky"
MsgBox "the environment type is " & maxwell.Environment.EnvironmentType
maxwell.Environment.EnvironmentType = "SkyDome"
MsgBox "changed the environment type to " & maxwell.Environment.EnvironmentType
'get/set date/time params
MsgBox "the current time of day is " & maxwell.DateAndTime.TimeOfDay
maxwell.DateAndTime.TimeOfDay = 11.22
MsgBox "changed time of day to " & maxwell.DateAndTime.TimeOfDay
End Sub