Inventor API Pattern Elements from Rectangular Pattern

Inventor API Pattern Elements from Rectangular Pattern

florian_wenzel
Advocate Advocate
825 Views
2 Replies
Message 1 of 3

Inventor API Pattern Elements from Rectangular Pattern

florian_wenzel
Advocate
Advocate

Hi,

Inventor 2022

API VB.NET VisualStudio

 

i try to use the Pattern Elements from my Rectangular Pattern, but without succes.

florian_wenzel_0-1660892461360.png

 

 

In Part Enviroment, i want to Pattern a WorkPlane 5 Times, fit to Path Lenght.

This Works.

 

Then i want to have Acces to the 2 or 3 WorkPlane from Pattern Elements, how to do this?

 

This is my Code:

 

Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32
Imports System.Collections.Generic
Imports System.Linq

Module CommandFunctionButton_12

    Public Sub CommandFunctionfweButton_12()

        Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
        Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
        Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry

        'Pick the Line
        Dim oLine As SketchLine = CType(g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveLinearFilter, "Pick a Line"), SketchLine)

        'Create Start point
        Dim oPoint As SketchPoint
        oPoint = oLine.StartSketchPoint

        'Create WorkPlane
        Dim oWorkplane As WorkPlane
        oWorkplane = oCompDef.WorkPlanes.AddByNormalToCurve(oLine, oPoint)

        'Create Object Coll for WorkPlane
        Dim oObjColl_01 As ObjectCollection
        oObjColl_01 = oTO.CreateObjectCollection
        oObjColl_01.Add(oWorkplane)

        'Create Path
        Dim oPath As Path = oCompDef.Features.CreatePath(oLine)
        Dim Count As Object = 5

        'Create Pattern Def
        Dim oRectPatternDef As RectangularPatternFeatureDefinition
        oRectPatternDef = oCompDef.Features.RectangularPatternFeatures.CreateDefinition(oObjColl_01, oPath, True, Count, PatternSpacingTypeEnum.kFitToPathLength)
        oRectPatternDef.XDirectionSpacingType = PatternSpacingTypeEnum.kFitToPathLength
        oRectPatternDef.OrientationMethod = PatternOrientationEnum.kAdjustToDirection1

        'Create Pattern Feature
        Dim oRectPattern As RectangularPatternFeature
        oRectPattern = oCompDef.Features.RectangularPatternFeatures.AddByDefinition(oRectPatternDef)

        'till this Moment Works Fine

        Dim oObjColl_Pattern As ObjectCollection
        oObjColl_Pattern = oTO.CreateObjectCollection
        oObjColl_Pattern.Add(oRectPattern.PatternElements)



        ''For Each oWorkPlaneColl As WorkPlane In oRectPattern.PatternElements()

        ''    oObjColl_Pattern.Add(oWorkPlaneColl)

        ''Next


        Dim oWorkPlane_02 As WorkPlane
        oWorkPlane_02 = oObjColl_Pattern(2)


        Dim oWorkPlane_03 As WorkPlane
        oWorkPlane_03 = oObjColl_Pattern(3)


        Dim oSketch_01 As PlanarSketch
        oSketch_01 = oCompDef.Sketches.Add(oWorkplane)

        Dim oSketch_02 As PlanarSketch
        oSketch_02 = oCompDef.Sketches.Add(oWorkPlane_02)

        Dim oSketch_03 As PlanarSketch
        oSketch_03 = oCompDef.Sketches.Add(oWorkPlane_03)


        Dim oCenterPoint_01 As SketchPoint
        oCenterPoint_01 = oSketch_01.SketchPoints.Add(oTG.CreatePoint2d(0, 0))

        Dim oCenterPoint_02 As SketchPoint
        oCenterPoint_02 = oSketch_02.SketchPoints.Add(oTG.CreatePoint2d(0, 0))

        Dim oCenterPoint_03 As SketchPoint
        oCenterPoint_03 = oSketch_03.SketchPoints.Add(oTG.CreatePoint2d(0, 0))


        Dim oCircle_01 As SketchCircle
        oCircle_01 = oSketch_01.SketchCircles.AddByCenterRadius(oCenterPoint_01, 1)

        Dim oCircle_02 As SketchCircle
        oCircle_02 = oSketch_02.SketchCircles.AddByCenterRadius(oCenterPoint_02, 2)

        Dim oCircle_03 As SketchCircle
        oCircle_03 = oSketch_03.SketchCircles.AddByCenterRadius(oCenterPoint_03, 3)

    End Sub



End Module

 

 

Thanks for any Sugesstion

0 Likes
Accepted solutions (1)
826 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor
Accepted solution

You need to access to  oRectPattern.PatternElements(i).ResultFeatures(1). This is the work plane except the first element. There you need to use the source oWorkPlane instead.

 

 

Sub Main()
    Dim oPartDoc As PartDocument = g_inventorApplication.ActiveDocument
    Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
    Dim oTO As TransientObjects = g_inventorApplication.TransientObjects
    Dim oTG As TransientGeometry = g_inventorApplication.TransientGeometry

    'Pick the Line
    Dim oLine As SketchLine = CType(g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveLinearFilter, "Pick a Line"), SketchLine)

    'Create Start point
    Dim oPoint As SketchPoint
    oPoint = oLine.StartSketchPoint

    'Create WorkPlane
    Dim oWorkplane As WorkPlane
    oWorkplane = oCompDef.WorkPlanes.AddByNormalToCurve(oLine, oPoint)

    'Create Object Coll for WorkPlane
    Dim oObjColl_01 As ObjectCollection
    oObjColl_01 = oTO.CreateObjectCollection
    oObjColl_01.Add(oWorkplane)

    'Create Path
    Dim oPath As Path = oCompDef.Features.CreatePath(oLine)
    Dim Count As Object = 5

    'Create Pattern Def
    Dim oRectPatternDef As RectangularPatternFeatureDefinition
    oRectPatternDef = oCompDef.Features.RectangularPatternFeatures.CreateDefinition(oObjColl_01, oPath, True, Count, PatternSpacingTypeEnum.kFitToPathLength)
    oRectPatternDef.XDirectionSpacingType = PatternSpacingTypeEnum.kFitToPathLength
    oRectPatternDef.OrientationMethod = PatternOrientationEnum.kAdjustToDirection1

    'Create Pattern Feature
    Dim oRectPattern As RectangularPatternFeature
    oRectPattern = oCompDef.Features.RectangularPatternFeatures.AddByDefinition(oRectPatternDef)

    'till this Moment Works Fine

    Dim centerPoint = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
    CreateSketchWithCircle(oWorkplane, centerPoint, 1)

    For i = 2 To oRectPattern.PatternElements.Count
        Dim element As FeaturePatternElement = oRectPattern.PatternElements(i)
        Dim elementWorkPlane As WorkPlane = element.ResultFeatures(1)

        Dim radius As Double = i 
        CreateSketchWithCircle(elementWorkPlane, centerPoint, radius)
    Next
End Sub

Sub CreateSketchWithCircle(workPlane As WorkPlane, centerPoint As Point2d, radius As Double)
    Dim oCompDef As PartComponentDefinition = workPlane.Parent
    Dim elementSketch = oCompDef.Sketches.Add(workPlane)
    elementSketch.SketchCircles.AddByCenterRadius(centerPoint, radius)
End Sub

 

Message 3 of 3

florian_wenzel
Advocate
Advocate

 

Thanks for Help, thanks for Solution

0 Likes