0 Replies Latest reply on Oct 26, 2015 5:23 PM by Eric Bunn

    Cavity Feature Scaling

    Eric Bunn

      I pulled this code out of SW API help and want to find out how it could be converted to do a non uniform scale instead of a uniform scale.  I've modified it slightly to suit my application and it works.  I would ultimately like to scale each axis differently. 

       

      Please reference this code near the end.  This is where I want to specify x y and z values:

              Debug.Print ("New scale uniformly value: " & swCavityFeatureData.UseUniformScale)

              swCavityFeatureData.UniformScale = 1.04

       

      Thanks in advance for the help.

       

       

      Sub ScaleCavity()

       

       

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim swModelDocExt As SldWorks.ModelDocExtension

          Dim swSelectionMgr As SldWorks.SelectionMgr

          Dim swFeature As SldWorks.Feature

          Dim swCavityFeatureData As SldWorks.CavityFeatureData

          Dim boolstatus As Boolean

          Dim xScale As Double

          Dim yScale As Double

          Dim zScale As Double

         

         

          Set swApp = CreateObject("SldWorks.Application.23")    

          swApp.Visible = True                                

          swApp.UserControl = True

         

          Set swModel = swApp.OpenDoc6("C:\DDPD\CAP Folder\Rhino Templates\Mold Body T.sldprt", swDocPART, 0, "", longstatus, longwarnings)          

          Set swModelDocExt = swModel.Extension

         

      'Select the Cavity1 feature and get and set its properties

       

       

          'boolstatus = swModel.Extension.SelectByID2("Mold Body T-1@Rhino Template - Top Bottom Config TB Mold", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

          swModel.ClearSelection2 True

          boolstatus = swModel.Extension.SelectByID2("Cavity1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)

       

       

          Set swSelectionMgr = swModel.SelectionManager

          Set swFeature = swSelectionMgr.GetSelectedObject6(1, -1)  

          Set swCavityFeatureData = swFeature.GetDefinition       

         

             

              boolstatus = swCavityFeatureData.AccessSelections(swModel, Nothing)

              Debug.Print ("Scale type: " & swCavityFeatureData.ScaleType) 

              Debug.Print ("Scale uniformly value: " & swCavityFeatureData.UseUniformScale)

              swCavityFeatureData.GetScale xScale, yScale, zScale

             

              Debug.Print ("Scale values:")

              Debug.Print ("  X: " & xScale)

              Debug.Print ("  Y: " & yScale)

              Debug.Print ("  Z: " & zScale)

             

              Debug.Print ("Value by which to scale this cavity feature in all directions: " & swCavityFeatureData.UniformScale)

              Debug.Print ("")

             

              swCavityFeatureData.UseUniformScale = True

             

              Debug.Print ("New scale uniformly value: " & swCavityFeatureData.UseUniformScale)

              swCavityFeatureData.UniformScale = 1.04

             

              Debug.Print ("New value by which to scale this cavity feature in all directions: " & swCavityFeatureData.UniformScale)

              boolstatus = swFeature.ModifyDefinition(swCavityFeatureData, swModel, Nothing)