RectangularPatternFeatureDefinition - Can this be used to update an existing (part file) Rect Pattern ?

RectangularPatternFeatureDefinition - Can this be used to update an existing (part file) Rect Pattern ?

nick.seman
Advocate Advocate
123 Views
2 Replies
Message 1 of 3

RectangularPatternFeatureDefinition - Can this be used to update an existing (part file) Rect Pattern ?

nick.seman
Advocate
Advocate

I am attempting to update an existing rectangular pattern, specifically I would like to select a different 2d sketch for "Direction 1"  I have been trying to  use RectangularPatternFeatureDefinition to no avail.  Actually, I cannot get it to update any parameter including the xCount.  If this is not the way to modify an existing Rectangular Pattern - is there one ?

 

Thanks in advance

Nick

0 Likes
124 Views
2 Replies
Replies (2)
Message 2 of 3

jjstr8
Collaborator
Collaborator

You may want to post your code so far. I'm not having any issues changing a rectangular pattern feature definition. A couple things to keep in mind.

  • .XCount is a Parameter, so change it by setting .XCount.Value
  • .XDirectionEntity is an Object. Check the API help for more details. The one they leave out in the description is that you can set it to a Path, which is what I think you're looking for. Search .SketchEntities in your sketch to find the first sketch line or arc, basically anything except a sketch point; CreatePath won't accept a point. Just give it first line or arc, it will automatically connect everything it can.

Links:

RectangularPatternFeatureDefinition.XDirectionEntity Property

Features.CreatePath Method 

0 Likes
Message 3 of 3

mateusz_baczewski
Advocate
Advocate

Hi,

I wrote a test rule that changes the direction/line along which a rectangular pattern is created. Enter the names of your rectangular pattern and sketch. In the sketch, you'll need to find the specific line along which the pattern should be created.

 

 

Sub main
	
	Dim oPartDoc As PartDocument = ThisDoc.Document
	Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
	Dim oFeatures As PartFeatures = oCompDef.Features
	
	Dim oRectangularFlatPattern As RectangularPatternFeature = oFeatures.RectangularPatternFeatures.Item("Your Rectangular name")
	
	Dim sketch As Sketch = oCompDef.Sketches.Item("Your sketch name")
	
	Dim newDirectionPath As Path = oFeatures.CreatePath(sketch.SketchLines.Item(1)) 'you should find sketch line that you intresting
	
	oRectangularFlatPattern.XDirectionEntity = newDirectionPath
	oPartDoc.Update()


End Sub
If you found it helpful, a "Like" would be much appreciated!
If this post solved your problem, please mark it as "Solution.".

0 Likes