Need Ilogic external rule to create parameter and event triggers

Need Ilogic external rule to create parameter and event triggers

khantheking1995
Contributor Contributor
147 Views
0 Replies
Message 1 of 1

Need Ilogic external rule to create parameter and event triggers

khantheking1995
Contributor
Contributor

Hi I have two ilogic codes that are mentioned at last. The codes have some lines that will create the below mentioned custom iproperties and user parameters in the inventor assembly.

Custom iproperties

Existing size Weight Kg

Existing part Weight Lbs

Existing Assembly weight(Kg)

New Assembly weight(kg)

User parameters

stockNumberBeamList

WeightKg

LengthM

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) = """" & 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

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 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

 From the above two rules, I want to extract the lines and created anew rule that the below mentioned function. I will run the code first once I save the assembly to setup the inventor environment to use the form i create that basically uses the require below function to work

  • All the custom iproperty and user parameter created using two code should be part of the new rule so when I create new assembly and press that VBA button for the rule it will create the iproperties and parameter created in the assembly.                                       khantheking1995_1-1698564817017.pngkhantheking1995_2-1698564881739.png

     

  • Rule should also contain a code that should add the external rule "ChangeBeam" like in below image
    Location of external Rule - "C:\Users\Public\ilogics"khantheking1995_0-1698564623288.png

    Now, I need another help with part of code in partselect with user parameter "LengthM".

    as per the code the code Length is pulled from somewhere i not sure  where it is from, but I want the weight to be pulled from below location and should be converted to Meter if its in any other unitskhantheking1995_3-1698565177423.png

    @Andrii_Humeniuk 

0 Likes
148 Views
0 Replies
Replies (0)