A pattern along a body edge using VBA

A pattern along a body edge using VBA

Anonymous
Not applicable
511 Views
2 Replies
Message 1 of 3

A pattern along a body edge using VBA

Anonymous
Not applicable

Hi,

In the code attached below, the pattern follows an axis.
I would like to have the pattern run along one edge of the body
How does it work? Is that possible? Does anyone have a code snippet for me? I am thankful for every hint. Please share your knowledge with me. Thank you very much.

 

ThisEdge.png

 

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
Accepted solutions (1)
512 Views
2 Replies
Replies (2)
Message 2 of 3

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

Hi, I show you an example below. First I define the feature of which you want to make the pattern.
In the case of the example this feature generates a solid body, so I take an edge of this generated solid body (In my example I have highlighted in red the number of edge I need)
Then I modify your code to get the result I need.

 

 

Sub RPF()

    Dim oPCD As PartComponentDefinition
    Set oPCD = ThisApplication.ActiveDocument.ComponentDefinition
    
    Dim oFeature As PartFeature
    Set oFeature = oPCD.Features.Item(1)
    
    Dim oEdge As Edge
    Set oEdge = oFeature.SurfaceBodies(1).Edges(2)
    
    Dim oOC As ObjectCollection
    Set oOC = ThisApplication.TransientObjects.CreateObjectCollection
    Call oOC.Add(oFeature)
    
    Dim oRPFD As RectangularPatternFeatureDefinition
    Set oRPFD = oPCD.Features.RectangularPatternFeatures.CreateDefinition(oOC, oEdge, True, 3, 10)
    
    Dim oRPF As RectangularPatternFeature
    Set oRPF = oPCD.Features.RectangularPatternFeatures.AddByDefinition(oRPFD)

End Sub

I hope some of this can be useful. regards

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 3

Anonymous
Not applicable

Hi Sergio!

Thank you for the code example. It works very well. Didn't think the code could be that simple and short. I find it remarkable that "Edges" can be attached directly to "SurfaceBodies". I don't know if I would have figured it out myself. I think I still have to learn a lot about BRep. Thanks again for your example. It helps me a lot.

0 Likes