By JDHill
#282970
Sure, I'm happy to try to work something up, but it may take me a few days to find some time to do it.
User avatar
By w i l l
#284625
JD - you didnt have time to do this did you by any chance? I still need to do the Solidworks zoom in.

If not, no worries I don't want to be a pest.
By JDHill
#284626
Hi Will, no I didn't - to be honest, being busy with the new Cinema plugin release, I had forgotten about this thread...let me see what I can do.
By JDHill
#284650
Pretty similar to the turntable one, just try this out and let me know if it does what you're looking for:
Code: Select all
Sub MaxwellZoomAnimation()
    On Error GoTo handle_error
    
    'dialog title
    Dim dialogTitle As String
    dialogTitle = "Maxwell Turntable Animation"
    
    'get SW
    Set swApp = Application.SldWorks
    If swApp Is Nothing Then
      MsgBox "Unable to connect to SolidWorks", vbOKOnly, dialogTitle
      Exit Sub
    End If
    
    'get active doc
    Dim doc As ModelDoc2
    Set doc = swApp.ActiveDoc
    If doc Is Nothing Then
      MsgBox "There is no active document.", vbOKOnly, dialogTitle
      Exit Sub
    End If
    
    'get active view
    Dim view As ModelView
    Set view = doc.ActiveView
    If view Is Nothing Then
      MsgBox "There is no active view.", vbOKOnly, dialogTitle
      Exit Sub
    End If
    
    'get view camera
    Dim cam As Camera
    Set cam = view.Camera
    If cam Is Nothing Then
      MsgBox "The active view has no SolidWorks camera - " & _
      "please add one, or choose a viewport which does.", vbOKOnly, dialogTitle
      Exit Sub
    End If
    
    'Maxwell.Script ScriptObject
    Dim maxwell As Object
    Set maxwell = CreateObject("Maxwell.Script.ScriptObject")
    
    'ScriptObject is created?
    If maxwell Is Nothing Then
      MsgBox "Unable to create Maxwell.Script.ScriptObject.", vbOKOnly, dialogTitle
      Exit Sub
    End If
    
    'ScriptObject is connected?
    If Not maxwell.IsConnected Then
      MsgBox "There is no current Maxwell Scene.", vbOKOnly, dialogTitle
      Exit Sub
    End If
    
    'declare a bunch of variables
    Dim viewportRect(0 To 3) As Long
    Dim originalPosition As MathPoint
    Dim cameraTarget As MathPoint
    Dim distance As MathVector
    Dim framePosition As MathPoint
    Dim strFrameCount As String
    Dim frameCount As Integer
    Dim meshesWereCached As Boolean
    Dim i As Integer
    
    'get viewport for refreshing
    viewportRect(0) = view.FrameLeft
    viewportRect(1) = view.FrameTop
    viewportRect(2) = view.FrameWidth
    viewportRect(3) = view.FrameHeight
    
    'initialize previous frameCount
    If previousFrameCount < 2 Then
      previousFrameCount = 24
    End If
    
    'get number of frames from user
get_frameCount:
    strFrameCount = InputBox("Specify the number of frames to render.", _
                             dialogTitle, previousFrameCount)
    'cancelled by user?
    If strFrameCount = "" Then Exit Sub
    
    'validate to numeric input
    If Not IsNumeric(strFrameCount) Then
      MsgBox "Please enter a number.", vbOKOnly, dialogTitle
      'try again
      GoTo get_frameCount
    End If
    
    'validate specified number of frames
    If CInt(strFrameCount) < 2 Then
      MsgBox "Please enter a number greater than one.", vbOKOnly, dialogTitle
      'try again
      GoTo get_frameCount
    End If
    
    'set framecount
    frameCount = CDbl(strFrameCount)
    
    'check for crazy number of frames
    If frameCount > 360 Then
      If Not MsgBox("That sure is alot of frames (" & _
                    frameCount & "). Do you really want " & _
                    "continue?", vbYesNo, dialogTitle) = vbYes Then
        Exit Sub
      End If
    End If
    
    'store as previous count
    previousFrameCount = frameCount
    'current position/target
    Set originalPosition = cam.GetPosition
    Set cameraTarget = cam.TargetPointPosition
    'save current value of Cache MXS Meshes option
    meshesWereCached = maxwell.PlugInOptions.CacheMXSMeshes
    'enable Cache MXS Meshes
    maxwell.PlugInOptions.CacheMXSMeshes = True
    'start plugin animation loop
    maxwell.Rendering.BeginAnimation

    For i = 1 To frameCount
      'write MXS
      maxwell.Rendering.RenderToMxs
      'get distance vector again
      Set distance = originalPosition.Subtract(cameraTarget)
      'scale by frameCount
      Set distance = distance.Scale(1# - (i / frameCount))
      'add scaled distance to original target
      Set framePosition = cameraTarget.AddVector(distance)
      'set new position
      cam.SetPositionCartesian framePosition.ArrayData(0), _
                               framePosition.ArrayData(1), _
                               framePosition.ArrayData(2)
      'refresh viewport
      view.GraphicsRedraw (viewportRect)
    Next

    'end plugin animation loop
    maxwell.Rendering.EndAnimation
    'reset camera exactly where it was before
    cam.SetPositionCartesian originalPosition.ArrayData(0), _
                             originalPosition.ArrayData(1), _
                             originalPosition.ArrayData(2)
    'refresh viewport
    view.GraphicsRedraw (viewportRect)
    'restore Cache MXS Meshes option to previous value
    maxwell.PlugInOptions.CacheMXSMeshes = meshesWereCached
    
    'done
    Exit Sub
    
    'something went wrong
handle_error:     MsgBox "An unexpected error occurred (" & Err.Description & ")"

End Sub
To test it without rendering, just comment-out (i.e. put an apostrophe at the front of the line) the BeginAnimation, RenderToMxs, and EndAnimation lines.
User avatar
By w i l l
#286349
Yeah thats good - thanks!

I've noticed that within Solidworks using the Maxwell plugin that if I type a number say '1' for example it actually types '111' (3x the number). Is there some setting that I need to change? This doesn't happen in any other software.
By JDHill
#286356
Hi Will, where do you mean? There are some places where the plugin tries to keep names unique, so it may be appending a '1' in an effort to do that, but I'd need to know where you're seeing it to say for sure.
User avatar
By w i l l
#286360
Well everywhere that you can input a value i.e. Sun Power or camera f-Stop.... anywhere. It's actually 4x so if I type 9 I get 9999. Maybe it's a keyboard problem, but it only happens in the Maxwell plugin.
By JDHill
#286364
Hmm, well there's nothing in the code to make it do that, so I'd look at whether there might be some other application running that would have a hook for monitoring/altering keystrokes, or else try repairing or updating the .Net Framework on your machine.
User avatar
By w i l l
#295873
Haven't checked this forum for a while... just wondering if Next Limit are any closer to convincing Solidworks to allow integration of Maxwell into Solidworks MotionManager for animation?

I get asked quite a lot to do product animation and still don't like the idea of converting Solidworks models and importing to Cinema 4D etc for animation.
By JDHill
#295874
I believe that I'll be able to make that work, it's just that along with integrating the texture-mapping feature of SW2009, this involves replacing almost all of the plugin's code and dropping support for earlier SW versions. I expected this to happen prior to yesterday's new release, but it was not yet possible, so I decided to release as-is and allow SW2007+ users to also get the benefit of the improvements that the new version provides. So it's going to take more time, and I don't have a definite ETA.
User avatar
By John Layne
#295887
Looking forward to the motion integration, that will be the day that I upgrade from swx 2008 to 2009
By CRAS
#295907
I´m struggling to get the example scripts running.
I followed the steps carefully and even prepared a maxwell scene, camera, etc.

The script tells me that: "There is no current Maxwell Scene"

Did I miss something? - please help
By JDHill
#295913
If you are running version 1.8.2 of the plugin, you don't need these scripts - I put them directly in the plugin. Just look in the plugin's menu/toolbar for the turntable and zoom animation buttons.
Sketchup 2024 Released

Any idea of when the Maxwell Sketchup plugin will […]

Will there be a Maxwell Render 6 ?

Let's be realistic. What's left of NL is only milk[…]