AnsweredAssumed Answered

Creating an Equation based on a measurement?

Question asked by Chris Johnson on Sep 4, 2013
Latest reply on Sep 4, 2013 by Chris Johnson

Hi All,,

 

I must be doing something wrong and could use a little help.

I want to measure the diameter of a selected edge and then use that dia. in an equation but its not working and I have no idea why.

 

 

Here is the test code I set up to goof around with... see anything wrong?

 

Option Explicit

    Dim swApp As Object

    Dim swmodel As Object

    Dim boolstatus As Boolean

    Dim longstatus As Long, longwarnings As Long

    Dim Measure                     As Measure

   

    Sub main()

    Set swApp = Application.SldWorks

    Set swmodel = swApp.ActiveDoc

    Set Measure = swmodel.Extension.CreateMeasure

 

Measure.ArcOption = 0

 

'PreSelect Edge and Run Macro

'Measure and Store selected Edge Diameter for later use

            boolstatus = Measure.Calculate(Nothing)

        Dim myMeasurement As Variant

            myMeasurement = Measure.Diameter

            swmodel.ClearSelection2 True

   

   

     

        Dim swEquationMgr As Object

            Set swEquationMgr = swmodel.GetEquationMgr()

                swEquationMgr.Add2 -1, """D1@Sketch2"" = myMeasurement - 0.5", True

  

'this shows that the measurement exists..      

    Debug.Print myMeasurement

   

    boolstatus = swmodel.ForceRebuild()

   

    End Sub

 

T

Thank you

Chris

Outcomes