Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to insert a component into an assembly then constrain them using imates already on the component. I am able to insert the components however the imates that are on the component do not appear in the assembly. Here is the code that brings the part into my assembly. Seems like this should be straight forward since its directly from the API manual.
SyntaxEditor Code Snippet
Public Sub Main() ' Get the component definition of the currently open assembly. ' This will fail if an assembly document is not open. Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition ' Create a new matrix object. It will be initialized to an identity matrix. Dim oMatrix As Matrix oMatrix = ThisApplication.TransientGeometry.CreateMatrix ' Place the first occurrence. Dim oOcc1 As ComponentOccurrence oOcc1 = oAsmCompDef.Occurrences.Add("C:\Vault Workspace\Designs\_Part Library\MSC - Miscellaneous\MSC.000001022.ipt", oMatrix) ' Place the second occurrence, but adjust the matrix slightly so they're ' not right on top of each other. oMatrix.Cell(1, 4) = 10 Dim oOcc2 As ComponentOccurrence oOcc2 = oAsmCompDef.Occurrences.Add("C:\Vault Workspace\Designs\_Part Library\MSC - Miscellaneous\MSC.000001022.ipt", oMatrix) ' Look through the iMateDefinitions defined for the first occurrence ' and find the one named "iMate:1". This loop demonstrates using the ' Count and Item properties of the iMateDefinitions object. Dim i As Long Dim oiMateDef1 As iMateDefinition For i = 1 To oOcc1.iMateDefinitions.Count If oOcc1.iMateDefinitions.Item(i).Name = "iMate:1" Then oiMateDef1 = oOcc1.iMateDefinitions.Item(i) Exit For End If Next If oiMateDef1 Is Nothing Then MsgBox ("An iMate definition named ""iMate:1"" does not exist in " & oOcc1.Name) Exit Sub End If ' Look through the iMateDefinitions defined for the second occurrence ' and find the one named "iMate:1". This loop demonstrates using the ' For Each method of iterating through a collection. Dim oiMateDef2 As iMateDefinition Dim bFoundDefinition As Boolean For Each oiMateDef2 In oOcc2.iMateDefinitions If oiMateDef2.Name = "iMate:2" Then bFoundDefinition = True Exit For End If Next If Not bFoundDefinition Then MsgBox ("An iMate definition named ""iMate:2"" does not exist in " & oOcc2.Name) Exit Sub End If ' Create an iMate result using the two definitions. Dim oiMateResult As iMateResult oiMateResult = oAsmCompDef.iMateResults.AddByTwoiMates(oiMateDef1, oiMateDef2) End Sub
Solved! Go to Solution.