Sketch Rectangular Pattern API – Parameter updates and dimension control issues

Sketch Rectangular Pattern API – Parameter updates and dimension control issues

projects_by_rh
Observer Observer
137 Views
1 Reply
Message 1 of 2

Sketch Rectangular Pattern API – Parameter updates and dimension control issues

projects_by_rh
Observer
Observer

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.

  1. 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.

  1. 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.
  1. Pattern only updates when manually editing it

If you:

  1. Right-click the pattern
  2. 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 Sub

Thanks for feedback.

0 Likes
138 Views
1 Reply
Reply (1)
Message 2 of 2

JelteDeJong
Mentor
Mentor

this sounds like a bug. Did you post this bug in the feedback forums. https://feedback.autodesk.com/
I expect that you will get more feedback there.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes