Need a Rule for changing component priority to Part priority

Need a Rule for changing component priority to Part priority

khantheking1995
Contributor Contributor
1,417 Views
11 Replies
Message 1 of 12

Need a Rule for changing component priority to Part priority

khantheking1995
Contributor
Contributor

I want a Ilogic rule, I will add the rule to a form

that when run, will allow me to select a part in the assembly(The assembly is created by Frame generator in Inventor 2023).

12345.jpg

If you see above image part select is a rule that allow me to select/pick a part from assembly

1. I will  click partselect in Form, the rule will run and allow me to select a part

2. The selected part/ipt details should come in the exisitng size data group.

Details/Data Required

A)  Size - Size data is available in Frame member Inkhantheking1995_0-1691395104592.png

Size data can also be taken from content center

khantheking1995_1-1691395248449.png

B) TOTAL WEIGHT IN LBS AND KGS FOR THE PART SELECTED

THIS DATA IS AVAILABLE BY KEEPING IN PART PRIORITY AND RIGHT CLICK, SELECT IPROPERTY OR VAULT ICONNECT PROPERTY

 

khantheking1995_2-1691395522119.png

khantheking1995_3-1691395552166.png

Now under exisitng size group, different Label are available

khantheking1995_5-1691396004515.png

 

I want Size Data to filled in size (under existing size date)

Total Weight in Lbs and Kgs in TOTA WEIGHT (Lbs) AND TOTA WEIGHT (Kgs) Label (under existing size date)

 

Kindly help me to create a rule and form setup for the above requirements

In form also, Im facing a problem, I can add weight of Assembly from Iproperties tab in Forms but I need weight of the selected part to be displayed in Forms in the Label mentioned above.

khantheking1995_4-1691395901191.png

 

@Andrii_Humeniuk 

@JDMather 

@Curtis_Waguespack 

@mcgyvr 

@Cadmanto 

@jtylerbc 

 

0 Likes
Replies (11)
Message 2 of 12

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @khantheking1995 . This rule should be the radio button of your component. Also, check that I've written your custom properties correctly (lines 10-13).

 

Sub main
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oAsmDoc As AssemblyDocument = oInvApp.ActiveDocument
	
	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("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
	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
    If oDef.IsContentMember Then
		MessageBox.Show("this sample works with the custom CC member only")
        Exit Sub
    End If
	
	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
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 12

khantheking1995
Contributor
Contributor

Thanks,

You really cracked it so easily, I'm trying this for almost a week

But there is minor bug in the existing code

 

Both the weights are coming in Kg, once should be Lbs, I tried to correct the code but no success

Hope you can help me on that.

khantheking1995_0-1691504655790.png

 

 

Now I want to develop the form a little more on the replaced Size Data

 

For the Replace size, I want a dropdown that shows all the available size option from content center in that respective Family and standard.

khantheking1995_1-1691504655795.png

 

The data for dropdown is available in content center as shown in below image.

khantheking1995_2-1691504655808.png

 

 

Once I select the part, the Ilogic rule must perform a calculation as below.

Calculation

  1. LENGTH = EXISITNGWEIGHT_LBS / EXISTINGWEIGHT_MASSPERLENGTH

LENGTH should be in ft (Even if it is in other units, it should be converted to ft)

EXISITNGWEIGHT_LBS = CAM-WEIGHT Lbs (you made custom Iproperty for this earlier program, only the bug need to be fixed)

EXISTINGWEIGHT_MASSPERLENGTH should be in Lbs/ft. The data is available in content center, Even if it is in other units, it should be converted to ft. (Explain in later part of the explanation on how to identify this data)

  1. REPLACEDWEIGHT_LBS = REPLACEDWEIGHT_MASSPERLENGTH * (LENGTH / 12 ul )

REPLACEDWEIGHT_LBS should be in Lbs(Even if it is in other units, it should be converted to ft)

REPLACEDWEIGHT_MASSPERLENGTH should be in Lbs/ft. The data is available in content center, even if it is in other units, it should be converted to ft. (Explain in later part of the explanation on how to identify this data)

 

 

 

 For the above calculation, I have created all the above mentioned as user parameter as in below Image. But If it easy for you, you can create the rule with all the parameter shown as custom Iproperty too, whichever is convenient for you.

khantheking1995_3-1691504655815.png

 

 

 

In the replaced size data group, I need rule for below application

  1. Existing Size and Weight in Lbs and Kg correctly will be filled as per your previously provided code once you gave me an update on that
  2. I have created a list of parameters in the inventor which need to be filled by a rule as follow below. 
  3. A) EXISITNGWEIGHT_LBS = CAM-WEIGHT Lbs
  4. B) EXISTINGWEIGHT_KG = CAM-WEIGHT Kgs

The above two parameter can be filled by the data that you got using the rule you provided.

 

khantheking1995_4-1691504655823.png

 

 

  1. C) LENGTH is a calculation that require EXISTINGWEIGHT_MASSPERLENGTH and EXISITNGWEIGHT_LBS

 

EXISTINGWEIGHT_MASSPERLENGTH should be in Lbs/ft (Even if it is in other units, it should be converted to ft)

The EXISTINGWEIGHT_MASSPERLENGTH can be get from Content center data as specific mass of the particular stock size of Existing size.

khantheking1995_5-1691504655835.png

 

But If you look at the unit it is in Kg/m, but its value should be converted to Lbs/ft.

The specific mass is available in other unit also like Kg/mm, Pounds/ft, Lbs/ft etc so rule should identify the unit of that column and should convert the specific mass to Lbs/ft. Below are some sample example of other units.

 

  1. D) REPLACEDWEIGHT_MASSPERLENGTH is required to calculate REPLACEDWEIGHT_LBS.

     This can be got similar to how we got REPLACEDWEIGHT_LBS.

 

Again, I created this as user parameter but if you feel there is any other better way, you can make it that way

 

Thanks for the help in Advance

 

khantheking1995_6-1691504655842.png

 

 

khantheking1995_7-1691504655850.png

 

 

 

0 Likes
Message 4 of 12

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @khantheking1995 . To automatically update the weight of a new profile, you need to have 2 rules:
Rule 1 (SelectPart):

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 oOccDoc As PartDocument = oDef.Document
	Dim oCCPropSet As PropertySet
	Try : oCCPropSet = oOccDoc.PropertySets.Item("Content Library Component Properties")
	Catch : End Try
    If oCCPropSet Is Nothing Then
		MessageBox.Show("The Part is not a CC part.")
        Exit Sub
    End If
	
	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 oListBeam, oWeightList, oLengthM As UserParameter
	Dim oRow As ContentTableRow = oFamily.TableRows.Item(MemberId)
	Dim iCount As Integer = oFamily.TableRows.Count-1
	Dim sStockNumb(iCount), sWeight(iCount) As String
	For i As Integer = 0 To iCount
		sStockNumb(i) = oFamily.TableRows(i + 1).Item(1).Value
		sWeight(i) = oFamily.TableRows(i + 1).Item(10).Value
	Next i
	Dim oColumn As ContentTableColumn = oFamily.TableColumns("STOCKNUMBER")
	Try 
		oListBeam = oUsParams("StockNumbBeamList")
	Catch
		oListBeam = oUsParams.AddByValue("StockNumbBeamList", "", _
										UnitsTypeEnum.kTextUnits)
	End Try
	oListBeam.Value = ""
	oListBeam.ExpressionList.ClearAll()
	Try
		oWeightList = oUsParams("WeightKg")
	Catch
		oWeightList = oUsParams.AddByValue("WeightKg", Nothing, _
										UnitsTypeEnum.kKilogramMassUnits)
	End Try
	oWeightList.ExpressionList.ClearAll()
	Try : oLengthM = oUsParams("LengthM") : Catch
	oLengthM = oUsParams.AddByValue("LengthM", Nothing, _
										UnitsTypeEnum.kMeterLengthUnits) : End Try
	MultiValue.List("StockNumbBeamList") = sStockNumb
	oWeightList.ExpressionList.ClearAll()
	MultiValue.List("WeightKg") = sWeight	
	oLengthM.Value = oDef.Parameters.UserParameters("B_L").Value
End Sub

Rule 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 dKG As Double = oWeightList.ExpressionList(i) * dLengthM
		oWeigt_KG.Value = Round(dKG, 2)
		oWeigt_Lbs.Value = Round(oUOfM.ConvertUnits(dKG, UnitsTypeEnum.kKilogramMassUnits, _
												UnitsTypeEnum.kLbMassMassUnits), 2)
	End If
Next

The second rule must be added to the trigger:
TriggerRule.png

My form settings:

SetForm.png

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 5 of 12

khantheking1995
Contributor
Contributor

Hi @Andrii_Humeniuk 

Thanks for the solution 

I have few bugs in the solution as explained below, hope you can help me with that

 

It works well for the square tubes

khantheking1995_0-1693382934304.png

 

 

but when I checked it with round bars I got error as below.

The replaced size dropdown pull up some random numbers(Round bar).

khantheking1995_1-1693382934319.png

 

 

I checked what that numbers are, so it the weight data, so instead of stcok numbers from table , it pulled weight data

khantheking1995_2-1693382934325.png

 

khantheking1995_3-1693382934333.png

 

 

Also I checked with other profile( T profile) to test it with same size but instead of showing same weight it shows differently I don’t know why,

 

khantheking1995_4-1693382934346.png

 

 

 

 can you see how to overcome these bugs, to make the tool more accurate in weight calculation

0 Likes
Message 6 of 12

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @khantheking1995 . In lines 50 and 51 of rule 1, you need to write down all possible variants of "Stock Number" and "Mass".
Rule 1:

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" })
	Dim iWeight As Integer = GetNumbColomn(oFamily.TableColumns, {"Specific mass", "Mass"})
	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.Contains(oColomn(i).DisplayHeading) Then Return i
	Next i
	Return 0
End Function

Rule 2:

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

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 7 of 12

khantheking1995
Contributor
Contributor

Receiving error as below

 

khantheking1995_0-1694532449227.jpegkhantheking1995_1-1694532454794.jpeg

@Andrii_Humeniuk 

0 Likes
Message 8 of 12

khantheking1995
Contributor
Contributor

@Andrii_Humeniuk 

Any update on how to resolve the bugs from last code?

0 Likes
Message 9 of 12

khantheking1995
Contributor
Contributor

I have deleted all parameter from my parameter tab and run the rule Partselect but received error as in second image.

khantheking1995_0-1695137817055.pngkhantheking1995_1-1695137834130.png

 

0 Likes
Message 10 of 12

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @khantheking1995 . You got an error on line 55 (old rule), which means you can't get the table column you want. It is necessary to check the correctness of the column name in lines 50 and 53 (new rule). I also added a check that will help you navigate where you can't get a column.

ColomnName.png

 

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
	Dim iWeight As Integer = GetNumbColomn(oFamily.TableColumns, {"Specific mass", "Mass"})
	If iWeight = -1 Then MessageBox.Show("Failed to get column - Mass", "Error!", _
											MessageBoxButtons.OK, MessageBoxIcon.Error) : Exit Sub
	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.Contains(oColomn(i).DisplayHeading) Then Return i
	Next i
	Return -1
End Function

 

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 11 of 12

khantheking1995
Contributor
Contributor

HI @Andrii_Humeniuk 

Now I have resolved the issue to get the mass columns for all type for shapes by modifying the code as below.

 

Old code

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

 

 
Private Function GetNumbColomn(ByVal oColomn As ContentTableColumns,
ByVal sName() As String) As Integer
For i As Integer = 1 To oColomn.Count
If sName.Contains(oColomn(i).DisplayHeading) Then Return i
Next i
Return -1
End Function
 
I have replaced it with following 

 

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

 

 

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

 

 

Now it is pulling all type of mass data from all table but the weight calculation is coming wrongly as in below image, can you help to resolve it.(the issue is there from old code too)

khantheking1995_0-1696313311945.png

Kindly give me a solution to calculate correct weight for replaced size

0 Likes
Message 12 of 12

khantheking1995
Contributor
Contributor

@Andrii_Humeniuk 

Any update on the above query?

0 Likes