AnsweredAssumed Answered

Kinematics Macro - can I drive the model?

Question asked by Simon Rafferty on May 6, 2016

I have been looking at the possibility of using Solidworks to generate positions for actuators by dragging a model (multi axis robot)  to a required position, let SW calculate the lengths of the actuators then save them as a line in a CSV file.

 

In order to avoid having to configure the macro for each model, I did this by using Distance & Angle limit mates and renaming the ones I'm interested in as Axis1, Axis2 etc.  The macro can parse the mates folder to find any called Axis# then build a CSV based on that.  That bit seems to work OK.

 

The bit that has floored me is reading back the CSV and forcing the model to move correspondingly.  If I change the mate type to ordinary distance mates - I can write a value to the distance and the model moves when I force an update.  However, like that, you cannot move the model by dragging - Hence using limit mates.

 

I can write a value to the distance, read it back and it appears to have changed.  However when I rebuild the model - the value changes back to what it was set to before and the model does not move!

[code]

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swFeat As SldWorks.Feature

Dim swMate As SldWorks.Mate2

 

Sub main()

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    If swModel Is Nothing Then

        End

    End If

   

    Set swFeat = swModel.FeatureByName("Axis1")

   

    If swFeat Is Nothing Then

        End

    End If

   

    Set swMate = swFeat.GetSpecificFeature2

   

    Dim swDispDim As SldWorks.DisplayDimension

    Dim swDim As SldWorks.Dimension

   

    Set swDispDim = swMate.DisplayDimension2(0)

   

    Set swDim = swDispDim.GetDimension2(0)

   

    Dim val As Double

   

    val = swDim.GetSystemValue3(swInConfigurationOpts_e.swThisConfiguration, "")(0)

    Debug.Print "Original Distance = " & val

    val = val + 0.005 'Add 5mm to distance

    swDim.SetSystemValue3 val, swInConfigurationOpts_e.swAllConfiguration, ""

    Debug.Print "New Distance value = " & swDim.GetSystemValue3(swInConfigurationOpts_e.swThisConfiguration, "")(0)

   

    'swModel.EditRebuild3

    swModel.ForceRebuild3 True

    Debug.Print "New Distance value after rebuild = " & swDim.GetSystemValue3(swInConfigurationOpts_e.swThisConfiguration, "")(0)

 

End Sub

[/code]

 

Which outputs the following:

Original Distance = 3.64127446215382E-02

New Distance value = 4.14127446215382E-02

New Distance value after rebuild = 3.64127446215564E-02

 

Is there some 'issue' with the API implementation of Distance Limit Mates?  I've only tried it in 2015 - but we're sticking with 2015 for the time being so it has to work in that!

 

Thanks in advance,

 

Si

Outcomes