Sketch Rectangular Pattern API – Parameter updates and dimension control issues
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
First of all, thank you for exposing the Sketch Rectangular Pattern methods through the API. This is very useful functionality.
However, while testing the API implementation I encountered several issues that make it difficult to use sketch patterns reliably in automated workflows.
- No clean way to control pattern spacing with a dimension
Currently there is no straightforward way to add a dimension that drives the pattern spacing.
It would be very useful if the pattern definition allowed creating a dimension directly, for example something like:
Boolean CreateOffsetDimWithExpression
on the pattern definition.
This would allow a dimension in the sketch to control the pattern pitch directly.
- Pattern parameters are not updating the geometry
When creating a sketch pattern through the API:
- The pattern is initially created correctly.
- The parameters appear in the parameter table, showing the value or expression that was assigned.
However:
- Changing the parameter value does not update the pattern geometry.
- Calling Update() or Rebuild does not solve the issue.
- Pattern only updates when manually editing it
If you:
- Right-click the pattern
- Select Edit Pattern
Inventor then shows the correct pattern preview using the updated parameter value.
After clicking OK, the pattern finally updates.
This indicates that the pattern is actually linked to the parameter, but the regeneration is not triggered automatically.
The pattern should update automatically whenever the parameter value changes.
Expected behavior
- The pattern spacing should always remain linked to the parameter expression
- Changing the parameter value should immediately regenerate the pattern, just like other sketch constraints and dimensions. if you add dim in sketch, the created par/value from adding the pattern, shoot update/follow as well.
Test script
Below is a minimal script that demonstrates the behavior.
Sub Main()
' create new part
Dim partDoc As PartDocument = ThisDoc.Document
'ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject)
Dim partDef As PartComponentDefinition = partDoc.ComponentDefinition
Dim sk As PlanarSketch = partDef.Sketches.Add(partDef.WorkPlanes.Item(3))
Dim tg As TransientGeometry = ThisApplication.TransientGeometry
Dim tobj As TransientObjects = ThisApplication.TransientObjects
' create reference lines
Dim vLine As SketchLine = sk.SketchLines.AddByTwoPoints(tg.CreatePoint2d(0, 0),tg.CreatePoint2d(0, 10))
Dim hLine As SketchLine = sk.SketchLines.AddByTwoPoints( tg.CreatePoint2d(0, 0), tg.CreatePoint2d(10, 0))
' create user parameter "spacer"
partDef.Parameters.UserParameters.AddByExpression( "spacer", "125 mm", UnitsTypeEnum.kMillimeterLengthUnits)
Dim ents1 As ObjectCollection = tobj.CreateObjectCollection()
ents1.Add(vLine)
' pattern #1 with fixed spacing
Dim pat1 As SketchRectangularPattern = sk.RectangularPatterns.Add(
sk.RectangularPatterns.CreateDefinition(
ents1,
hLine,
10,
False,
False,
"100 mm"))
' create a second seed line so pattern #2 is independent
Dim vLine2 As SketchLine = sk.SketchLines.AddByTwoPoints(
tg.CreatePoint2d(0, 20),
tg.CreatePoint2d(0, 30))
Dim ents2 As ObjectCollection = tobj.CreateObjectCollection()
ents2.Add(vLine2)
' pattern #2 driven by parameter
Dim pat2 As SketchRectangularPattern = sk.RectangularPatterns.Add(
sk.RectangularPatterns.CreateDefinition(
ents2,
hLine,
10,
False,
False,
"spacer"))
partDoc.Update()
ThisApplication.ActiveView.Fit()
End SubThanks for feedback.