9 Replies Latest reply on Jan 3, 2018 2:14 AM by Rob Edwards

    change name of dimension

    Chris Johnson

      Hello,

      Im trying to change the name of a dimension but cant figure out how to get it done..

       

      I have created my dim like this:

       

      Dim myDim As Object

      Set myDim = swModel.AddDimension2(5.96992194749195E-02, 0, -1.94322962720376E-02)

       

       

       

      Now I would like to change its name from"D1@layout" to "OD@layout" how do you do this?

       

       

       

      thanks

      Chris

        • Re: change name of dimension
          Terry Werth

          Chris;

           

          If you are in the model, right click on the dimension and you can change the D1 in the Primary Value ofthe dimension pane on the left side. If you want to change the 'layout', you need to rename your sketch the dimension is tied to.

           

          If you are in drawing; I have not been able to change a dimension's name there.

           

          Terry

          • Re: change name of dimension
            Anshul Pandeys

            DisplayDimension dispDimension = //what ever dispDimension obj u have.

             

            IDimension   IDim        =   dispDimension.GetDimension2(0);

            double       val         =   (IDim.GetValue3((int)swInConfigurationOpts_e.swThisConfiguration, null)

            • Re: change name of dimension
              Rob Edwards

              I know this is an old post but it's the first hit on google for 'change dimension name solidworks api'

               

              I couldn't get Josh's answer to work - has the API changed since this was posted? or am I doing something wrong...?

               

              I found I had to do this

               

              Set swDim = swPart.AddDimension2(0#, 0#, -0.01)

              swDim.GetDimension.Name = "Length"

                • Re: change name of dimension
                  Deepak Gupta

                  You can also select a dimension and then use these lines

                   

                  Option Explicit
                  Sub main()
                      Dim swApp                      As SldWorks.SldWorks
                      Dim swModel                    As SldWorks.ModelDoc2
                      Dim swSelMgr                    As SldWorks.SelectionMgr
                      Dim swDispDim                  As SldWorks.DisplayDimension
                      Dim swDim                      As SldWorks.Dimension
                  
                      Set swApp = Application.SldWorks
                      Set swModel = swApp.ActiveDoc
                      Set swSelMgr = swModel.SelectionManager
                      Set swDispDim = swSelMgr.GetSelectedObject5(1)
                      Set swDim = swDispDim.GetDimension
                     
                      swDim.Name = "TEST123" 'Change name as required here between quotes
                      swModel.ClearSelection2 True
                  
                  End Sub
                  
                    • Re: change name of dimension
                      Rob Edwards

                      Thanks Depak

                       

                      That's really good to know, so for a newly created feature I could use for example

                       

                      Part.Extension.SelectByID2 "D1@Boss-Extrude1", "DIMENSION", 0#, 0#, 0#, True, 0, Nothing, 0

                       

                      prior to your code...

                       

                      I was baffled for a quite while before I read in the help file I had  to enable swDisplayFeatureDimensions.

                      I think your ways a lot less faff than messing about with user preferences....

                       

                           userstate = .Extension.GetUserPreferenceToggle(swDisplayFeatureDimensions, swDetailingNoOptionSpecified)

                           swPart.Extension.SetUserPreferenceToggle swDisplayFeatureDimensions, swDetailingNoOptionSpecified, True

                        

                          Set swDDim = swFeature.GetFirstDisplayDimension

                                swDDim.GetDimension.name = "Depth"

                       

                          Set swDDim = swFeature.GetNextDisplayDimension(swDDim)

                                swDDim.GetDimension.name = "Width"

                                ...

                          swPart.Extension.SetUserPreferenceToggle swDisplayFeatureDimensions, swDetailingNoOptionSpecified, userstate

                      Nice One!