Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Extracting sketch curves points

12 REPLIES 12
Reply
Message 1 of 13
kulkary
654 Views, 12 Replies

Extracting sketch curves points

Given a sketch, I wish to get its profile paths (outer, plus inners), for each path, I wish to get their individual curves (line, arc, splines, any type). For lines, I need start and end points, for others, some sample points would do.

 

For "T" like thin profile shape, following code got me, 1 ProfilePath, which had 8 Lines (thus 8 points) and it worked fine. 

T.png

 

For Each path As Inventor.ProfilePath In extFeature.Profile

    If Not path Is Nothing And path.Count > 0 Then

    For Each entity As Inventor.ProfileEntity In path

    If entity.CurveType = Curve2dTypeEnum.kLineSegmentCurve2d Then

        Dim oSkE As SketchEntity = entity.SketchEntity
        Dim oLine As SketchLine = CType(oSkE, SketchLine)
        Dim startpt As Inventor.Point2d = oLine.StartSketchPoint.Geometry
        Dim endpt As Inventor.Point2d = oLine.EndSketchPoint.Geometry

But same logic does not work (crashes at Casting I guess) for "S" shape as below:

 

S.png

 

It gives path.Count == 0.

 

Any clues?

Tags (1)
12 REPLIES 12
Message 2 of 13
Vladimir.Ananyev
in reply to: kulkary

Could you please upload your test part file and code sub that produce Count = 0.

Thanks


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 13
kulkary
in reply to: Vladimir.Ananyev

Hello,

Thanks for your help.

Attached is the part and here is the code (its under construction, so may
not be of good quality):

Dim extrudes As Inventor.ExtrudeFeatures
extrudes = m_partDoc.ComponentDefinition.Features.ExtrudeFeatures

If extrudes.Count > 0 Then

Dim extFeature As Inventor.ExtrudeFeature = extrudes.Item(1) '
YOGESH: now just FIRST

If Not extFeature.Profile Is Nothing Then

Dim pathIndex As Integer = 0

For Each path As Inventor.ProfilePath In extFeature.Profile

If Not path Is Nothing And path.Count > 0 Then

Dim pathVertices As Vertices = New Vertices

For Each entity As Inventor.ProfileEntity In path

If entity.CurveType =
Curve2dTypeEnum.kLineSegmentCurve2d Then

Dim oSkE As SketchEntity =
entity.SketchEntity
Dim oLine As SketchLine = CType(oSkE,
SketchLine)
Dim startpt As Inventor.Point2d =
oLine.StartSketchPoint.Geometry
Dim endpt As Inventor.Point2d =
oLine.EndSketchPoint.Geometry
Dim v1 As System.Windows.Vector = New
System.Windows.Vector(startpt.X, startpt.Y)
Dim v2 As System.Windows.Vector = New
System.Windows.Vector(endpt.X, endpt.Y)
'Debug.Print("Start Point = [" & v2.X & " ,
" & v2.Y & "]")
'Debug.Print("End Point = [" & v1.X & " , "
& v1.Y & "]")

If pathVertices.Count = 2 Then
If pathVertices.Index(v2) = 0 Then
' its goinf in reverse way
pathVertices.Reverse()
End If
End If

If (pathVertices.Index(v1) = -1) Then
pathVertices.Add(v1)
End If
If (pathVertices.Index(v2) = -1) Then
pathVertices.Add(v2)
End If
End If

Next

'if there are holes, meaning more than one path,
then add first vertex again to close it
If extFeature.Profile.Count > 1 Then

Dim addAtLast As Boolean = True
Dim vertexToAdd As System.Windows.Vector =
pathVertices.Vertex(0) ' cache it first then add at end for CCW and first
for CW

If pathIndex = 0 Then ' first profile should be
CCW
pathVertices.ForceCounterClockWise()
Else
pathVertices.ForceClockWise() ' make it
clockwise!!!!!!!!!!!!!
addAtLast = False
End If

If addAtLast = True Then
For Each vp As System.Windows.Vector In
pathVertices
m_InputPolygonVertices.Add(vp)
Next
m_InputPolygonVertices.Add(vertexToAdd)
Else
m_InputPolygonVertices.Add(vertexToAdd)
For Each vp As System.Windows.Vector In
pathVertices
m_InputPolygonVertices.Add(vp)
Next
End If
Else
pathVertices.ForceCounterClockWise()
For Each vp As System.Windows.Vector In
pathVertices
m_InputPolygonVertices.Add(vp)
Next
End If
End If

pathIndex = pathIndex + 1

Next

Dim myDebug As Boolean = True
If myDebug = True And m_InputPolygonVertices.Count > 0 Then
Dim w As StreamWriter = New StreamWriter("my.dat")
For Each v As System.Windows.Vector In
m_InputPolygonVertices
w.WriteLine(String.Format("{0} {1}", v.X, v.Y))
Next
w.Close()
End If

Please let me know if I am missing anything and suggest good way of
extracting profiles (outter and inners) separately and then getting points
for each of them.

Thanks

Yogesh

kulkarniay@gmail.com

E1-32 State Bank Nagar, NCL
Panchavati, Pashan, Pune 411008
India

Note: I will (surely attempt to) reply within 24hrs on weekdays if answers
are within my reach. If you can not wait that longer please feel free to
sms or call me at +91-9890251406
Message 4 of 13
xiaodong_liang
in reply to: kulkary

Hi,

 

your code is not run-able. I used a simple code (just checking if the path exists) on a sketch which looks similar to "S". The code can return the path lines.

 

Could you provide your part file?

 

Capture.JPG

Message 5 of 13
kulkary
in reply to: xiaodong_liang

Hello,

Attached are the part files (ipt and sat of the same part)


Thanks

Yogesh

kulkarniay@gmail.com

E1-32 State Bank Nagar, NCL
Panchavati, Pashan, Pune 411008
India

Note: I will (surely attempt to) reply within 24hrs on weekdays if answers
are within my reach. If you can not wait that longer please feel free to
sms or call me at +91-9890251406
Message 6 of 13
kulkary
in reply to: kulkary

Ok, I will try to upload again (I had attached in the mail-reply via gmail, earlier)

Message 7 of 13
Vladimir.Ananyev
in reply to: kulkary

Hi Yogesh

it seems like you have a problem with uploading the files.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 8 of 13
kulkary
in reply to: Vladimir.Ananyev

This site did not allow .sat file but I guess did the .ipt file.

Could you get the ipt? Its in my previous post. Attached here as well.

Message 9 of 13
kulkary
in reply to: xiaodong_liang

The code attached here has worked ok with the attached Part1.ipt but does not work with my part S.ipt. I had created this "S" profile by using the Text command in Sketching environment. You may want to try that as well.

Message 10 of 13
xiaodong_liang
in reply to: kulkary

Hi,

 

forget what I posted just now 🙂 I made a mistake. Actually, no any problem with the API. For TextBox path, it is correct that the PathProfile.Path is empty. To get the TextBox, access PathProfile.TextBox, next TextBox.BoundaryGeometry

 

 Dim path As ProfilePath
            For Each path In extFeature.Profile
                If path.TextBoxPath Then
                    Dim oTB As TextBox = path.TextBox
                    Dim oOutlineColl As SketchEntitiesEnumerator = oTB.BoundaryGeometry

                    Dim oEachEntity As SketchEntity
                    For Each oEachEntity In oOutlineColl
                        If TypeOf oEachEntity Is SketchLine Then
                            Dim oSL As SketchLine = oEachEntity
                            Dim oSTPt As SketchPoint = oSL.StartSketchPoint
                            Dim oEndPt As SketchPoint = oSL.EndSketchPoint
                        ElseIf TypeOf oEachEntity Is SketchSpline Then
                        Else

                        End If
                    Next
                Else
                    If path.Count > 0 Then
                        For Each entity As Inventor.ProfileEntity In path

                            If entity.CurveType =
                                Curve2dTypeEnum.kLineSegmentCurve2d Then
                                Dim oSkE As SketchEntity = entity.SketchEntity
                                Dim oLine As SketchLine = CType(oSkE, SketchLine)
                                Dim startpt As Inventor.Point2d = oLine.StartSketchPoint.Geometry
                                Dim endpt As Inventor.Point2d = oLine.EndSketchPoint.Geometry

                            End If

                        Next
                    End If
                End If
            Next

 

 

 

 

Message 11 of 13
kulkary
in reply to: xiaodong_liang

Thanks a lot. The 'TextBox' idea has worked. 

Message 12 of 13
kulkary
in reply to: xiaodong_liang

I debuged it further and found that in the 'TexBox' logic presented above, it does return 4 sketchentities but they are all lines, TextBox's bounding lines. I did not see the Splines of "S" coming there. Did I miss anything?

Message 13 of 13
xiaodong_liang
in reply to: kulkary

Hi,

 

you did not miss anything. I am wrong. We have a wish#1432685: retrieve geometry of text from sketch texboxes by API. I thought it has been implemented. When I saw "BoundaryGeometry", I was rushed to think it is that. However, it is actually the lines of the boundary of the TextBox. If you set TextBox.ShowBoundaries = true, you can see the 4 lines. Sorry for the misleading.

 

If you wanted to draw a client graphics from the strokes of the TextBox, you could consider to use GraphicsNode.AddTextGraphics. The TextBox.Style tells you the Font and Size of the TextBox, by which you could initialize TextGraphics.

 

If you must get the strokes, probably the Windows API FormattedText, PathGeometry may help a bit. I cannot guarantee, but this is what I can see by now.

 

Again, sorry for my misleading.

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report