Thursday, May 10, 2012

Working With Unconstrained Imported Assembly Components




Issue:
You've found a great 3D model on the web that you want to use in Inventor. It was originally created in some other 3D design software, but you were able to import it into Inventor. The problem is that the parts come in unconstrained and can move all over the place. Is there an option to import models from other software and keep the assembly constraints?

Solution:
There is no option to import the assembly constraints, but most likely you won't need to apply constraints to all of the parts because they have been imported in the correct orientation and location. Instead you can just ground all of the parts in place so that they will not move, and then un-ground and apply assembly constraints to just the parts that need to move or that you need to edit.

If the assembly has a lot of moving parts that need assembly constraints, you can un-ground and constrain one part at a time to keep everything from moving on you.

Here is a quick iLogic rule that will ground all components in place also.

'start of ilogic code
' get the active assembly
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'set the Master LOD active
Dim oLODRep As LevelofDetailRepresentation
oLODRep = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master")
oLODRep.Activate

 'Iterate through all of the occurrences and ground them.
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
'check for and skip virtual components
If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
oOccurrence.Grounded = True
else
end if
Next
' end of ilogic code


Update (July, 22, 2014): 
Here is an updated version of this rule that grounds everything found in the first 3 assembly levels.


'start of ilogic code
 'get user input
 qGround = InputRadioBox("Select one:", "Ground", "Un-Ground", True, "ilogic")
'get the active assembly
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'set the Master LOD active
Dim oLODRep As LevelofDetailRepresentation
oLODRep = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master")
oLODRep.Activate

'Iterate through all of the top level occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
                        If oOccurrence.DefinitionDocumentType = _
                        DocumentTypeEnum.kAssemblyDocumentObject Then
                             'Iterate through all of the 2nd level occurrences
                                    Dim oSub1Occ As ComponentOccurrence
                                    For Each oSub1Occ In oOccurrence.SubOccurrences
                                    'ground everything in the 2nd level   
                                    oSub1Occ.Grounded = qGround
                                                If oSub1Occ.DefinitionDocumentType = _
                                                DocumentTypeEnum.kAssemblyDocumentObject Then
                                                  'Iterate through all of the 3nd level occurrences
                                                Dim oSub2Occ As ComponentOccurrence
                                                For Each oSub2Occ In oSub1Occ.SubOccurrences
                                                'ground everything in the 3rd level    
                                                oSub2Occ.Grounded = qGround
                                                Next
                                      Else
                                      End If
                             Next
                   Else
                   End If
          'ground everything in the top level    
            oOccurrence.Grounded = qGround
Next  
' end of ilogic code