- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm using Inventor professional 2023, I have a ilogic which does the following function.
It helps me to select a part from an assembly (Its basically a assembly made from content center structural parts), so when i slect a part using the Iloic code 1 it assign weight data and pulls size data from content center and also it create a custom user paramater and assign the list of values available in the size column and mass columns to its respective parameter. then with ilogic code 2 when I select a specific size from dropdown in the form. it will calculate the new weight for the new size. see below images
Form
Created user paramters with dropdown
Ilogic code 1:Partselect
Sub main Dim oInvApp As Inventor.Application = ThisApplication Dim oAsmDoc As AssemblyDocument = oInvApp.ActiveDocument Dim oContentCenter As ContentCenter = oInvApp.ContentCenter Dim oUsParams As UserParameters = oAsmDoc.ComponentDefinition.Parameters.UserParameters Dim oUOfM As UnitsOfMeasure = oAsmDoc.UnitsOfMeasure Dim oCustom As PropertySet = oAsmDoc.PropertySets("Inventor User Defined Properties") Dim oDesignProps As PropertySet = oAsmDoc.PropertySets("Design Tracking Properties") Dim oWeigt_KG, oWeigt_Lbs, oStockNumb As Inventor.Property Try : oWeigt_KG = oCustom("Existing size Weight Kg") Catch : oWeigt_KG = oCustom.Add("", "Existing size Weight Kg") : End Try Try : oWeigt_Lbs = oCustom("Existing Part Weight Lbs") Catch : oWeigt_Lbs = oCustom.Add("", "Existing Part Weight Lbs") : End Try Try : oCustom("CAM-Weight Kg").Value = "" Catch : oCustom.Add("", "CAM-Weight Kg") : End Try Try : oCustom("CAM-Weight Lbs").Value = "" Catch : oCustom.Add("", "CAM-Weight Lbs") : End Try oStockNumb = oDesignProps("Stock Number") oWeigt_KG.Value = "" oWeigt_Lbs.Value = "" oStockNumb.Value = "" Dim oOcc As ComponentOccurrence oOcc = oInvApp.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, _ "Select component...") If oOcc Is Nothing Then Exit Sub Dim oDef As PartComponentDefinition = oOcc.Definition Dim oCCPropSet As PropertySet Try : oCCPropSet = oDef.Document.PropertySets.Item("Content Library Component Properties") Catch : MessageBox.Show("The Part is not a CC part.") : End Try Dim dMass As Double = oOcc.MassProperties.Mass oWeigt_KG.Value = Round(dMass, 2) oWeigt_Lbs.Value = Round(oUOfM.ConvertUnits(dMass, UnitsTypeEnum.kKilogramMassUnits, _ UnitsTypeEnum.kLbMassMassUnits), 2) oStockNumb.Value = oDef.Document.PropertySets("Design Tracking Properties") _ ("Stock Number").Value Dim familyId As Inventor.Property = oCCPropSet.Item("FamilyId") Dim MemberId As String = oCCPropSet.Item("MemberId").Value Dim oFamily As ContentFamily oFamily = oContentCenter.GetContentObject("v3#" & familyId.Value & "#") Dim oContentNode As ContentTreeViewNode = oContentCenter.TreeViewTopNode Dim oLengthM As UserParameter Dim oRow As ContentTableRow = oFamily.TableRows.Item(MemberId) Dim iCount As Integer = oFamily.TableRows.Count - 1 Dim iStockNumb As Integer = GetNumbColomn(oFamily.TableColumns, {"Stock Number" }) If iStockNumb = -1 Then MessageBox.Show("Failed to get column - Stock Number", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If Dim iWeight As Integer = GetNumbColomn(oFamily.TableColumns, {"Specific mass", "Mass","Mass [Kg/mm]"}) If iWeight = -1 Then MessageBox.Show("Failed to get column - Mass", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If Dim sStockNumb(iCount), sWeight(iCount) As String For i As Integer = 0 To iCount sStockNumb(i) = """" & oFamily.TableRows(i + 1)(iStockNumb).Value & """" sWeight(i) = """" & oFamily.TableRows(i + 1)(iWeight).Value & """" Next i Dim oColumn As ContentTableColumn = oFamily.TableColumns("STOCKNUMBER") Call SetParamList(oUsParams, "StockNumbBeamList", sStockNumb) Call SetParamList(oUsParams, "WeightKg", sWeight) Try : oLengthM = oUsParams("LengthM") : Catch oLengthM = oUsParams.AddByValue("LengthM", Nothing, _ UnitsTypeEnum.kMeterLengthUnits) : End Try oLengthM.Value = oDef.Parameters.UserParameters("B_L").Value End Sub Private Function SetParamList(ByVal oUsParams As UserParameters, ByVal sNameParam As String, ByVal sList() As String) Dim oUsParam As UserParameter Try : oUsParam = oUsParams(sNameParam) Catch oUsParam = oUsParams.AddByValue(sNameParam, "", _ UnitsTypeEnum.kTextUnits) End Try Call oUsParam.ExpressionList.ClearAll() oExpList = oUsParam.ExpressionList Call oExpList.SetExpressionList(sList, True, 1) If oExpList.AllowCustomValues Then oExpList.AllowCustomValues = False If oExpList.CustomOrder Then oExpList.CustomOrder = False End Function Private Function GetNumbColomn(ByVal oColomn As ContentTableColumns, ByVal sName() As String) As Integer For i As Integer = 1 To oColomn.Count If sName.Any(Function(name) oColomn(i).DisplayHeading.ToLower().Contains(name.ToLower())) Then Return i End If Next i Return -1 End Function
Ilogic code 2: ChangeBeam
Dim oDoc As AssemblyDocument = ThisDoc.Document Dim oUOfM As UnitsOfMeasure = oDoc.UnitsOfMeasure Dim oCustom As PropertySet = oDoc.PropertySets("Inventor User Defined Properties") Dim oUsParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters Dim oListBeam, oWeightList, oLengthM As UserParameter Try oListBeam = oUsParams("StockNumbBeamList") oWeightList = oUsParams("WeightKg") oLengthM = oUsParams("LengthM") Catch : Exit Sub : End Try If String.IsNullOrEmpty(oListBeam.Value) Then Exit Sub Dim oWeigt_KG, oWeigt_Lbs, oStockNumb As Inventor.Property Try : oWeigt_KG = oCustom("CAM-Weight Kg") Catch : oWeigt_KG = oCustom.Add("", "CAM-Weight Kg") : End Try Try : oWeigt_Lbs = oCustom("CAM-Weight Lbs") Catch : oWeigt_Lbs = oCustom.Add("", "CAM-Weight Lbs") : End Try For i As Integer = 1 To oListBeam.ExpressionList.Count If oListBeam.ExpressionList(i) = oListBeam.Expression Then Dim dLengthM As Double dLengthM = oUOfM.ConvertUnits(oLengthM.Value, kCentimeterLengthUnits, kMeterLengthUnits) Dim sWeight As String = oWeightList.ExpressionList(i) Dim dKG As Double = sWeight.Substring(1, sWeight.Length-2) * dLengthM oWeigt_KG.Value = Round(dKG, 2) oWeigt_Lbs.Value = Round(oUOfM.ConvertUnits(dKG, UnitsTypeEnum.kKilogramMassUnits, _ UnitsTypeEnum.kLbMassMassUnits), 2) End If Next
but I have a problem here , the mass data is reordered in ascending from 1 to 9 but I want to assign the data in the same way as it is in content center so that the mass will be assigned correctly for its respective size.
Image 1 :order in content center
Image 2:order in my dropdown paramter
It reshuffle in increase from 1 to 9 , i want the same order as in content center, kindly help me
Also In the form, I want to add the total weight of assembly also come in the form and also it show show new total weight because of the change of new size . Refer image below
@Andrii_Humeniuk , hope you can help me on this
Solved! Go to Solution.