5 Replies Latest reply on Nov 25, 2014 9:12 PM by Velibor Marjanovic

    Getting physical dimension value out of particular sketch?

    Velibor Marjanovic

      Hi,

      at the moment I am stuck with trivial issue (it should be, unless I don't get this at all) in regards to passing dimension out of sketch:

      Dim swPart as IPartDoc

      Dim featureOfPart as IFeature = Nothing

      Dim sketchWidth As IDimension = Nothing

      Dim dblSketchWidth as Double = 0

       

      swPart = swApp.ActiveDoc

      featureOfPart = swPart.FeatureByName("Something")

      sketchWidth = featureOfPart.IParameter("Width@SomethingSketch@SomethingPart.sldprt")

       

      dblSketchWidth = sketchWidth.IGetSystemValue3(swInConfigurationOpts_e.swThisConfiguration, 1, Nothing)

      MsgBox (dblSketchWidth)

       

      Getting an error: "Use the "new" keyword to create object instance.".

      Tried other functions (dimension.value, IGetValue3) which returns double value from dimension but with same issue and message.

      IGetSystemValue3 should return double value of the length. Please let me know what I am missing here. I tried to use SelectionByID, but that function uses x, y, z coordinates and what I need it is length of line, not its location in space. BTW using SW2014 with Visual Basic.Net as macro language.

      Thanks.

        • Re: Getting physical dimension value out of particular sketch?
          Daniel Andersson

          Have you tried  to change

           

          sketchWidth = featureOfPart.IParameter("Width@SomethingSketch@SomethingPart.sldprt")

           

          To

           

          sketchWidth = featureOfPart.IParameter("Width")

           

          It might also be that your "Something" feature is not the actual sketch feature.

           

          See this post as reference:

          https://forum.solidworks.com/thread/62821?forceNoRedirect=true

           

          And I'm not sure but the "1" in

          sketchWidth.IGetSystemValue3(swInConfigurationOpts_e.swThisConfiguration, 1, Nothing

          Might be set to nothing since you are not specifing any specific configuration (swSpecifyConfiguration).

           

          Could you please state on which line you get the error if my suggestions do not help.

            • Re: Getting physical dimension value out of particular sketch?
              Velibor Marjanovic

              Ooops clicked previously  on wrong one...

              Hi, first of all thanks for helping.

              I did change upper suggestion (in regards to "Width"), and changed function name to sketchWidth.GetValue2("Default"), so I can avoid numbering configurations (decrease number of potential problems) and again getting same error. Debugger stops actually right on that line: dblSketchWidth=sketchWidth.GetValue2("Default"). BTW default is only configuration available.

              Really not quite sure what is issue here???

                • Re: Getting physical dimension value out of particular sketch?
                  Daniel Andersson

                  GetValue2 is obsolete and you should stick with GetSystemValue3. Go for GetSystemValue3 and you will have different input and returns. Noticed that you tried to used IGetSystemValue3. I would follow the example below, taken from

                  http://help.solidworks.com/2014/english/api/sldworksapi/Get_Depth_of_Extrusion_Example_VBNET.htm

                   

                  E.g.....

                   

                          Dim swModel As ModelDoc2

                          Dim swDim As Dimension

                          Dim vConfigNames As Object

                          Dim vValue As Object

                   

                          swModel = swApp.ActiveDoc

                          swDim = swModel.Parameter("D1@Boss-Extrude1") 'Would be Width@SomeSketch in your case.

                   

                          Debug.Assert(Not swDim Is Nothing)

                   

                          Debug.Print("File = " & swModel.GetPathName)

                          Debug.Print("  FullName     = " & swDim.FullName)

                          Debug.Print("  Name         = " & swDim.Name)

                   

                          vConfigNames = swModel.GetConfigurationNames

                          vValue = swDim.GetSystemValue3(swInConfigurationOpts_e.swThisConfiguration, (vConfigNames))

                   

                          Debug.Print("  SystemValue  = " & vValue(0) * 1000.0# & & "" & "mm")

                    • Re: Getting physical dimension value out of particular sketch?
                      Velibor Marjanovic

                      Hello Daniel,

                      thanks for the solution. Finally the issue is resolved, but for my overall understanding, I don't get it yet why it did not work out with:

                      swPart = swApp.ActiveDoc

                      swFeature = swPart.FeatureByName("Blahblah")

                      swDim = swFeature.IParameter("Something@SomethingElse")

                      dblValue = swDim.IGetSystemValue3(thisConfiguration, vConfigName)

                       

                      Technicaly all parameters given are correct and should coincide with by function required return value (especially dblValue line as returned value should be the number).

                      Best regards,

                • Re: Getting physical dimension value out of particular sketch?
                  Velibor Marjanovic

                  Hi, first of all thatnks for helping.

                  I did change upper suggestion (in regards to "Width"), and changed function name to sketchWidth.GetValue2("Default"), so I can avoid numbering configurations (decrease number of potential problems) and again getting same error. Debugger stops actually right on that line: dblSketchWidth=sketchWidth.GetValue2("Default")

                  Really not quite sure what is issue here???