Circular pattern of parts in assembly

Circular pattern of parts in assembly

rcolon9E4ZX
Advocate Advocate
931 Views
3 Replies
Message 1 of 4

Circular pattern of parts in assembly

rcolon9E4ZX
Advocate
Advocate

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.

0 Likes
Accepted solutions (1)
932 Views
3 Replies
Replies (3)
Message 2 of 4

MechMachineMan
Advisor
Advisor
Accepted solution

Try this:

 

Dim objCollection As ObjectCollection

Set objCollection = oApp.TransientObjects.CreateObjectCollection
Call
objCollection.Add(oOcc(0))
Call objCollection.Add(oOcc(1))

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 4

MechMachineMan
Advisor
Advisor

Bugged browser... Response was duplicated here.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 4 of 4

rcolon9E4ZX
Advocate
Advocate

I got it to work.

 

Dim oSelectedOccs1 As ObjectCollection
    Set oSelectedOccs1 = ThisApplication.TransientObjects.CreateObjectCollection
    oSelectedOccs1.Add oOcc(1)
    Dim oSelectedOccs2 As ObjectCollection
    Set oSelectedOccs2 = ThisApplication.TransientObjects.CreateObjectCollection
    oSelectedOccs2.Add oOcc(2)
    
    Dim oOccPats As OccurrencePatterns
    Set oOccPats = oAsmCompDef.OccurrencePatterns
    
    Dim oOccPat As OccurrencePattern
    Set oOccPat = oOccPats.AddCircularPattern(oSelectedOccs1, oAsmCompDef.WorkAxes(2), True, 8 * Atn(1) / 12, 12)
    Set oOccPat = oOccPats.AddCircularPattern(oSelectedOccs2, oAsmCompDef.WorkAxes(2), True, 8 * Atn(1) / 10, 10)

Added two parts in the "North" position of the circle with different radii. This code puts the occurences in different object collections and patterns them around.

0 Likes