I need to change the Unit of Mass to "kilograms" in Mass/Section Properties of the Document Properties through my Macro.
How do I do it?
SolidworksApi macros
I need to change the Unit of Mass to "kilograms" in Mass/Section Properties of the Document Properties through my Macro.
How do I do it?
SolidworksApi macros
From SW2009 API help files
IModelDocExtension::GetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, swUserPreferenceOption_e.swDetailingNoOptionSpecified)
IModelDocExtension::SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, swUserPreferenceOption_e.swDetailingNoOptionSpecified, swUnitsMassPropMass_e.<Value>)
See swUnitsMassPropVolume_e for valid options
Thanks Deepak
I used "ModelDocExtension::SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 3)"
This API set the Units for Mass in the Mass/Section Properties to "kilograms".
Can you provide help with the syntax to do this? I'm more familiar with VBA and the VB.NET syntax throws me (I'm not a programmer anyway).
Thanks,
Craig S.
Sorry, but I can't find this swUnnitsMassPropMass as a value in my constants. Can you tell me the value? And also for length and volume?
Regards,
Stefan
Nachricht geändert durch Stefan Lüghausen:Everything is ok. I found a new version of swconst and so I have the needed values.
Craig,
Check attached macro to change Mass/Section Properties (Mass)
This Macro Only Run in SW2011.
I wish thisMacro run in SW2006
At SW2011→Debugger through
swUserPreferenceIntegerValue_e.swUnitSystem, 0,
but SW2006→Not Debugger through
--------------------------------
' Mass_Section Properties (Mass) ---------------------------------06/08/10
' ******************************************************************************
' Macro will change the Mass units for Mass/Section Properties from Grams to Kilograms
' or vice versa
' ------------------------------------------------------------------------------
' Written by: Deepak Gupta (http://gupta9665.wordpress.com/)
' ------------------------------------------------------------------------------
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim Instance As swUnitsMassPropMass_e 'As swUnitsMassPropMass_e
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Debug.Print Instance
' Set the Unit system to Custom
boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitSystem, 0, swUnitSystem_Custom)
' Get/Check Mass/Section Properties - Mass - Unit, if Grams
If (Part.Extension.GetUserPreferenceInteger(swUnitsMassPropMass, 0) = 2) Then
' Change to Kilograms
boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, 3) '
Else
' Else keep or set to Grams
boolstatus = Part.Extension.SetUserPreferenceInteger(swUserPreferenceIntegerValue_e.swUnitsMassPropMass, 0, 2)
End If
End Sub
Check in SW2006 API help files and update the macro with appropriate codes/methods.
Function SetUserUnit(SwModel As ModelDoc2)
With SwModel
.SetUserPreferenceIntegerValue swUnitsMassPropMass, swUnitsMassPropMass_Kilograms
.SetUserPreferenceIntegerValue swUnitsMassPropVolume, swUnitsMassPropVolume_Meters3
.SetUserPreferenceIntegerValue swUnitsMassPropLength, swMETER
.SetUserPreferenceIntegerValue swDetailingArrowStyleForDimensions, swCLOSED_ARROWHEAD
'.SetMaterialPropertyName "Vessel.sldmat", "Q235A"
'.SetMaterialPropertyName "Vessel.sldmat", "Q245R"
'Set Arrow Height
.SetUserPreferenceDoubleValue swDetailingArrowHeight, 1# / 1000
Debug.Print .GetUserPreferenceDoubleValue(swDetailingArrowHeight)
''Set Arror Length
.SetUserPreferenceDoubleValue swDetailingArrowLength, 12 / 1000
'Set Arrow Width
.SetUserPreferenceDoubleValue swDetailingArrowWidth, 5 / 1000
Debug.Print .GetUserPreferenceDoubleValue(swDetailingArrowWidth)
''Set Dim Font Height
.SetUserPreferenceDoubleValue swDetailingDimFontHeight, 3 / 1000
Debug.Print .GetUserPreferenceDoubleValue(swDetailingDimFontHeight)
.SetUserPreferenceDoubleValue swDetailingDimFontHeight, 3 / 1000
''
.ForceRebuild3 True
End With
End Sub
Sub del()
Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2
Set SwApp = Application.SldWorks
Set SwModel = SwApp.ActiveDoc
SwApp.SetUserPreferenceToggle swUseEnglishLanguage, False
SetUserUnit SwModel
Debug.Print SwModel.GetType, SwModel.GetTitle
End Sub
*********************************************************************************************
2010 SolidWorks API Help - Get and Set User Preferences Example (VBA)
http://help.solidworks.com/2010/english/api/sldworksapi/get_and_set_user_preferences_example_vb.htm
result is
Tools > Options > System Options > General > Custom property used as component description: Description
Tools > Options > System Options > View > Reverse mouse wheel zoom direction: True
Tools > Options > System Options > View > Arrow keys: 13.0009575981079
Tools > Options > System Options > View > Mouse speed: 56
Tools > Options > System Options > View > View transition: 2.5
Tools > Options > System Options > View > Hide/show component: .800000011920929
Tools > Options > System Options > View > Isolate: 1.22222220897675
Tools > Options > Document Properties > Drafting Standard > Overall drafting standard is ISO
Tools > Options > Document Properties > Annotations > Balloons > Leader Thickness: 0
Tools > Options > Document Properties > Annotations > Balloons > Custom Leader Thickness: 2.8000000747852E-04
Tools > Options > Document Properties > Annotations > Balloons > Frame Thickness: 0
Tools > Options > Document Properties > Annotations > Balloons > Custom Frame Thickness: 2.8000000747852E-04
Tools > Options > Document Properties > Annotations > Balloons > Text Upper Custom property: Source
Tools > Options > Document Properties > Annotations > Balloons > Single balloon - Style: 2
Tools > Options > Document Properties > Annotations > Balloons > Single balloon - Size: 3
Tools > Options > Document Properties > Annotations > Balloons > Stacked balloons - Style: 2
Tools > Options > Document Properties > Annotations > Balloons > Stacked balloons - Size: 3
Tools > Options > Document Properties > Annotations > Balloons > Auto balloon layout: 5
Tools > Options > Document Properties > Annotations > Balloons > Leader display - Use document leader length: True
Tools > Options > Document Properties > Annotations > Balloons > Layer:
Tools > Options > Document Properties > Annotations > Balloons > Font is italic and bold: True
**********************************************
Function SetUserUnit(SwModel As ModelDoc2)
With SwModel
.SetUserPreferenceIntegerValue swUnitsMassPropMass, swUnitsMassPropMass_Kilograms
.SetUserPreferenceIntegerValue swUnitsMassPropVolume, swUnitsMassPropVolume_Meters3
.SetUserPreferenceIntegerValue swUnitsMassPropLength, swMETER
.SetUserPreferenceIntegerValue swUnitSystem, swUnitSystem_Custom
.SetUserPreferenceIntegerValue swUnitsLinear, swMM
''
.SetUserPreferenceIntegerValue swDetailingArrowStyleForDimensions, swCLOSED_ARROWHEAD
'.SetMaterialPropertyName "Vessel.sldmat", "Q235A"
'.SetMaterialPropertyName "Vessel.sldmat", "Q245R"
'Set Arrow Height
.SetUserPreferenceDoubleValue swDetailingArrowHeight, 1# / 1000
'Debug.Print .GetUserPreferenceDoubleValue(swDetailingArrowHeight)
''Set Arror Length
.SetUserPreferenceDoubleValue swDetailingArrowLength, 12 / 1000
'Set Arrow Width
.SetUserPreferenceDoubleValue swDetailingArrowWidth, 5 / 1000
'Debug.Print .GetUserPreferenceDoubleValue(swDetailingArrowWidth)
''Set Dim Font Height
.SetUserPreferenceDoubleValue swDetailingDimFontHeight, 3 / 1000
'Debug.Print .GetUserPreferenceDoubleValue(swDetailingDimFontHeight)
.SetUserPreferenceDoubleValue swDetailingDimFontHeight, 3 / 1000
''
.SetUserPreferenceDoubleValue swDetailingNoteFontHeight, 3 / 1000
'.ForceRebuild3 True
End With
End Function
**********************************************
2010 SolidWorks API Help - Get Annotations Array Example (VBA)
http://help.solidworks.com/2010/english/api/sldworksapi/get_annotations_array_example_vb.htm