AnsweredAssumed Answered

Change Drawing Document Font Macro (partial) - Help finding variable names/incorporating

Question asked by Patrick Malone on Oct 23, 2017
Latest reply on Oct 24, 2017 by Patrick Malone

I am trying to "write" a macro to change the document settings inside a drawing.

I want to change every occurrence where a FONT is used/specified to SWRomns.

I know "recording" has its limitations and issues but since I'm a novice it is a good starting point for me.

 

The code shown below does a decent job but there are several instances that are not changed.

 

' ******************************************************************************

' Macro1.swb - macro recorded on 10/23/17 by X

' ******************************************************************************

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

Dim myTextFormat As Object

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

myTextFormat.TypeFaceName = "SWRomns"

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

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDetailingBalloonAutoBalloons, 0, swLeaderStyle_e.swSTRAIGHT)

Set myTextFormat = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingAnnotationTextFormat, 0)

myTextFormat.TypeFaceName = "SWRomns"

boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingAnnotationTextFormat, 0, myTextFormat)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDimensionsExtensionLineStyle, swUserPreferenceOption_e.swDetailingRadiusDimension, swLineStyles_e.swLineCONTINUOUS)

boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDimensionsExtensionLineStyleSameAsLeader, swUserPreferenceOption_e.swDetailingRadiusDimension, False)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDimensionsExtensionLineStyleThickness, swUserPreferenceOption_e.swDetailingRadiusDimension, swLineWeights_e.swLW_THIN)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDimensionsExtensionLineStyle, swUserPreferenceOption_e.swDetailingHoleDimension, swLineStyles_e.swLineCONTINUOUS)

boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDimensionsExtensionLineStyleSameAsLeader, swUserPreferenceOption_e.swDetailingHoleDimension, False)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDimensionsExtensionLineStyleThickness, swUserPreferenceOption_e.swDetailingHoleDimension, swLineWeights_e.swLW_THIN)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDimensionsExtensionLineStyle, swUserPreferenceOption_e.swDetailingChamferDimension, swLineStyles_e.swLineCONTINUOUS)

boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDimensionsExtensionLineStyleSameAsLeader, swUserPreferenceOption_e.swDetailingChamferDimension, False)

boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swDimensionsExtensionLineStyleThickness, swUserPreferenceOption_e.swDetailingChamferDimension, swLineWeights_e.swLW_THIN)

Set myTextFormat = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingWeldSymbolTextRootInsideFont, 0)

myTextFormat.TypeFaceName = "SWRomns"

boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingWeldSymbolTextRootInsideFont, 0, myTextFormat)

boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDetailingSectionViewLabels_PerStandard, 0, False)

Set myTextFormat = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionView_RotationTextFormat, 0)

myTextFormat.TypeFaceName = "SWRomns"

boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingSectionView_RotationTextFormat, 0, myTextFormat)

boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDetailingDetailViewLabels_PerStandard, 0, False)

boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDetailingAuxViewLabels_PerStandard, 0, False)

boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDetailingOrthoViewLabels_PerStandard, 0, False)

Set myTextFormat = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingLocationLabelTextFormat, 0)

myTextFormat.TypeFaceName = "SWRomns"

boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingLocationLabelTextFormat, 0, myTextFormat)

Set myTextFormat = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingTableTextFormat, 0)

myTextFormat.TypeFaceName = "SWRomns"

boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingTableTextFormat, 0, myTextFormat)

Set myTextFormat = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingViewTextFormat, 0)

myTextFormat.TypeFaceName = "SWRomns"

boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.swDetailingViewTextFormat, 0, myTextFormat)

boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swDetailingMiscView_PerStandard, 0, False)

End Sub

 

 

The instances that DID NOT CHANGE from my recorded macro (But I need to have change)

are here:  (All are Document Properties inside a DWG)

 

Under Annotations

    Balloons -> Text Font

    Datums -> Text Font

    Geometric Tolerancing -> Text Font

    Notes -> Text Font

    Surface Finishes -> Text Font

    Weld Symbols -> Text Font

Under Dimensions

    Angle -> Text Font

    Anglular Running -> Text Font

    Arc Length -> Text Font

    Chamfer -> Text Font

    Diameter -> Text Font

    Hole Callout -> Text Font

    Linear -> Text Font

    Ordinate -> Text Font

    Radius -> Text Font

 

I found the variable names for the Annotation items that still need to be changed.

 

swDetailingBalloonTextFormat

swDetailingDatumTextFormat

swDetailingGeometricToleranceTextFormat

swDetailingNoteTextFormat

swDetailingSurfaceFinishTextFormat

swDetailingWeldSymbolTextFormat

 

I do not know how to incorporate these into my macro.

I suspect I need to add the following for each variable?

 

boolstatus = Part.Extension.SetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.NAME-GOES-HERE, 0, myTextFormat)

Set myTextFormat = Part.Extension.GetUserPreferenceTextFormat(swUserPreferenceTextFormat_e.NAME-GOES-HERE, 0)

myTextFormat.TypeFaceName = "SWRomns"

 

Is this correct?

 

 

How can I find the variable name for the associated Dimension Items that I also need to add?

 

Under Dimensions

    Angle -> Text Font

    Angular Running -> Text Font

    Arc Length -> Text Font

    Chamfer -> Text Font

    Diameter -> Text Font

    Hole Callout -> Text Font

    Linear -> Text Font

    Ordinate -> Text Font

    Radius -> Text Font

 

I guess this is multi-part question.

Hopefully this is a step up from a "write this for me" type question.

I am a novice and I am using SW 2015 SP5.

Outcomes