Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey guys,
I am having trouble creating a circular pattern of a part. Below is my code so far. Everything works great until the point marked 'Failure'. I'm having trouble creating an object collection and also calling the AddCircularPattern Method of the OccurencePatterns object.
Sub placeparts() ' Connect to a running instance of Inventor. Dim oApp As Inventor.Application Set oApp = GetObject(, "Inventor.Application") ' Get the Documents collection. Dim docs As Inventor.Documents Set docs = oApp.Documents ' Create a new part document. Dim oProjectMgr As DesignProjectManager Set oProjectMgr = ThisApplication.DesignProjectManager Dim oProject As DesignProject Set oProject = oProjectMgr.ActiveDesignProject Dim oTemplatesPath As String oTemplatesPath = oProject.TemplatesPath Dim oAsmDoc As Inventor.AssemblyDocument Set oAsmDoc = docs.Add(kAssemblyDocumentObject, oTemplatesPath & "Standard (in).iam", True) ' Set a reference to the assembly component definintion. ' This assumes an assembly document is open. Dim oAsmCompDef As AssemblyComponentDefinition Set oAsmCompDef = oAsmDoc.ComponentDefinition ' Set a reference to the transient geometry object. Dim oTG As TransientGeometry Set oTG = ThisApplication.TransientGeometry ' Create a matrix. A new matrix is initialized with an identity matrix. Dim oMatrix(1) As Matrix Set oMatrix(0) = oTG.CreateMatrix Set oMatrix(1) = oTG.CreateMatrix ' Set the translation portion of the matrix so the part will be positioned ' at (3,2,1). Call oMatrix(0).SetTranslation(oTG.CreateVector(3, 2, 1)) Call oMatrix(1).SetTranslation(oTG.CreateVector(9, 6, 3)) ' Add the occurrence. Dim oOcc(1) As ComponentOccurrence Set oOcc(0) = oAsmCompDef.Occurrences.Add("C:\Temp\Part1.ipt", oMatrix(0)) Set oOcc(1) = oAsmCompDef.Occurrences.Add("C:\Temp\Part1.ipt", oMatrix(1)) oOcc(1).Grounded = True
'Failure Dim objCollection As ObjectCollection Set objCollection = objCollection.Add(oOcc(0)) Set objCollection = objCollection.Add(oOcc(1)) Dim oOccPats As OccurrencePatterns Set oOccPats = oAsmCompDef.OccurrencePatterns Dim oOccPat As OccurrencePattern Set oOccPat = oOccPats.AddCircularPattern(objCollection, oAsmCompDef.WorkAxes(2), True, 1, 3) End Sub
Any help with this would be greatly appreciated.
Solved! Go to Solution.