Wednesday, 25 October 2017

Macro program to change font of dimension , note, section view text, and diameter / radius value in SolidWorks Macro.

This program/code will help to manage the all font in same size with one click in solidWorks drawing. you can make a command tool in drawing by this macro.
This program will cover-

  1.  Dimension font size
  2. Section view font size
  3. Diameter text location - horizontal
  4. Note font size
  5. Size of detail font size
  6. Save file after done all changes
In this program, font size is 8. you can change it as per requirement. 



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

'dimension font size

Dim myTextFormat As Object
Set myTextFormat = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDimensionTextFormat, swUserPreferenceOption_e.swDetailingDimension)


myTextFormat.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDimensionTextFormat, swUserPreferenceOption_e.swDetailingDimension, myTextFormat)



'section font size

Dim myTextFormat1 As Object
Set myTextFormat1 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionTextFormat, 0)
myTextFormat1.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionTextFormat, 0, myTextFormat1)
Set myTextFormat1 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelNameTextFormat, 0)
myTextFormat1.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelNameTextFormat, 0, myTextFormat)
Set myTextFormat1 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelLabelTextFormat, 0)
myTextFormat1.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelLabelTextFormat, 0, myTextFormat)
Set myTextFormat1 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelScaleTextFormat, 0)
myTextFormat1.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelScaleTextFormat, 0, myTextFormat)
Set myTextFormat1 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelDelimiterTextFormat, 0)
myTextFormat1.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionLabelDelimiterTextFormat, 0, myTextFormat)
Set myTextFormat1 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionView_RotationTextFormat, 0)
myTextFormat1.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionView_RotationTextFormat, 0, myTextFormat)



'diameter text location
boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDetailingDimensionTextAndLeaderStyle, swUserPreferenceOption_e.swDetailingDiameterDimension, swDisplayDimensionLeaderText_e.swBrokenLeaderHorizontalText)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDetailingDimensionTextAndLeaderStyle, swUserPreferenceOption_e.swDetailingRadiusDimension, swDisplayDimensionLeaderText_e.swBrokenLeaderHorizontalText)

'note font size



Dim myTextFormat2 As Object
Set myTextFormat2 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingNoteTextFormat, 0)
myTextFormat2.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingNoteTextFormat, 0, myTextFormat2)

'SIZE OF DETAILS
Dim myTextFormat3 As Object
Set myTextFormat3 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailTextFormat, 0)
myTextFormat3.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailTextFormat, 0, myTextFormat)

Dim myTextFormat4 As Object
Set myTextFormat4 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_NameTextFormat, 0)
myTextFormat4.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_NameTextFormat, 0, myTextFormat)
Set myTextFormat4 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_LabelTextFormat, 0)
myTextFormat4.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_LabelTextFormat, 0, myTextFormat)
Set myTextFormat4 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_ScaleTextFormat, 0)
myTextFormat4.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_ScaleTextFormat, 0, myTextFormat)
Set myTextFormat4 = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_DelimiterTextFormat, 0)
myTextFormat4.CharHeightInPts = 8
boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingDetailView_DelimiterTextFormat, 0, myTextFormat)


'save file

Dim swErrors As Long
Dim swWarnings As Long
boolstatus = Part.Save3(1, swErrors, swWarnings)

End Sub




Download Macro- Click Here

No comments:

Post a Comment