Controlling Number of Features in a Circular Pattern - iLogic

Controlling Number of Features in a Circular Pattern - iLogic

Anonymous
Not applicable
1,127 Views
5 Replies
Message 1 of 6

Controlling Number of Features in a Circular Pattern - iLogic

Anonymous
Not applicable

How do you control the number of features in a circular pattern(of a single part) with iLogic?  I can count them but don't know how to change them.  I can change the parameter directly but is there something like oCircularPatternFeature.NumberOfElements?

 

SyntaxEditor Code Snippet

Dim oDoc As PartDocument
Dim oCompDef As PartComponentDefinition
Dim oCircularPatternFeature As CircularPatternFeature
Dim oCircularPatternFeatures As CircularPatternFeatures
Dim dNumberOfBolts As Parameter


'Set the document
oDoc = ThisDoc.Document

'Set the component definition
oCompDef = oDoc.ComponentDefinition

'Set the circular pattern features collection
oCircularPatternFeatures = oCompDef.Features.CircularPatternFeatures

'Show the number of bolts
For Each oCircularPatternFeature In oCircularPatternFeatures

    If oCircularPatternFeature.Name = "BoltPattern" Then
    
        dNumberOfBolts = oCircularPatternFeature.Count
    
        MessageBox.Show("There are now " & dNumberOfBolts.Value & " bolts.", "Test")
        
    
    Else
    End If

Next
0 Likes
1,128 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

In the documentation is looks like you can redefine your pattern with the "CircularPatternFeatures.Add" Method. Use the Count variable.

 

 

CircularPatternFeatures.Add( ParentFeatures As ObjectCollection, AxisEntity As Object, NaturalAxisDirection As Boolean, Count As Variant, Angle As Variant, FitWithinAngle As Boolean, [ComputeType] As PatternComputeTypeEnum ) As CircularPatternFeature

0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks for the reply.  I did previously try that and got an error message that Count is read-only.

 

Also, I am not trying to add a new pattern, just modify an existing.

0 Likes
Message 4 of 6

Anonymous
Not applicable

I understand you just want to modify the existing pattern but I do not think it's that easy.

I think you will need to redefine the pattern with all of the original inputs plus add to the number of features in the pattern with the count parameter in the add method.

 

here is a link to a macro for creating a circular pattern from VBA. Maybe it will help push you in the right direction. It uses the .Add method and changes the count parameter.

http://forums.autodesk.com/t5/inventor-customization/help-with-creating-circularpattern-vba/td-p/363...

0 Likes
Message 5 of 6

Vladimir.Ananyev
Alumni
Alumni

Here is the sample to proof the concept.

It adds the second extrude feature (disk) to the existing circular pattern feature.

Open the attached part file and run the iLogic rule.

 

'this rule adds one more feature 
'to the existing circular pattern Feature

Dim oDoc As PartDocument = ThisDoc.Document
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition

'Feature to be added to the existing pattern
'Should be above the pattern node in the browser!
Dim oPartFeature As PartFeature = oDoc.ComponentDefinition _
		.Features.ExtrudeFeatures.Item("Disk")

'reference to the circular pattern feature
Dim oCPF As CircularPatternFeature = oDef.Features.CircularPatternFeatures.Item(1)

'get the feature collection
Dim objCol As ObjectCollection = oCPF.ParentFeatures
'modify the object collection - add one more extrude feature
Call objCol.Add(oPartFeature)

'apply changes to the pattern
oCPF.ParentFeatures = objCol

oDoc.Update
Beep

 Initial state:

Before.PNG

 

Result:

After.PNG

cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 6 of 6

Dean.kichenbrand
Contributor
Contributor

Thanks this helped me a lot also works for RectangularPatternFeature to swap around ParentFeature

 

Public Sub ChangeElem(oPartDef As PartComponentDefinition, oDoc As Document)

    Dim oPartFeature As PartFeature
    Set oPartFeature = oPartDef.features.HoleFeatures.Item("TRP3_HOLE")

    Dim oRPF As RectangularPatternFeature
    Set oRPF = oPartDef.features.RectangularPatternFeatures.Item("TopPattern")
    
    Dim objCol As ObjectCollection
    Set objCol = oRPF.Definition.ParentFeatures


'I added the clear so I can swap the old ParentFeature with a new one
    Call objCol.Clear
    Call objCol.Add(oPartFeature)
    
    oRPF.Definition.ParentFeatures = objCol
    oRPF.Definition.NaturalXDirection = False
    oDoc.Update

End Sub
0 Likes