I would like to inquire about modifying iLogic for calculating sweep length.

I would like to inquire about modifying iLogic for calculating sweep length.

cjfgns1003
Advocate Advocate
238 Views
1 Reply
Message 1 of 2

I would like to inquire about modifying iLogic for calculating sweep length.

cjfgns1003
Advocate
Advocate

iLogic calculates the sketch length of sweep modeling and displays the value in iProperties.
Where should I edit the result to display the first decimal place?

 

Sub main
    Dim oDoc As PartDocument = ThisApplication.ActiveDocument
    Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
	Dim LengthTotal As Double = 0
	Dim oPath As Path
	For Each oSweep As SweepFeature In oDef.Features.SweepFeatures
		oPath = oSweep.Definition.Path
		LengthTotal = LengthTotal + GetLengthOfSweep(oPath)
	Next

    Dim oUParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters
    Dim oExists As Boolean = False
	Dim oParamName As String = "SIZE"
    For Each oUParam As UserParameter In oUParams
    	If oUParam.Name = oParamName Then
			oUParam.Value = LengthTotal
			oExists = True
		End If
    Next

    If oExists = False Then
        oUParams.AddByValue(oParamName, LengthTotal, UnitsTypeEnum.kDefaultDisplayLengthUnits)
    End If
	ParaExport(oDef.Parameters.UserParameters, oParamName, kZeroDecimalPlacePrecision)
    oDoc.Update
End Sub

Private Function GetLengthOfSweep(ByVal oPath As Path) As Double
    Dim TotalLength As Double = 0
    Dim oCurve As Object
	Dim oCurveEval As CurveEvaluator
	Dim MinParam As Double
    Dim MaxParam As Double
    Dim length As Double
    For i As Integer = 1 To oPath.Count
        oCurve = oPath.Item(i).Curve 
        oCurveEval = oCurve.Evaluator
        oCurveEval.GetParamExtents(MinParam, MaxParam)
        oCurveEval.GetLengthAtParam(MinParam, MaxParam, length)
        TotalLength = TotalLength + length
    Next
	Return TotalLength
End Function

Private Sub ParaExport(ByRef oUParas As UserParameters, ByVal oParaName As String, _
						ByVal oDecimalPrecision As CustomPropertyPrecisionEnum)
    For Each oUPara As UserParameter In oUParas
		If oUPara.Name = oParaName Then
            oUPara.ExposedAsProperty = True
			Dim oCPF As CustomPropertyFormat = oUPara.CustomPropertyFormat
			oCPF.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
            oCPF.Precision = oDecimalPrecision
			oUPara.Comment = "스윕길이로 산출함."
            Exit Sub
        End If
    Next
End Sub
0 Likes
Accepted solutions (1)
239 Views
1 Reply
Reply (1)
Message 2 of 2

pcrawley
Advisor
Advisor
Accepted solution

This bit (right at the end of the code) defines the way the value is exported:


For Each oUPara As UserParameter In oUParas If oUPara.Name = oParaName Then oUPara.ExposedAsProperty = True Dim oCPF As CustomPropertyFormat = oUPara.CustomPropertyFormat oCPF.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType oCPF.Precision = oDecimalPrecision oUPara.Comment = "스윕길이로 산출함." Exit Sub End If Next

 If you want to round the exported iProperty, then change the line that reads:

 

oCPF.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType

 

to

 

oCPF.Precision = kOneDecimalPlacePrecision

 

The code should now read:

 

Sub main
    Dim oDoc As PartDocument = ThisApplication.ActiveDocument
    Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
	Dim LengthTotal As Double = 0
	Dim oPath As Path
	For Each oSweep As SweepFeature In oDef.Features.SweepFeatures
		oPath = oSweep.Definition.Path
		LengthTotal = LengthTotal + GetLengthOfSweep(oPath)
	Next

    Dim oUParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters
    Dim oExists As Boolean = False
	Dim oParamName As String = "SIZE"
    For Each oUParam As UserParameter In oUParams
    	If oUParam.Name = oParamName Then
			oUParam.Value = LengthTotal
			oExists = True
		End If
    Next
	
    If oExists = False Then
        oUParams.AddByValue(oParamName, LengthTotal, UnitsTypeEnum.kDefaultDisplayLengthUnits)
    End If
	ParaExport(oDef.Parameters.UserParameters, oParamName, kZeroDecimalPlacePrecision)
    oDoc.Update
End Sub

Private Function GetLengthOfSweep(ByVal oPath As Path) As Double
    Dim TotalLength As Double = 0
    Dim oCurve As Object
	Dim oCurveEval As CurveEvaluator
	Dim MinParam As Double
    Dim MaxParam As Double
    Dim length As Double
    For i As Integer = 1 To oPath.Count
        oCurve = oPath.Item(i).Curve 
        oCurveEval = oCurve.Evaluator
        oCurveEval.GetParamExtents(MinParam, MaxParam)
        oCurveEval.GetLengthAtParam(MinParam, MaxParam, length)
        TotalLength = TotalLength + length
    Next
	Return TotalLength
End Function

Private Sub ParaExport(ByRef oUParas As UserParameters, ByVal oParaName As String, _
						ByVal oDecimalPrecision As CustomPropertyPrecisionEnum)
    For Each oUPara As UserParameter In oUParas
		If oUPara.Name = oParaName Then
                    oUPara.ExposedAsProperty = True
		    Dim oCPF As CustomPropertyFormat = oUPara.CustomPropertyFormat
	            oCPF.PropertyType = CustomPropertyTypeEnum.kNumberPropertyType
                    oCPF.Precision = kOneDecimalPlacePrecision
		    oUPara.Comment = "Calculated Sweep Length"
            Exit Sub
        End If
    Next
End Sub

 

Peter