×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Change a value of a selected dimension and rebuild

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.

RE: Change a value of a selected dimension and rebuild

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

 

-handleman, CSWP (The new, easy test)

RE: Change a value of a selected dimension and rebuild

(OP)
It is a part file and I'm trying to change a dimension of a dimension that I selected that was a sketch dimension.

RE: Change a value of a selected dimension and rebuild

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)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources