Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Convert - [Tool] Convert Polyline to Spline (2D) - from VBA to VB.Net

GeorgK
Advisor

Convert - [Tool] Convert Polyline to Spline (2D) - from VBA to VB.Net

GeorgK
Advisor
Advisor

Hello together,

 

I try to convert this tool:

 

https://forums.autodesk.com/t5/inventor-forum/tool-convert-polyline-to-spline-2d/m-p/8779347?collaps...

 

But I have an error in my code:

 

Private Sub PreviewPoints()
        ' Generierung der Liste der aktuellen Punkte  ' Erstellen der Punkte und Hinzufügen zur Punkteliste
        Dim oSelectSet As SelectSet
        oSelectSet = m_inventorApplication.ActiveDocument.SelectSet
        oSelectSet.Clear()
        Dim oTransGeom As TransientGeometry

        Dim nPointPreview As Object
        'Dim nPoint As Object = Nothing

        oTransGeom = m_inventorApplication.TransientGeometry
        Dim oPreviewPoints As ObjectCollection
        oPreviewPoints = m_inventorApplication.TransientObjects.CreateObjectCollection
        Dim oPoints(nPoint) As Point2d
        For i = 1 To nPoint
            ' Generieren des aktuellen Punkts
            oPoints(i) = oTransGeom.CreatePoint2d(oPointCoordX(i), oPointCoordY(i)) '==>>> Error
            ' Aufnahme des Punkts in die Liste
            oPreviewPoints.Add(oPoints(i))
        Next i
        'oSelect.Select oPreviewPoints
        ' Hinzufügen der Punkte zur aktuellen Ebene
        Dim oSketch As PlanarSketch
        oSketch = m_inventorApplication.ActiveEditObject
        For i = 1 To nPoint
            ' Generieren des aktuellen Punkts als Mittelpunkt (mit Markierung)
            oSketch.SketchPoints.Add(oPoints(i), True)
        Next i

        ' Warten auf die Bestätigung
        MsgBox("Vorschau beenden")

        ' Löschen der aktuellen Punkte
        nPointPreview = oSketch.SketchPoints.Count
        For i = nPointPreview To nPointPreview - nPoint + 1 Step -1
            '  MsgBox "Typ: " & TypeName(obj)
            ' Selektieren des aktuellen Punkts
            oSelectSet.Select(oSketch.SketchPoints(i))
        Next
        oSelectSet.Delete()

    End Sub

Thank you

Georg

0 Likes
Reply
1,688 Views
16 Replies
Replies (16)

Frederick_Law
Mentor
Mentor

There is a lot more then just convert to VB.Net.

You can find a template from SDK.

Take a look at API help on addin development.

0 Likes

GeorgK
Advisor
Advisor

Hello @Frederick_Law ,

 

I have an add-in already. This tool would be nice to have it in my add-in 🙂

 

Thanks

Georg

0 Likes

Frederick_Law
Mentor
Mentor

I think you have VBA macro?

And try to convert it to an "app" or addin?

I read you other post.

0 Likes

GeorgK
Advisor
Advisor

In the other post is a VBA macro.

https://forums.autodesk.com/autodesk/attachments/autodesk/78/744546/4/DialogPolylineToSpline.zip

I tried to convert it to VB.Net for my existing add-in.

 

Attached is a standalone version.

 

 

 

 

 

0 Likes

chandra.shekar.g
Autodesk Support
Autodesk Support

@GeorgK,

 

Can you please explain the requirement in detail with non confidential VBA code? 

 

what is nPoint variable (Declared, but not defined properly)?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g ,

 

I tried to convert the VBA program from my initial post to VB.Net.

 

https://forums.autodesk.com/t5/inventor-forum/tool-convert-polyline-to-spline-2d/m-p/8779347?collaps...

 

Thank you

Georg

0 Likes

weiser
Advocate
Advocate

Hi there,
I'm the author of the VBA-Tool. I've put the whole code into a VBA-UserForm. And to keep it simple I am using some "global" declarations in the beginning of the code.

So the prefix 'n' is for number of, 'm' for maximum number of, 'o' for object, 'i' for indices. Maybe this helps reading the code, because I did all the comments in German 😉

Regards

0 Likes

chandra.shekar.g
Autodesk Support
Autodesk Support

@GeorgK,

 

Can you please provide reproducible steps to investigate?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes

GeorgK
Advisor
Advisor

I tried to convert it to VB.Net. There is an error in the marked line:

 

Private Sub PreviewPoints()
        ' Generierung der Liste der aktuellen Punkte  ' Erstellen der Punkte und Hinzufügen zur Punkteliste
        Dim oSelectSet As SelectSet
        oSelectSet = m_inventorApplication.ActiveDocument.SelectSet
        oSelectSet.Clear()
        Dim oTransGeom As TransientGeometry

        Dim nPointPreview As Object
        'Dim nPoint As Object = Nothing

        oTransGeom = m_inventorApplication.TransientGeometry
        Dim oPreviewPoints As ObjectCollection
        oPreviewPoints = m_inventorApplication.TransientObjects.CreateObjectCollection
        Dim oPoints(nPoint) As Point2d
        For i = 1 To nPoint
            ' Generieren des aktuellen Punkts
            oPoints(i) = oTransGeom.CreatePoint2d(oPointCoordX(i), oPointCoordY(i)) '==>>> Error !!!!
            ' Aufnahme des Punkts in die Liste
            oPreviewPoints.Add(oPoints(i))
        Next i
        'oSelect.Select oPreviewPoints
        ' Hinzufügen der Punkte zur aktuellen Ebene
        Dim oSketch As PlanarSketch
        oSketch = m_inventorApplication.ActiveEditObject
        For i = 1 To nPoint
            ' Generieren des aktuellen Punkts als Mittelpunkt (mit Markierung)
            oSketch.SketchPoints.Add(oPoints(i), True)
        Next i

        ' Warten auf die Bestätigung
        MsgBox("Vorschau beenden")

        ' Löschen der aktuellen Punkte
        nPointPreview = oSketch.SketchPoints.Count
        For i = nPointPreview To nPointPreview - nPoint + 1 Step -1
            '  MsgBox "Typ: " & TypeName(obj)
            ' Selektieren des aktuellen Punkts
            oSelectSet.Select(oSketch.SketchPoints(i))
        Next
        oSelectSet.Delete()

    End Sub
0 Likes

chandra.shekar.g
Autodesk Support
Autodesk Support

@GeorgK,

 

DialogPolylineToSpline.zip contains DialogPolylineToSpline.frm and DialogPolylineToSpline.frx files which may not used to debug the code. Can you please provide non confidential solution to debug the code?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g 

 

attached is the coverted file.

 

Thank you

Georg

0 Likes

chandra.shekar.g
Autodesk Support
Autodesk Support

@GeorgK,

 

Can you please provide non confidential sample model data and steps to reproduce the issue?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g,

 

attached is a sample model.

 

Thank you

Georg

0 Likes

chandra.shekar.g
Autodesk Support
Autodesk Support

@GeorgK,

 

Gave a try to reproduce the error. But inventor crashed in between while testing it. Can you please give reproducible steps to test the behavior?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes

GeorgK
Advisor
Advisor

Hello @chandra.shekar.g ,

 

the ipt is working with the VBA code.  But it's not working with the VB.Net code. I couldn't find the answer for the crash.

Thank you Georg

0 Likes

chandra.shekar.g
Autodesk Support
Autodesk Support

@GeorgK,

 

Hoping that below change may be helpful.

 

Private Sub PreviewPoints()
        ' Generierung der Liste der aktuellen Punkte  ' Erstellen der Punkte und Hinzufügen zur Punkteliste
        Dim oSelectSet As SelectSet
        oSelectSet = m_inventorApplication.ActiveDocument.SelectSet
        oSelectSet.Clear()
        Dim oTransGeom As TransientGeometry

        Dim nPointPreview As Object
        'Dim nPoint As Object = Nothing

        oTransGeom = m_inventorApplication.TransientGeometry
        Dim oPreviewPoints As ObjectCollection
        oPreviewPoints = m_inventorApplication.TransientObjects.CreateObjectCollection
        Dim oPoints(nPoint) As Point2d
        For i = 0 To nPoint -1
            ' Generieren des aktuellen Punkts
            oPoints(i) = oTransGeom.CreatePoint2d(oPointCoordX(i), oPointCoordY(i)) '==>>> Error !!!!
            ' Aufnahme des Punkts in die Liste
            oPreviewPoints.Add(oPoints(i))
        Next i
        'oSelect.Select oPreviewPoints
        ' Hinzufügen der Punkte zur aktuellen Ebene
        Dim oSketch As PlanarSketch
        oSketch = m_inventorApplication.ActiveEditObject
        For i = 1 To nPoint
            ' Generieren des aktuellen Punkts als Mittelpunkt (mit Markierung)
            oSketch.SketchPoints.Add(oPoints(i), True)
        Next i

        ' Warten auf die Bestätigung
        MsgBox("Vorschau beenden")

        ' Löschen der aktuellen Punkte
        nPointPreview = oSketch.SketchPoints.Count
        For i = nPointPreview To nPointPreview - nPoint + 1 Step -1
            '  MsgBox "Typ: " & TypeName(obj)
            ' Selektieren des aktuellen Punkts
            oSelectSet.Select(oSketch.SketchPoints(i))
        Next
        oSelectSet.Delete()

    End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Type a product name