Community
Original post: http://beinginventive.typepad.com/being-inventive/2011/09/loop-length-of-a-sweep-as-custom-parameter...
Modified Code:
'Set a reference to the strings Dim propertyName7 As String = InputBox("Enter Sweep Name", "Calculate Sweep Length", "Fill in sweep name (case sensitive) see in feature tree") Dim propertyName8 As String = InputRadioBox("What are the Units?", "mm", "in", False, "Pick the Units") If propertyName8 = True Then propertyName8 = " mm" Else propertyName8 = " in" End If '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 opath = oDef.Features.SweepFeatures.Item(propertyName7).Path 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 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 If exists Then oparams.Item("Sweeplength").Value = TotalLength Else oparams.UserParameters.AddByValue( "Sweeplength", TotalLength, 11266) End If oDoc.Update MessageBox.Show(Parameter("Sweeplength")& (propertyName8), "Total Sweep Length")
you can now input which sweeps you have.
If somebody can help me somehow to be able to select multiple sweeps that would be great!
im also going to try to have the code detect the units, and automatically convert it into mm or inches depending the user input.
Thanks!
Max
Added The Change units parameters, still need to sync first question with the rest. 😕
'furom link: http://forums.autodesk.com/t5/Inventor-General/Improved-the-Measure-Sweep-Code/td-p/4782187 'Set a reference to the strings Dim propertyName7 As String = InputBox("Enter Sweep Name", "Calculate Sweep Length", "Fill in sweep name (case sensitive) see in feature tree") Dim propertyName8 As String = InputRadioBox("What are the Units?", "mm", "in", False, "Pick the Units") If propertyName8 = True Then propertyName8 = " mm" Else propertyName8 = " in" End If '------- start of change units ------ question = MessageBox.Show("Are you sure you want to change the units of measure?", _ "iLogic",MessageBoxButtons.YesNo) If question = vbNo Then Return Else 'get input from user oUnit = InputRadioBox("Select a units of measure type", "Metric", "Imperial", True, "ilogic") 'create precision value list oPrecisionArray = New String(){0, 1, 2, 3, 4, 5} 'get input from user oPrecision = InputListBox("Select the number of decimal places to use for the units of length display.", _ oPrecisionArray, 3, "iLogic", "Decimal Places ") 'example UnitsTypeEnum Enumerators 'kCentimeterLengthUnits = 11268 'kMillimeterLengthUnits = 11269 'kInchLengthUnits = 11272 'kKilogramMassUnits = 11283 'kGramMassUnits = 11284 'kLbMassMassUnits = 11286 If oUnit = True Then 'set to millimeter oUOM_1 = 11269 'set to kilogram oUOM_2 = 11283 Else 'set to inch oUOM_1 = 11272 'set to pounds mass oUOM_2 = 11286 End If 'Define the open document Dim openDoc As Document openDoc = ThisDoc.Document 'set length units for the top level assembly openDoc.unitsofmeasure.LengthUnits = oUOM_1 'set mass units for the top level assembly openDoc.unitsofmeasure.MassUnits = oUOM_2 'set precision openDoc.unitsofmeasure.LengthDisplayPrecision = oPrecision 'Look at all of the files referenced in the open document Dim docFile As Document For Each docFile In openDoc.AllReferencedDocuments 'format file name Dim FNamePos As Long FNamePos = InStrRev(docFile.FullFileName, "\", -1) Dim docFName As String docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos) 'set length units docFile.unitsofmeasure.LengthUnits = oUOM_1 'set mass units docFile.unitsofmeasure.MassUnits = oUOM_2 'set precision docFile.unitsofmeasure.LengthDisplayPrecision = oPrecision 'rebuild to update the display docFile.Rebuild Next End If 'update all iLogicVb.UpdateWhenDone = True '------- end of change units ------ '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 opath = oDef.Features.SweepFeatures.Item(propertyName7).Path 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 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 If exists Then oparams.Item("Sweeplength").Value = TotalLength Else oparams.UserParameters.AddByValue( "Sweeplength", TotalLength, 11266) End If oDoc.Update MessageBox.Show(Parameter("Sweeplength")& (propertyName8), "Total Sweep Length")
Let me know what you guys think 🙂