Place one custom member of each content center family into iam

Place one custom member of each content center family into iam

Anonymous
Not applicable
659 Views
3 Replies
Message 1 of 4

Place one custom member of each content center family into iam

Anonymous
Not applicable

I am doing a lot of Content Center customizations to adapt to company standards.


I need one custom member of each family to do customization on the content center family templates. It is a little time-consuming to do this manually on so many parts… Therefore I am looking for an ilogic rule that creates one custom part of each of my custom families in e.g. Fasteners-folder.


One approach could be to run an ilogic rule from an iam that places one custom member of each family into the iam. I have found a starting point on this page… but it is not quite what I am after as you have to type the exact name of the family - I want one of each for every family in the Folder.

 

Hope someone already has a solution on this or could help outSmiley Happy


https://forums.autodesk.com/t5/inventor-customization/ilogic-to-trigger-and-insert-custom-content-ce...

 

Sub Main()
PlaceContentCenterPart()
End Sub

Sub PlaceContentCenterPart()

' Set a reference to the active assembly document.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

' Set a reference to the ContentCenter object.
Dim oContentCenter As ContentCenter
oContentCenter = ThisApplication.ContentCenter

' Get the content node (category) "Fasteners:Bolts:Hex Head"
Dim oContentNode As ContentTreeViewNode
oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item("Fasteners").ChildNodes.Item("Bolts").ChildNodes.Item("Hex Head")

' Get the "ISO 4015" Family object.
Dim oFamily As ContentFamily
For Each oFamily In oContentNode.Families
If oFamily.DisplayName = "ISO 4015" Then
Exit For
End If
Next

' Create a member based on the first row of the family.
Dim Error1 As MemberManagerErrorsEnum
Dim strContentPartFileName As String
Dim strErrorMessage As String
strContentPartFileName = oFamily.CreateMember(1, Error1, strErrorMessage)

' Dim oMat As Matrix
' oMat = ThisApplication.TransientGeometry.CreateMatrix

' Insert an instance of the content center member in the assembly.
'Call oDoc.ComponentDefinition.Occurrences.Add(strContentPartFileName, oMat)
' Set a reference to the transient geometry object.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

' Create a matrix.
Dim oMatrix As Matrix
oMatrix = oTG.CreateMatrix

'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence

'place an instance of the component
'in this case at 0,0,0
'positioned at the co-ordinates
oMatrix.SetTranslation(oTG.CreateVector(0, 0, 0))

oOccurrence = oAsmCompDef.Occurrences.Add(strContentPartFileName, oMatrix)
oOccurrence.Grounded = False
End Sub

 

0 Likes
660 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

I was able to get a step closer... But two steps missing:

1. I want the content center parts to be placed as custom parts - with saved path same as iam

2. I want the rule to locate all the "child-nodes" in the Fasteners-category (no need to specify Bolts, Studs, etc)

 

Sub Main()
PlaceContentCenterPart()
End Sub
Sub PlaceContentCenterPart()
    ' Set a reference to the active assembly document.
    Dim oDoc As AssemblyDocument
    oDoc = ThisApplication.ActiveDocument
    ' Set a reference to the ContentCenter object.
    Dim oContentCenter As ContentCenter
    oContentCenter = ThisApplication.ContentCenter

    ' Get the content node (category)
    Dim oContentNode As ContentTreeViewNode
   oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item("Fasteners").ChildNodes.Item("Bolts").ChildNodes.Item("Studs")
    ' Get the "ISO 4015" Family object.
    Dim oFamily As ContentFamily
   oX = 5 
   oY = 5
    For Each oFamily In oContentNode.Families
   oX = oX + 10
   oY = oY + 10

  '        'If oFamily.DisplayName = "ISO 4015" Then
  '  If oFamily.DisplayName = "ISO 4015" Then
  '            Exit For
  '        End If
  '    Next
      ' Create a member based on the first row of the family.
      Dim Error1 As MemberManagerErrorsEnum
      Dim strContentPartFileName As String
      Dim strErrorMessage As String
      strContentPartFileName = oFamily.CreateMember(1, Error1, strErrorMessage)
     ' Dim oMat As Matrix
     ' oMat = ThisApplication.TransientGeometry.CreateMatrix
      ' Insert an instance of the content center member in the assembly.
      'Call oDoc.ComponentDefinition.Occurrences.Add(strContentPartFileName, oMat)
      ' Set a reference to the transient geometry object.
      Dim oAsmCompDef As AssemblyComponentDefinition
  oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
  Dim oTG As TransientGeometry
  oTG = ThisApplication.TransientGeometry
     
  ' Create a matrix. 
  Dim oMatrix As Matrix
  oMatrix = oTG.CreateMatrix
  'Iterate through all of the occurrences
  Dim oOccurrence As ComponentOccurrence
  'place an instance of the component
  'in this case at 0,0,0
  'positioned at the co-ordinates

  oMatrix.SetTranslation(oTG.CreateVector(oX, oY, 0))
  oOccurrence = oAsmCompDef.Occurrences.Add(strContentPartFileName, oMatrix)
  oOccurrence.Grounded = False
    Next
End Sub
0 Likes
Message 3 of 4

Anonymous
Not applicable

Hope that some can give me some pointers on how to proceed with this rule? Would appreciate it a lotSmiley Happy

0 Likes
Message 4 of 4

Anonymous
Not applicable

Hi!

I have got very little response to my post here... but I try once moreSmiley Happy

This rule almost works... only one issue: 

All parts are placed correctly with spacing delta-x direction starting from 0,0,0

BUT for each family I am not able to set delta-z.

As it works now parts for each families are placed on top of each other.

 

 

 


Sub Main
        Dim oContentCenter As ContentCenter
           oContentCenter = ThisApplication.ContentCenter

        Dim oContentNode As ContentTreeViewNode
		'Uncomment Level:
		'oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item("Fasteners")
		oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item("Fasteners").ChildNodes.Item("Nuts")
        'oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item("Fasteners").ChildNodes.Item("Washers").ChildNodes.Item("Plain")
        LoopGetFromTreeView(oContentNode)
    End Sub

Private Sub LoopGetFromTreeView(oContentTreeViewNode As ContentTreeViewNode)
	
        Dim oContentTreeViewNodeLoop As ContentTreeViewNode
        Dim strPath As String
        strPath = oContentTreeViewNode.FullTreeViewPath
        Dim strFam As String
        strFam = oContentTreeViewNode.DisplayName
        Dim strExport As String
        strExport = oContentTreeViewNode.DisplayName
        Dim oContentFamily As ContentFamily
   
   
   ' INPUT - CC Category Browser Tree Level:
	 	'LEVEL 1 (Fasteners, "_Metal valves and fittings BSP"	
		    CCTopNode = "Fasteners"
		'LEVEL 2 (Washers, Valves BSP, Pins, Rivets
			CCChildNode1 = "Washers"
		'LEVEL 3 (Plain, Spring
			CCChildNode2 = "Plain"

        oX = 0
        oY = 0
        oZ = 0 

            ' Set a reference to the active assembly document.
		    Dim oDoc As AssemblyDocument
		    oDoc = ThisApplication.ActiveDocument
		    Dim fileName As String = String.Empty
		    Dim CustomPartDirectory= ThisDoc.Path & "\"
		    Dim isCustom As Boolean = m_customInfo IsNot Nothing
		    Dim refresh As Inventor.ContentMemberRefreshEnum = ContentMemberRefreshEnum.kUseDefaultRefreshSetting

		    ' Set a reference to the ContentCenter object.
		    Dim oContentCenter As ContentCenter
		    oContentCenter = ThisApplication.ContentCenter


		    ' Get the content node (category)
'		    Dim oContentNode As ContentTreeViewNode
'		       'oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item("Fasteners").ChildNodes.Item("Washers").ChildNodes.Item("Plain")
		    oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item(CCTopNode).ChildNodes.Item(CCChildNode1)'.ChildNodes.Item(CCChildNode2)
		    
'		    If node Is Nothing Then node = oContentCenter.TreeViewTopNode.ChildNodes.Item(CCTopNode).ChildNodes.Item(CCChildNode1)
		
    
        For Each oContentFamily In oContentTreeViewNode.Families
        ' Set spacing for each member
			oX = oX + 5
			
		'MessageBox.Show(oContentFamily.DisplayName, "Title")
			
   			' Create a member based on the first row of the family.
			                Dim Error1 As MemberManagerErrorsEnum
			                Dim strContentPartFileName As String
			                Dim values As NameValueMap
			                values = ThisApplication.TransientObjects.CreateNameValueMap
			                Dim strErrorMessage As String
			                fileName = IO.Path.Combine(CustomPartDirectory, MakeValidFileName(oContentFamily.DisplayName + "-1" + ".ipt"))
			                strContentPartFileName = oContentFamily.CreateMember(1, Error1, strErrorMessage,refresh,isCustom,fileName ,values)

			                Dim oAsmCompDef As AssemblyComponentDefinition
			                oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
			                Dim oTG As TransientGeometry
			                oTG = ThisApplication.TransientGeometry
			                    
			                ' Create a matrix.  
			                Dim oMatrix As Matrix
			                oMatrix = oTG.CreateMatrix

			                'Iterate through all of the occurrences
			                Dim oOccurrence As ComponentOccurrence

			                'place an instance of the component 
			                oMatrix.SetTranslation(oTG.CreateVector(oX, oY, oZ)) 

			                oOccurrence = oAsmCompDef.Occurrences.Add(strContentPartFileName, oMatrix) 
			                oOccurrence.Grounded = False

   			MessageBox.Show(oContentFamily.DisplayName, "Title")

        Next

	        For Each oContentTreeViewNodeLoop In oContentTreeViewNode.ChildNodes
	   		' Set spacing for each Category-level
				oZ = oZ + 20
MessageBox.Show(oZ, "Title")

'				oY = oY+20
'				MessageBox.Show("New Category", "Title")
		            LoopGetFromTreeView(oContentTreeViewNodeLoop)
'				oZ = oZ + 20
	        Next
 End Sub


Public Shared Function MakeValidFileName(ByVal fileName As String) As String
        Dim invalidChars As Char() = New Char() {"/"c, "\"c, ":"c, "<"c, ">"c, """"c}
        If (fileName.IndexOfAny(invalidChars) < 0) Then
            Return fileName
        End If
        For Each ch As Char In invalidChars
            fileName = fileName.Replace(ch, "_"c)
        Next
        Return fileName
 End Function






0 Likes