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
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
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)
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
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