VBA code to change sketch's Dimensions

VBA code to change sketch's Dimensions

fujitranthanh
Explorer Explorer
154 Views
1 Reply
Message 1 of 2

VBA code to change sketch's Dimensions

fujitranthanh
Explorer
Explorer

I have a simple code to resize sketch.
But it doesn't work with diameter and radius
Hope everyone can help me
Thanks and regards

Sub test()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oDim As Object
On Error Resume Next
Set selSet = oDoc.SelectSet

Dim constraint As DimensionConstraint

For Each constraint In selSet
'MsgBox constraint.Parameter.Expression
constraint.Parameter.Expression = 100
constraint.Driven = True
constraint.Driven = False
Next

End Sub
0 Likes
155 Views
1 Reply
Reply (1)
Message 2 of 2

Dev_rim
Advocate
Advocate

When you are working with the expressions you have to give a string with unit of measure. For example:

"100 mm"

"15 in"

 

Its only can be edited like this:

 

  If TypeOf constraint Is DimensionConstraint Then
            Dim param As Parameter
            Set param = constraint.Parameter
            
            Select Case constraint.Type
                Case kDiameterDimConstraint, kRadiusDimConstraint
                    param.Expression = "50 mm"
                Case Else
                    ' Set for linear or other types
                    param.Expression = "100 mm"
            End Select
            
            constraint.Driven = True
            constraint.Driven = False
        Else
            MsgBox "Selected item is not a dimension constraint."
        End If
If my answer is solved your problem, please mark it as Solution

Freundliche Grüße / Kind Regards
0 Likes