Populate comboboxes with content center family key columns

Populate comboboxes with content center family key columns

j_chaissonQB25Y
Contributor Contributor
467 Views
6 Replies
Message 1 of 7

Populate comboboxes with content center family key columns

j_chaissonQB25Y
Contributor
Contributor

Good afternoon everyone,

 

is there any one out there that knows how to populate a combobox by pointing to a family’s key column and then the next combobox narrows it down and so on. Essentially the same way content center works with listboxes but with comboboxes. I’m working on a form and would love to be able to drive and pick all my components from one form. 

-Jeremy 

0 Likes
468 Views
6 Replies
Replies (6)
Message 2 of 7

A.Acheson
Mentor
Mentor

Hi @j_chaissonQB25Y 

Could you explain the type of form your using? You might have a better time creating a winform explained here and then populating with the family table data. Do you have the code required for accessing the family data? If so attach here, if not there is some samples on this forum.   Could you attach an approximate sample of what you want to achieve, where your selecting the family information and hopefully someone can point you in the right direction. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 7

j_chaissonQB25Y
Contributor
Contributor

I already have a form created. I’m using Visual Studio. I’m not quite sure how to reference the family keys into each combobox. 

Type: is the family (Heavy Barrel, Long Weld Neck)

Class: (150,300,etc)

Joint: (RF,RTJ)

….and so on, by the time you have selected the options you have narrowed down to correct part to place or replace. 

 

j_chaissonQB25Y_0-1693673831422.jpeg

 

0 Likes
Message 4 of 7

A.Acheson
Mentor
Mentor

Hi @j_chaissonQB25Y 

 

Here is a method to be run in a CC part file that contains a ND column, any ANSI pipe Fitting. The function will return the current size and the sub will get all ND's.

 

	Sub Main
		a = GetND()
		MessageBox.Show(a, "Title")
		GetAllND() 
	End Sub
	
	Function GetND() As String
		Dim doc As PartDocument = ThisDoc.Document
		Dim oCC As ContentCenter = ThisApplication.ContentCenter
		Dim propSet As PropertySet = doc.PropertySets.Item("{B9600981-DEE8-4547-8D7C-E525B3A1727A}")

		'Get FamilyId property.
		Dim familyId As Inventor.Property = propSet.Item("FamilyId")

		'Get Family.
		Dim oContentFamily As ContentFamily = oCC.GetContentObject("v3#" & familyId.Value & "#") 

		' Get MemberId property
		Dim strMemberId As String = propSet("MemberId").Value 

		'Get Current Row
		Dim oCurrentTableRow As ContentTableRow = oCC.GetContentObject("v3#" & familyId.Value & "#" & strMemberId)

		Dim NDCol As ContentTableColumn
		Dim ND As String
		'Set the column criteria. 
		Try
			NDCol = oContentFamily.TableColumns.Item("ND")
			ND = oCurrentTableRow.GetCellValue(NDCol)
		Catch
		End Try
		Return ND
	End Function
	
	
	Sub GetAllND() 
		Dim NDList As New List (Of String)
		Dim doc As PartDocument = ThisDoc.Document
		Dim oCC As ContentCenter = ThisApplication.ContentCenter
		Dim propSet As PropertySet = doc.PropertySets.Item("{B9600981-DEE8-4547-8D7C-E525B3A1727A}")

		'Get FamilyId property.
		Dim familyId As Inventor.Property = propSet.Item("FamilyId")

		'Get Family.
		Dim oContentFamily As ContentFamily = oCC.GetContentObject("v3#" & familyId.Value & "#") 
		'Get Current Row
		For Each oCurrentTableRow As ContentTableRow In oContentFamily.TableRows
				Dim NDCol As ContentTableColumn
				Dim ND As String
				'Set the column criteria. 
				Try
					NDCol = oContentFamily.TableColumns.Item("ND")
					ND = oCurrentTableRow.GetCellValue(NDCol)
					NDList.Add(ND)
				Catch
				End Try
		
		Next
		
		d0 = InputListBox("Prompt", NDList, d0, Title := "Title", ListName := "List")

	End Sub

 

And here is how you would use change a part in the assembly with 3 variable criteria to select a member row. The criteria is all manually input so you will need to ensure your family contains this data.

 

'https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/change-length-of-a-content-center-file-with-ilogic/td-p/9512570

Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oCC As ContentCenter = ThisApplication.ContentCenter
Dim oCCmember As ComponentOccurrence 

'[Select Components
Dim comps As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim comp As Object

'Set a reference to the select set of the active document.
 Dim oSelectSet As SelectSet = ThisApplication.ActiveDocument.SelectSet
 
If oSelectSet.Count = 0 Then ' Check to make sure items were pre selected in browser pane or windowing compoonents.
	'[Selecting Component using Pick.
	While True
		comp = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter,"Select a component to add to the folder, Press Esc when Complete") 	
		
		'If nothing gets selected then we're done.	
		If IsNothing(comp) Then Exit While 
			comps.Add(comp) 
	End While
	']
'Allow the user to select manually occurrences in advance of running the rule.
ElseIf oSelectSet.Count > 0 Then 
	For Each comp In oSelectSet
		If TypeOf comp Is ComponentOccurrence
			comps.Add(comp)
		Else
		End If 
	Next
	
	'[Pause Inventor between selections
	'https://ekinssolutions.com/selecting-multiple-entities-using-pick-in-inventor/
	System.Windows.Forms.Application.DoEvents()
    System.Threading.Thread.Sleep(300)
	System.Windows.Forms.Application.DoEvents()
	']
End If


Dim NDList As String() = {"2", "3", "4", "5", "6" }
Dim ND As String = InputListBox("Choose a ND", NDList, "2", Title := "Change Dia", ListName := "Dia")
If ND = Nothing Then :	MessageBox.Show("Exiting", "Title") : Return :End If

Dim SchList As String() = {"10", "40", "Current"}
Dim Sch As String = InputListBox("Choose a Sch", SchList, "Current", Title := "Change Sch", ListName := "Sch")
If Sch = Nothing Then :	MessageBox.Show("Exiting", "Title") : Return :End If

Dim MatList As String() = {"Steel, Wrought", "Aluminum", "Current" }
Dim Mat As String = InputListBox("Choose a Mat", MatList, "Current", Title := "Change Mat", ListName := "mat")
If Mat = Nothing Then :	MessageBox.Show("Exiting", "Title") : Return :End If
	
For Each comp In comps
	
	 oCCmember = comp 
	 
	Dim propSet As PropertySet = oCCmember.Definition.Document.PropertySets.Item("{B9600981-DEE8-4547-8D7C-E525B3A1727A}")

	'Get FamilyId property.
	Dim familyId As Inventor.Property = propSet.Item("FamilyId")

	'Get Family.
	Dim oContentFamily As ContentFamily = oCC.GetContentObject("v3#" & familyId.Value & "#") 

	' Get MemberId property
	Dim strMemberId As String = propSet("MemberId").Value 

	'Get Current Row
	Dim oCurrentTableRow As ContentTableRow = oCC.GetContentObject("v3#" & familyId.Value & "#" & strMemberId)

	Dim NDCol As ContentTableColumn
	Dim SchCol As ContentTableColumn 
	Dim MatCol As ContentTableColumn 
	Dim oNewMember As String 
	
	Dim ee As MemberManagerErrorsEnum

	'Set the column criteria. 
	Try
		NDCol = oContentFamily.TableColumns.Item("ND")
	Catch
	End Try
	Try
		SchCol = oContentFamily.TableColumns.Item("SN")
		If Sch = "Current" Then
			'Get current schedule or have seperate list.
			Sch = oCurrentTableRow.GetCellValue(SchCol)
		End If
	Catch
	End Try
	Try
		MatCol = oContentFamily.TableColumns.Item("MATERIAL")
		If Mat = "Current" Then
			'Get current schedule or have seperate list.
			Mat = oCurrentTableRow.GetCellValue(MatCol)
		End If
	Catch
	End Try


		'Get Row.
		For Each oContentTableRow As ContentTableRow In oContentFamily.TableRows
			
			If Not SchCol Is Nothing Then
			
				'Set the criteria for row selection
				If oContentTableRow.GetCellValue(NDCol) = ND AndAlso oContentTableRow.GetCellValue(SchCol) = Sch AndAlso oContentTableRow.GetCellValue(MatCol) = Mat Then
					Try
						oNewMember = oContentFamily.CreateMember(oContentTableRow, ee, "Some error occured", , False, )
						oCCmember.Replace(oNewMember, True)
					Catch
						Logger.Info("ERROR")
					End Try
					
					oCCmember.Replace(oNewMember, True)
				End If
			ElseIf SchCol Is Nothing Then
				If oContentTableRow.GetCellValue(NDCol) = ND AndAlso oContentTableRow.GetCellValue(MatCol) = Mat Then
					Try
						oNewMember = oContentFamily.CreateMember(oContentTableRow, ee, "Some error occured", , False, )
						oCCmember.Replace(oNewMember, True)
					Catch
						Logger.Info("ERROR")
					End Try
				
					
				End If
		 	End If
			
		Next


		If  String.IsNullOrEmpty(oNewMember) Then
			MessageBox.Show("No matching row found", "Title")
		End If

		'oDoc.Update
	 oCCmember.Parent.Document.Update
Next
		

 

As for the dynamic component box population you would need to recheck each list and check it is a valid value by checking its value and its row index. Gets fairly messy.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 7

j_chaissonQB25Y
Contributor
Contributor

thank you for this code it will come in handy, but im looking for a method that targets the key column for each combobox and returns a list of options in the combobox. i dont want to hard code the key options because then i need to constantly update my addin. if its referencing the key columns any changes in the CC family will automatically update in the addin.

0 Likes
Message 6 of 7

j_chaissonQB25Y
Contributor
Contributor

also......... your first method that returns the ND size and then every other ND it works great but there is one flaw, how do you get it to only return unique ND's and not duplicates?

0 Likes
Message 7 of 7

A.Acheson
Mentor
Mentor

Hi @j_chaissonQB25Y 

The member name will be unique or if all the other variables you provide are valid then this will indicate what member row to select assuming there is enough tested to make them unique. For removing duplicates from lists you can check stack overflow or similar forums for these methods.

 

I am not certain if there is a key identifier for content center column.

I found this here in the api help.

Maybe you can do a search of the API Help also. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes