Change a value of a selected dimension and rebuild
Change a value of a selected dimension and rebuild
(OP)
This seems really trival but I'm trying to change the value of a dimension that has been selected and rebuild the part.
Here is snap shot of the code where I prompt the user to select a dimension. In the code I can retrieve the current value, but no I'm struggling with changing that value, then rebuilding the part.
************************************************
swApp.SendMsgToUser2 "Please select a dimension.", swMbWarning, swMbOk
While SelMgr.GetSelectedObjectType3(1, 0) <> swSelDIMENSIONS
Model.ClearSelection2 True 'Clear all selections
While SelMgr.GetSelectedObjectCount < MINSELECTIONS
DoEvents 'Wait for user selection
Wend
If SelMgr.GetSelectedObjectType3(1, 0) = swSelDIMENSIONS Then
Set MyDim = SelMgr.GetSelectedObject6(1, 0)
End If
Wend
MyDimValue = MyDim.GetDimension2(0).Value
Change dimension value here and rebuild part...
***********
Thanks.
Here is snap shot of the code where I prompt the user to select a dimension. In the code I can retrieve the current value, but no I'm struggling with changing that value, then rebuilding the part.
************************************************
swApp.SendMsgToUser2 "Please select a dimension.", swMbWarning, swMbOk
While SelMgr.GetSelectedObjectType3(1, 0) <> swSelDIMENSIONS
Model.ClearSelection2 True 'Clear all selections
While SelMgr.GetSelectedObjectCount < MINSELECTIONS
DoEvents 'Wait for user selection
Wend
If SelMgr.GetSelectedObjectType3(1, 0) = swSelDIMENSIONS Then
Set MyDim = SelMgr.GetSelectedObject6(1, 0)
End If
Wend
MyDimValue = MyDim.GetDimension2(0).Value
Change dimension value here and rebuild part...
***********
Thanks.






RE: Change a value of a selected dimension and rebuild
-handleman, CSWP (The new, easy test)
RE: Change a value of a selected dimension and rebuild
RE: Change a value of a selected dimension and rebuild
CODE
Const MINSELECTIONS As Long = 1
Dim swApp As SldWorks.SldWorks
Dim Model As SldWorks.ModelDoc2
Dim myDispDim As SldWorks.DisplayDimension
Dim myDim As SldWorks.Dimension
Dim SelMgr As SldWorks.SelectionMgr
Dim myDimValue As Variant
Dim NewVal As Double
Sub main()
Set swApp = Application.SldWorks
Set Model = swApp.ActiveDoc
Set SelMgr = Model.SelectionManager
If Not ((SelMgr.GetSelectedObjectCount2(-1) = 1) And (SelMgr.GetSelectedObjectType3(1, -1) = swSelDIMENSIONS)) Then
swApp.SendMsgToUser2 "Please select a dimension.", swMbWarning, swMbOk
Model.ClearSelection2 True
End If
While SelMgr.GetSelectedObjectType3(1, -1) <> swSelDIMENSIONS
Model.ClearSelection2 True 'Clear all selections
While SelMgr.GetSelectedObjectCount < MINSELECTIONS
DoEvents 'Wait for user selection
Wend
Wend
Set myDispDim = SelMgr.GetSelectedObject6(1, -1)
Set myDim = myDispDim.GetDimension2(0)
myDimValue = myDim.GetValue3(swThisConfiguration, Empty)
NewVal = CDbl(InputBox("Enter new value", "Change Dimension", myDimValue(0)))
myDim.SetValue3 NewVal, swThisConfiguration, Empty
Model.EditRebuild3
End Sub
-handleman, CSWP (The new, easy test)