Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a simple SW2017 hole tolerance change macro

Status
Not open for further replies.

SUEDE

Mechanical
Sep 9, 2004
5
0
0
US
I am looking for a *.swp file that I can add to my SolidWorks 2017 toolbar that allows me to change the tolerance of a selected hole(s) dimension.

A dowel hole will default to a three place decimal when dimensioned with the "hole callout".

I would like to highlight the dimension, hit a macro button and change to:

• "limit" style
• +.0000/-.0005
• 4 place inch
• duel dimension
• 3 place mm

(please see attachment)

Does anyone have the VBA skills to provide such an invaluable macro?
 
 https://files.engineering.com/getfile.aspx?folder=f9f9bae4-0b36-4b89-801d-435cbed748dc&file=tolerance_macro.pdf
Replies continue below

Recommended for you

Any particular reason you don't want to do this with a Style? Granted, it does take 2 clicks instead of 1, which may be reason enough if you have to do it incredibly frequently....

 
You can also highlight several dimensions and change style at once.

"For every expert there is an equal and opposite expert"
Arthur C. Clarke Profiles of the future

 
Good question. I could do that too, but I would need a macro to autoload the style when I make a new drawing (they will not allow me to modify the drawing template here). Otherwise I need to load the style each time I make a drawing…and I make a lot of drawings.

So, is there a .swp code to autoload the style?
 
Frankly, they can't stop you from modifying the drawing template.... If you can save any file, you can save a template. If you save a copy of your "approved" template somewhere else, nobody can tell if you used theirs or yours to start a drawing.

Plus, unless this style is special and unique to you, everyone in the organization would benefit from adding this style (and probably others) to the template.



 
There may be reasons beyond what's obvious to us here why the OP can't alter the company template. Technically it's simple, but then there are "the rules"...
The OP can try making a personal copy to add the style, but may have to proceed cautiously afterward, depending on the consequences of changing the template at his/her organization. Furthermore, the OP runs the risk of producing drawings with an old template, if suddenly those authorized to do so suddenly change the approved template, while Suede continues to use their obsolete personal copy.

Suede,
They don't have a specific macro for your problem, but may offer some inspiring ideas:
STF
 
Try this:

Dim swApp As Object
Dim Part As SldWorks.DrawingDoc
Dim boolstatus As Boolean
Dim longstatus As Long
Dim swDispDim As SldWorks.DisplayDimension

Sub main()
Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.EditDimensionProperties(swTolType_e.swTolLIMIT, 0, -0.0000127, "", "", False, 4, swDimensionArrowsSide_e.swDimArrowsSmart, True, swArrowStyle_e.swSLASH_ARROWHEAD, swArrowStyle_e.swSLASH_ARROWHEAD, "", "", True, "", "", "", True, swThisConfiguration, "")

Set swDispDim = Part.SelectionManager.GetSelectedObject6(1, 0)
Call swDispDim.SetDual2(False, False)
longstatus = swDispDim.SetUnits2(False, swLengthUnit_e.swINCHES, swFractionDisplay_e.swDECIMAL, 0, False, swUnitsDecimalRounding_e.swUnitsDecimalRounding_Truncate)
longstatus = swDispDim.SetPrecision3(4, 3, 4, 3)
End Sub
 
Status
Not open for further replies.
Back
Top