Create Point2d from SketchPoint in Circular Pattern in Sketch VB.NET

Create Point2d from SketchPoint in Circular Pattern in Sketch VB.NET

florian_wenzel
Advocate Advocate
1,256 Views
5 Replies
Message 1 of 6

Create Point2d from SketchPoint in Circular Pattern in Sketch VB.NET

florian_wenzel
Advocate
Advocate

Hi,

 

Inventor 2022

API Visual Studio VB.NET

 

i try to Create a little bit Complex Sketch.

The Goal is to get Circulat Pattern of Lines in a SketchArc2d.

It works not bad, but only when i use simple Coordinates Points, for example 0,0 🙂

florianwenzelEJNZZ_0-1652832310844.png

florianwenzelEJNZZ_1-1652832334857.png

 

 

florianwenzelEJNZZ_1-1652831048724.png

 

 

This is the code:

 

 

 

 

 

 

 

Imports System.Runtime.InteropServices
Imports Inventor
Imports Microsoft.Win32



Module CommandFunctionButton_09
    Public Sub CommandFunctionfweButton_09()

        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



        Dim oCurve As Object = CType(g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveFilter, "Pick a Curve"), Object)

        Dim oPlane09 As Object = CType(g_inventorApplication.CommandManager.Pick(SelectionFilterEnum.kWorkPlaneFilter, "Pick a Plane"), Object)

        Dim oWorkSketch09 As PlanarSketch = oCompDef.Sketches.Add(oPlane09, False)

        Dim oEntity09 As SketchEntity
        oEntity09 = oWorkSketch09.AddByProjectingEntity(oCurve)


        Dim oSketchLine09a As SketchLine
        oSketchLine09a = oWorkSketch09.SketchLines.AddByTwoPoints(oEntity09.CenterSketchPoint, oEntity09.EndSketchPoint)

        Dim oSketchLine09b As SketchLine
        oSketchLine09b = oWorkSketch09.SketchLines.AddByTwoPoints(oEntity09.CenterSketchPoint, oEntity09.StartSketchPoint)

        Dim oRotatePoint2 As Point2d
        oRotatePoint2 = oTG.CreatePoint2d(10, 0)

        Dim oAngleDim As TwoLineAngleDimConstraint
        oAngleDim = oWorkSketch09.DimensionConstraints.AddTwoLineAngle(oSketchLine09a, oSketchLine09b, oRotatePoint2, True)

        Dim oValueAngle As Double
        oValueAngle = oAngleDim._DisplayValue

        Dim oValue1 As Double
        oValue1 = oValueAngle / 4

        Dim oValue2 As Double
        oValue2 = oValue1 * 2

        Dim oValue3 As Double
        oValue3 = oValue1 * 3

        Dim oColection As ObjectCollection
        oColection = oTO.CreateObjectCollection
        Call oColection.Add(oSketchLine09b)

        Dim oRotatePoint As Point2d
        oRotatePoint = oTG.CreatePoint2d(0, 0)


        Call oWorkSketch09.RotateSketchObjects(oColection, oRotatePoint, oValue1, True, False)
        Call oWorkSketch09.RotateSketchObjects(oColection, oRotatePoint, oValue2, True, False)
        Call oWorkSketch09.RotateSketchObjects(oColection, oRotatePoint, oValue3, True, False)

    End Sub
End Module

 

 

 

 

 

 

 

florianwenzelEJNZZ_2-1652831106703.png

 

 

 

The Question is:

a) How to Create Point2d from SketchPoint, for example from Start or EndPoint of Sketchline or Center of Arc?

For Example, when the CenterPoint of Arc is somewere in space, or to define the Point2d by Dimmension etc..

Not to using X and Y Coords.

florianwenzelEJNZZ_0-1652833234435.png

 

 

 

b) How to Define the creating SketchLines via Feature "RotateSketchObject", so that i can later use this ?

as SketchLineR1, SketchLineR2, SketchLineR3 etc..

florianwenzelEJNZZ_1-1652832885753.png

 

 

c) How to Define  a existing already Arc2d in a Sketch via AddByProjectingEntity? for example to use the CenterPoint?

 

florianwenzelEJNZZ_3-1652833032747.png

 

 

d) with API Sketch RotateSketchObject is not exactly the same, as we manually (native) use in Sketch CircularPattern, does CircularPattern working also in Sketch? 

in  RotateSketchObject we are not able to choose the count and etc...

 

florianwenzelEJNZZ_2-1652832981188.png

 

How to make this with file Test_43, without using Coords X,Y to define Point2d.

Is it possible, to Create the Point2d using other methode?

 

Thanks for any Sugestion

 

 

0 Likes
Accepted solutions (1)
1,257 Views
5 Replies
Replies (5)
Message 2 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

Hello,

Sketch circular pattern has no API. You are not able to create new circular pattern. But  you can copy existing circular pattern from one sketch to another.

Sub CopyCircularPatternTest()
    Dim sk1 As PlanarSketch
    Dim sk As PlanarSketch
    
    Set sk1 = ActivePart.ComponentDefinition.Sketches(1)
    Set sk2 = ActivePart.ComponentDefinition.Sketches(2)
    
    Call sk1.CopyContentsTo(sk2)

End Sub

 

In the case when you don't need to create circular pattern and just need sketch lines in the right position, you can use something like this

 

Sub CopyCircularPatternTest2()
    
    'Planar sketch must be active
    Dim oSketch As PlanarSketch
    Set oSketch = ThisApplication.ActiveEditObject
    
    'Sketch mus contains at least one SketchArc
    Dim arc As SketchArc
    Set arc = oSketch.SketchArcs(1)
    
    'Define lines count (pattern elements count)
    Dim linesCount As Integer
    linesCount = 5
    
    Dim centerPoint As SketchPoint
    Set centerPoint = arc.CenterSketchPoint
    
    Dim arcEvaluator As Curve2dEvaluator
    Set arcEvaluator = arc.Geometry.Evaluator
    
    Dim minParam As Double
    Dim maxParam As Double
    Call arcEvaluator.GetParamExtents(minParam, maxParam)
    
    Dim paramDiff As Double
    paramDiff = (maxParam - minParam) / (linesCount - 1)

    Dim pointParams() As Double
    ReDim pointParams(linesCount - 1)
    
    Dim i As Integer
    For i = 0 To linesCount - 1
        pointParams(i) = minParam + i * paramDiff
    Next
    
    Dim pointCoords() As Double
    Call arcEvaluator.GetPointAtParam(pointParams, pointCoords)
    
    Dim j As Integer
    For j = 0 To linesCount - 1
        Dim xIndex As Double
        Dim yIndex As Double
        xIndex = j * 2
        yIndex = j * 2 + 1
        
        Dim x As Double
        Dim y As Double
        x = pointCoords(xIndex)
        y = pointCoords(yIndex)
        
        Dim endPoint As Point2d
        Set endPoint = ThisApplication.TransientGeometry.CreatePoint2d(x, y)
        
        Dim newLine As SketchLine
        Set newLine = oSketch.SketchLines.AddByTwoPoints(centerPoint, endPoint)
        
        'Fixed position
        'Call oSketch.GeometricConstraints.AddGround(newLine.EndSketchPoint)
        
        'Coincindent constraint to sketch arc
        Call oSketch.GeometricConstraints.AddCoincident(arc, newLine.EndSketchPoint)
        
    Next
    
End Sub
Message 3 of 6

florian_wenzel
Advocate
Advocate

Hi,

thanks a lot.

So, if you want to Create Point2d, is the only way with Coords XY ?

I asking, because i saw in a Sample :Creation a balloon API Sample (Inventor 2022 Help | Creation a balloon | Autodesk) , that they create a Point2d from a DrawingCurveSegment.

 

Is possible to create a Point2d  from LineSegment2d ?

 

 

 

 

 

 

0 Likes
Message 4 of 6

Michael.Navara
Advisor
Advisor

If you want to create new Point2D, you need to use this method: 

ThisApplication.TransientGeometry.CreatePoint2d(x, y)

But sometimes you can obtain the point2D object as result of method (Point2D.Copy()) or as a property value.

For more info see API reference

 

Message 5 of 6

florian_wenzel
Advocate
Advocate

ok,

and what mean this:

 

Inventor 2020 Help | LineSegment2d.MidPoint Property | Autodesk

Description

Gets the mid point of the line segment.

Syntax

LineSegment2d.MidPoint() As Point2d

Property Value

This is a read only property whose value is a Point2d.

 

Can i create Point2d from LineSegment2d?

Also, is possible to Convert SketchLine in a lineSegment2d?

When, then how.

 

Thanks

0 Likes
Message 6 of 6

florian_wenzel
Advocate
Advocate

ok,

i got it

       Dim oSketchLine01 As SketchLine
        oSketchLine01 = oWorkSketch01.SketchLines.AddByTwoPoints(oWorkPoint01, oWorkPoint02)

        Dim oSketchArc01 As SketchArc
        oSketchArc01 = oWorkSketch01.SketchArcs.AddByThreePoints(oWorkPoint03, oWorkPoint05, oWorkPoint04)




        Dim oLineSegment01 As LineSegment2d
        oLineSegment01 = oSketchLine01.Geometry

        Dim oPoint As Point2d
        oPoint = oLineSegment01.MidPoint

        Dim oSketchLine02 As SketchLine
        oSketchLine02 = oWorkSketch01.SketchLines.AddByTwoPoints(oPoint, oWorkPoint03)

😉

 

0 Likes