VBA Rectangular Pattern regardless from the Workaxis

VBA Rectangular Pattern regardless from the Workaxis

Anonymous
Not applicable
863 Views
2 Replies
Message 1 of 3

VBA Rectangular Pattern regardless from the Workaxis

Anonymous
Not applicable

Dear big programming world!

I tried a RectangularPattern via VBA. I got it going in an assembly. But it only works with the work axes. Is there a way to let the pattern run along a unit vector or the like? How do I create a Rectangular Pattern in a Part and in an Assembly? How can I set a direction regardless of the work axes? Please help me. Thank you

 

 

' Set a reference to the active assembly document

Dim oDoc As AssemblyDocument

Set oDoc = ThisApplication.ActiveDocument

' Set a reference to the AssemblyComponentDefinition

Dim oDef As AssemblyComponentDefinition

Set oDef = oDoc.ComponentDefinition

' Get the x\-axis of the assembly

Dim oXAxis As WorkAxis

Set oXAxis = oDef.WorkAxes.Item(1)

' Get the y\-axis of the assembly

Dim oYAxis As WorkAxis

Set oYAxis = oDef.WorkAxes.Item(2)

Dim oParentOccs As ObjectCollection

Set oParentOccs = ThisApplication.TransientObjects.CreateObjectCollection

oParentOccs.Add oDef.Occurrences.Item(1)

' Create a rectangular pattern of components\:

' 4 columns in the x\-direction with an offset of 5 in

' 3 rows in the y\-direction with an offset of 4 in

Dim oRectOccPattern As RectangularOccurrencePattern

Set oRectOccPattern = oDef.OccurrencePatterns.AddRectangularPattern( _

oParentOccs, oXAxis, True, "5 in", 4, oYAxis, True, "4 in", 3)

End Sub

0 Likes
Accepted solutions (2)
864 Views
2 Replies
Replies (2)
Message 2 of 3

JaneFan
Autodesk
Autodesk
Accepted solution

Hey @Anonymous , 

I guess you are saying two things: 

In assembly: it is occurrence pattern: OccurrencePatterns.AddRectangularPattern()

In AddRectangularPattern method, we can provide direction which need be proxy object that defines the direction of the pattern. This must be a proxy to a linear edge or a work axis.

 

In part: it is rectangular pattern feature: 

Features.RectangularPatternFeatures.AddByDefinition()
Features.RectangularPatternFeatures.CreateDefinition()
In CreateDefinition method, we can provide X and Y directions, which can be linear entity like a linear Edge, a WorkAxis, a WorkPlane (normal is used), a planar Face (normal is used), or a GeometryIntent

 




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 3 of 3

Anonymous
Not applicable
Accepted solution
 

Hey Jane!

 

Thank you for your hint. I tried it and now I can also create patterns in a part.
Only I still don't understand how to use an edge of the body instead of an axis. I think I'll explain that in more detail in another post.

 

This is my code:

 
Sub RPF()

    Dim oPCD As PartComponentDefinition
    Set oPCD = ThisApplication.ActiveDocument.ComponentDefinition
    
    Dim oXAxis As WorkAxis
    Set oXAxis = oPCD.WorkAxes.Item(1)
    
    Dim oOC As ObjectCollection
    Set oOC = ThisApplication.TransientObjects.CreateObjectCollection
    Call oOC.Add(oPCD.Features.Item(1))
    
    Dim oRPFD As RectangularPatternFeatureDefinition
    Set oRPFD = oPCD.Features.RectangularPatternFeatures.CreateDefinition(oOC, oXAxis, True, 3, 10)
    
    Dim oRPF As RectangularPatternFeature
    Set oRPF = oPCD.Features.RectangularPatternFeatures.AddByDefinition(oRPFD)

End Sub

 

0 Likes