2 Replies Latest reply on Jan 13, 2014 5:05 PM by Daniel McRae

    Difficulty linking dimensions from API

    Daniel McRae

      With our sheet metal parts, we often use equations that are derived from the sheet metal thickness or bend radius; for instance, we have a permanent variable called trim, which is the sum of the two. This way we can dimension something based on the overall size and allow space for any aditional flanges added later. To access these, we have two global variables, Thickness and BendRadius. Before SW was modified to allow for multibody sheet metal parts, our template had these permanently linked, but this hasn't worked for the last few years. So we re-wrote one of the macros we use to link the thickness and bend radius to these variables. This stops working every so often as SW changes, so we re-modify it.

       

      The most recent update to SW has broken our tool and I'm having trouble fixing it. The main problem is that the API doesn't seem to be letting me link the variables using the DisplayDimension.SetLinkedText command. The basic macro I've been using is listed below - all you should need to test it is a file containing a sheet metal feature. Any suggestions to get around this problem are welcome!

       

       

      ' Link sheet metal thickness and Bend Radius to already existing global

      ' variables named Thickness and BendRadius respectively.

      '

      ' Requires an open part with the sheet metal feature already existing,

      ' and two global variables, one called Thickness, one called BendRadius


      Sub main()

          Dim swApp As SldWorks.SldWorks

          Dim swModel As ModelDoc2

          Dim swFeat As Feature

          Dim dispDimension As DisplayDimension


          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc


          ' Iterate over all features looking for sheetmetal, then iterate over

          ' dimensions that feature contains

          Set swFeat = swModel.FirstFeature

          Do While Not swFeat Is Nothing

              If swFeat.GetTypeName2 = "SheetMetal" Then

                  Set dispDimension = swFeat.GetFirstDisplayDimension

                  Do While Not dispDimension Is Nothing

                      ' D7 seems to be the thickness in all the new sheetmetal

                      ' features I've tried

                      If dispDimension.GetDimension2(0).Name = "D7" Then

                          dispDimension.SetLinkedText "Thickness"  ' Doesn't work!

                      End If

                      ' Similarly, D1 seems to be the BendRadius

                      If dispDimension.GetDimension2(0).Name = "D1" Then

                          dispDimension.SetLinkedText "BendRadius"  ' Doesn't work again!

                      End If

                      Set dispDimension = _

                          swFeat.GetNextDisplayDimension(dispDimension)

                  Loop

              End If

              Set swFeat = swFeat.GetNextFeature

          Loop

      End Sub

       

      Thanks for any help,

      Daniel

        • Re: Difficulty linking dimensions from API
          Tapani Sjoman

          Tested with SW2013 and worked fine after writing

           

          ....

          If swFeat.GetTypeName2 = "SheetMetal" Then

          ....

           

          Don't have SW2014 yet so can't say about it.

          • Re: Difficulty linking dimensions from API
            Daniel McRae

            Hi all,

             

            Thanks to Tapani checking it out on his system and my VAR (Intercad, particularly their API expert, Artem) doing some work behind the scenes, I tracked the problem down to the template I was using.

             

            Basically, this template has stuck around for years, including a time when it included a sheet metal feature that had the thickness and radius linked already. This feature was deleted when SW introduced multibody sheet metal parts. It seems that template confused SolidWorks, so that whenever a new sheet metal feature was created, while the SW feature tree would list it as (for example) Sheet-Metal1, the API would identify it as one above this, Sheet-Metal2. This meant that we couldn't add equations programmatically, and also that linking the values didn't work either. Recreating the template from scratch removed the bug, so that using equations to control it worked well, as suggested by Intercad. I'd rather have it linked, but it seems that since I'm using the global variables before the sheet metal is created, it means SolidWorks can't do it.

             

            Regards,

            Daniel

             

            (edited to note that linking still isn't working; oh well)