Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have two code mentioned below that is used in the form(Image 1), PartSelect button activates Partselect rule and pulls data and the StockNumBeamList drops down trigger an external rule "ChangeBeam" that i need to add manually everytime (image 2) I create a assembly so I need a lines to automating this process so I want lines need to be added to "Partselect" rule that add "ChangeBeam" rule to eventtrigger (as in image 2) If its not already added.
Image 1
Image 2
"Partselect" Rule.
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) = """" & oUOfM.ConvertUnits(oFamily.TableRows(i + 1)(iWeight).Value, oFamily.TableColumns(iWeight).Units, "kg/m") & """" 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 Not oExpList.CustomOrder Then oExpList.CustomOrder = True 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
"ChangeBeam" List
Dim oDoc As AssemblyDocument = ThisDoc.Document Dim oUOfM As UnitsOfMeasure = oDoc.UnitsOfMeasure Dim oCustom As PropertySet = oDoc.PropertySets("Inventor User Defined Properties") Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition Dim dMassN As Double = Round(oDef.MassProperties.Mass, 2) Dim oUsParams As UserParameters = oDef.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, oNewAsm_KG, oStockNumb As Inventor.Property Try : oCustom("Existing Assembly weight(Kg)").Value = dMassN Catch : oCustom.Add(dMassN, "Existing Assembly weight(Kg)") : End Try Try : oNewAsm_KG = oCustom("New Assembly weight(Kg)") Catch : oNewAsm_KG = oCustom.Add("", "New Assembly weight(Kg)") : End Try Try : oExWeigt_KG = oCustom("Existing size Weight Kg") Catch : oExWeigt_KG = oCustom.Add("", "Existing size Weight Kg") : End Try 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) oNewAsm_KG.Value = Round(dMassN - oExWeigt_KG.Value + dKG, 2) End If Next
Solved! Go to Solution.