Message 1 of 13
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Found a pretty slick rule for returning the length of a sweep which I'm using to me collect lengths for hoses and tubes however I'm having trouble with handling an error in a try-catch block and was wondering what the right way to handle the error where a sweep is not named Hose Sweep or Tube Sweep as right now it errors out if either of those names aren't found. Secondly the parameter Sweeplength that it creates, I can't get it to round to 2 decimal places?
'Set a reference to the active part document
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition
Dim opath As Path
Try :
opath = oDef.Features.SweepFeatures.Item("Hose Sweep").Path
Catch :
opath = oDef.Features.SweepFeatures.Item("Tube Sweep").Path
Catch :
MsgBox("To get the length of your hose or tube the sweep feature needs to be named explicitly as Hose Sweep or Tube Sweep")
Exit Sub
End Try
Dim TotalLength As Double
Dim roundLength As Double
TotalLength = 0
Dim oCurve As Object
Dim i As Integer
For i = 1 To opath.Count
oCurve = opath.Item(i).Curve
Dim oCurveEval As CurveEvaluator
oCurveEval = oCurve.Evaluator
Dim MinParam As Double
Dim MaxParam As Double
Dim length As Double
Call oCurveEval.GetParamExtents(MinParam, MaxParam)
Call oCurveEval.GetLengthAtParam(MinParam, MaxParam, length)
TotalLength = TotalLength + length
Next i
roundLength = Round(TotalLength, 2)
Dim oparams As Parameters
Dim oparam As Parameter
oparams = oDoc.ComponentDefinition.Parameters
Dim exists As Boolean
exists = False
'Find out if parameter exists
For Each oparam In oparams
If oparam.Name = "Sweeplength" Then exists = True
Next oparam
'Change the value if the parameter exists otherwise add the parameter
'MsgBox(roundLength & " " & TotalLength)
If exists Then
oparams.Item("Sweeplength").Value = roundLength
Else
oparams.UserParameters.AddByValue("Sweeplength", roundLength, 11266)
End If
oDoc.Update
Solved! Go to Solution.