Adding (2x) or (4x) on M8 or Ø6.5 dimensions

Hello

Yesterday I created 2 macros to simplify my life in drawing, adding the (2x) or (4x) on a dimension.
It works very well when the rating is bare, i.e. just 95.
On the other hand, when I have an M6 or Ø12 then it replaces my rating with 6 (2x) and 12 (2x), I lose the prefix every time. How to do it, is there a solution? On Creo I put this variable (2x) in the suffix box but it doesn't exist on solidworks.
Thanks in advance

Good luck to you for the transition from Créo to Solidworks. I was complaining a lot after the 1st regretting Sldw ... and now I'm doing the opposite :smiley:

If not, can you share your VBA code so that the experts can help you with more customizations than the general case?

But, like that seen from a distance, I have the impression that you overwrite what is written to replace with the dimension (x2) or the dimension (x4)
To do it right, you should rather tell him to count the number of characters in your dimension, and then add your (x2) or (x4) to the end of your counter

Hello coin37coin

Indeed I overwrite what is written...
But making a macro to count the number of characters and adding my (2x) that I don't master...
Here is my novice macro:
2x.swp (23.5 KB)

For your information, 25 years of creo behind me I started with the 2000i version

Well done for the software change after so much time. This is a whole logic to be questioned!

You can greatly lighten your code
The first 4 lines of boolstatus are just the step-by-step of writing (2x). So you can just keep the last line.
This would give

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized
boolstatus = Part.EditDimensionProperties2(0, 0, 0, "  ", "", False  , 1, 2, True, 12, 12, "  ", " (2x)", True, "  ", "", True  )
Part.ClearSelection2 True
End Sub

And then I dry out a little bit.
Your Part.EditDimensionProperties2 code recalls the parameters of the dimension you saved your dimension to.
So you would have to find how to save your current settings and remind them when you add (2x) ... or how to simply modify the 13th parameter of your function

EditDimensionProperties2 Method (IModelDoc2) - 2012 - SOLIDWORKS API Help

For all the holes made with the assistance if side with symbol for the drilling the quantity is put by itself without macro.

2 Likes

Hello sbadenis
Thank you for the answer
Yes I know this solution but I don't like it and moreover it is not ISO.

1 Like

Here, after looking a little on the net, a solution that should work
I allowed myself to " pimp" her a little. When you click on the macro it will ask you how many times you want to repeat and it adds at the end with the (x)

Sub QteRepetition()

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Sun swSelMgr As SldWorks.SelectionMgr
Dim swDispDim As SldWorks.DisplayDimension
Dim swDim As SldWorks.Dimension

Dim SuffixCurrent As String
Dim NeoSuffix As String

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

Set swSelMgr = swModel.SelectionManager
Set swDispDim = swSelMgr.GetSelectedObject6(1, 0)
Set swDim = swDispDim.GetDimension

'Implements the current suffix
SuffixCurrent = swDispDim.GetText(swDimensionTextSuffix)
'Text to be filled in
NeoSuffix = InputBox(" Number of Repetition ")
NeoSuffix = " (" & NeoSuffix & " x) "
'changes the dimension suffix
swDispDim.SetText swDimensionTextSuffix, NeoSuffix
'assigns the suffix to the selected dimension'
swDispDim.SetText, swDimensionTextSuffix, SuffixCurrent & NeoSuffix

swModel.GraphicsRedraw2
End Sub

If you don't want the question box, just replace

NeoSuffix = InputBox("Number of Repetition")
NeoSuffix = " (" & NeoSuffix & "x)"

by

NeoSuffix = " (2x) "

2 Likes

Thank you coin37coin
But I have a mistake here
NeoSuffix = InputBox("Number of Repetition")
NeoSuffix = " (" & NeoSuffix & "x)"

Can you help me?

Hello @_Cricri

The error comes from the French quotation marks that must be replaced by the English quotation marks"

2 Likes

The error is on the " " around x I think.

When copying, there was a change in format, so you have to have

NeoSuffix = " (" & NeoSuffix & " x) "

Let's see if it solves the problem?

1 Like

Yes, and they need to be replaced throughout the macro :wink:

2 Likes

Yes it's good it works, great THANK YOU to coin37coin and to Sylk at the end