Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Change a value of a selected dimension and rebuild

Status
Not open for further replies.

CycloneWade

Automotive
Apr 1, 2005
76
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.
 
Replies continue below

Recommended for you

What is the context of what you are trying to do? Part? drawing? assembly? Sketch?



-handleman, CSWP (The new, easy test)
 
It is a part file and I'm trying to change a dimension of a dimension that I selected that was a sketch dimension.
 
Code:
Option Explicit
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)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor