Macro solidworks rename a dimension

Hello community.

 

Still in the development of my macros, I am looking for a way to rename my sidecuts.

Instead of the traditional G-d. @EsquisseX, I would like to have "text of my choice" @nom of the sketch

I can put a prefix or a suffix in the text of the call number but not rename it

 

Below is the code used but which does not work to rename the call number.


Dim myDisplayDim As Object
Set myDisplayDim = swmodel. AddDimension2(-0.15, height / 2, 0)
Dim myDimension As Object
Set myDimension = swmodel. Parameter("H@Esquisse2")
boolstatus = swmodel. EditDimensionProperties2(0, 0, 0, "", "", True, 9, 2, True, 12, 12, "H = ", "", True, "", "", False)

 

Do you have an idea of why and how???

 

Thank you in advance

 

Happydad

Hello

I imagine you recorded a macro to get this result?

Instead, you should use a "For Each" function that will go through all the dimensions of the part, an example (which will retrieve the values of all the dimensions for all the configurations), see this section of the API help:

http://help.solidworks.com/2012/English/api/sldworksapi/Get_Dimension_Values_in_All_Configurations_Example_VB.htm

By adapting this macro, it shouldn't be very difficult to retrieve the name of each rating.

 

Edit: a macro that will probably be even more useful:

http://help.solidworks.com/2012/English/api/sldworksapi/Get_Display_Dimension_Properties_Example_VB.htm

Edit 2: the previous macro is just a piece of code, this one is complete and will be very useful too:

http://help.solidworks.com/2012/English/api/sldworksapi/Iterate_Through_Dimensions_in_Model_Example_VB.htm

 

2 Likes

If you can post the functional macro afterwards so that it can benefit everyone, that would be great!

Thank you!

Thank you for this answer.

 

I didn't use a for each function but when creating my rating I gave it the name I wanted to passge.

 

Below is the modified code that works.

Dim myDisplayDim As Object
Set myDisplayDim = swmodel. AddDimension2(-0.15, height / 2, 0)
Dim myDimension As Object
Set myDimension = swmodel. Parameter("H@Esquisse2")
Set swSelMgr = swmodel. SelectionManager
Set swDispDim = swSelMgr.GetSelectedObject5(1)
Dim swDim As SldWorks.Dimension
Set swDim = swDispDim.GetDimension
Dim nom_cote As String


boolstatus = swmodel. EditDimensionProperties2(0, 0, 0, "", "", True, 9, 2, True, 12, 12, "H = ", "", True, "", "", False)
nom_cote = "H"
swDim.Name = nom_cote

1 Like

Oh indeed, it was during the creation, I hadn't paid attention!