- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I'n new to Ilogic but seeing the possibilities through it.
I have a rule (blatantly borrowed off the internet) for calculating the length of a sweep. I've created a template with the code imbedded with it.
When I create the part from the part menu (File, new, part), the rule runs as expected, however when I create the part through within an assembly(open assembly, then "file, create in-place component"), when the rule runs it gives me an error "
It's very frustrating as the rule runs as it should otherwise, it's only when creating the part within an assembly! Any ideas? I'd appreciate any help. Thanks
The ilogic is below, however I'm not convinced its the code itself as it runs perfectly as a standalone part.
Sub main
'Set a reference to the active part document
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition
Dim LengthTotal As Double
LengthTotal = 0
'add length of all sweeps
Dim oSweep As SweepFeature
For Each oSweep In oDef.Features.SweepFeatures
Dim oPath As Path
oPath = oSweep.path
LengthTotal = LengthTotal + GetLengthOfSweep(oPath)
Next oSweep
Dim oparams As Parameters
Dim oparam As Parameter
oparams = oDoc.ComponentDefinition.Parameters
Dim exists As Boolean
exists = False
'Find out if parameter exists
Dim paraName As String
paraName = "Length"
For Each oparam In oparams
If oparam.Name = paraName Then exists = True
Next oparam
'Change the value if the parameter exists otherwise add the parameter
If exists Then
oparams.Item(paraName).Value = LengthTotal
Else
oparams.UserParameters.AddByValue(paraName, LengthTotal, 11266)
End If
Call ParaExport(oDef.Parameters, paraName, kZeroDecimalPlacePrecision)
oDoc.Update
End Sub
'get length of a sweep
Private Function GetLengthOfSweep(ByVal oPath As Path) As Double
Dim TotalLength 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
Return TotalLength*1.2
End Function
'exporting the parameter, optional
Private Sub ParaExport(ByRef oParas As Parameters, _
ByVal oParaName As String, _
ByVal oDecimalPrecision As CustomPropertyPrecisionEnum)
Dim oPara As Parameter
For Each oPara In oParas
If String.Compare(oPara.name, oParaName) = 0 Then
If Not oPara.ExposedAsProperty = True Then oPara.ExposedAsProperty = True
If Not oPara.CustomPropertyFormat.ShowUnitsString = False Then _
oPara.CustomPropertyFormat.ShowUnitsString = False
If Not oPara.CustomPropertyFormat.ShowLeadingZeros = True Then _
oPara.CustomPropertyFormat.ShowLeadingZeros = True
If Not oPara.CustomPropertyFormat.ShowTrailingZeros = False Then _
oPara.CustomPropertyFormat.ShowTrailingZeros = False
If Not oPara.CustomPropertyFormat.Precision = oDecimalPrecision Then _
oPara.CustomPropertyFormat.Precision = oDecimalPrecision
Dim oComment As String
oComment = "Is determined by by iLogic-rule: 'SweepLength'"
If Not oPara.Comment = oComment Then oPara.Comment = oComment
Exit Sub
End If
Next oPara
End Sub
Solved! Go to Solution.