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, thanks for the reply.
I neglected to mention that I need to change the name of the dimension programatically rather than manually.
I have already renamed the sketch in a previous step of the macro.All that is left is to change the dim name.
myDim.Name = "OD"
Lol, Thanks Josh.
I knew it would be something easy...but wow that was really easy!
I would like to thank: "The acadamy of the obvious" for nominating me for this award......
DisplayDimension dispDimension = //what ever dispDimension obj u have.
IDimension IDim = dispDimension.GetDimension2(0);
double val = (IDim.GetValue3((int)swInConfigurationOpts_e.swThisConfiguration, null)
Thank you Anshul.
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"
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
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