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: 

VBA -> .Net Problem with Point2D

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
martin_winkler
585 Views, 4 Replies

VBA -> .Net Problem with Point2D

 

Hi,

i am actually writing VBA Code to VB.Net and have a problem with a Point2D object.

The macro shall align text, views and titles in an idw using the first selected object.

In VBA the macro works fine. In VB.NET i get a failure with the COM Object.

Any idea?


This is the example in VBA for the X Axis:

 

Sub AlignX()
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oSelect As SelectSet
Set oSelect = oDoc.SelectSet

Dim newPoint As Point2d
Set newPoint = oSelect.Item(1).Position

For Each obj In oSelect
  newPoint.Y = obj.Position.Y
  obj.Position = newPoint
Next
End Sub

 

VB.Net Code:

Sub AlignX()
            Dim oDoc As DrawingDocument = InventorApp.ActiveDocument
            Dim oSelect As SelectSet = oDoc.SelectSet
            Dim tg As TransientGeometry = InventorApp.TransientGeometry
            Dim newPointX As Point2d = Nothing
            Dim obj As Object

            newPointX = tg.CreatePoint2d(oSelect.Item(1).Position.X, oSelect.Item(1).Position.Y)

                For Each obj In oSelect
                    newPoint.Y = obj.Position.Y
                    obj.Position = newPointX
                Next
            End Sub


In the  For Each loop at obj.Position = newPointX  .Net creates the failure.

3DCS_2017.07.24_15h49m53s_001_.jpg

 

Best Regards Martin

4 REPLIES 4
Message 2 of 5
YuhanZhang
in reply to: martin_winkler

Can you provide the document(if it is not confidential) and create a snapshot to tell which objects are selected, and we can look into where the problem is?



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 3 of 5
martin_winkler
in reply to: YuhanZhang

Hi,

for better understanding the tool i make a video in which you can see how the tool works with the VBA Code.

You can try it in every idw!

 

After several workarrounds i think the problem is with the selected obj. because obj is declared as Object.

This is neccessary because obj can become different object types. But all of this objects have an obj.Position which i can set in VBA without problems.

In .Net there is a Type conflict because .Net not recognized that obj.Position is a Point2D. It.s a System_Com object

I tried declaring obj AS DrawingView...then it works, but only for DrawingViews.

 

How can i solve this type problem?

Let me know if you need more information.

 

Best Regards Martin

Message 4 of 5
YuhanZhang
in reply to: martin_winkler

You can change the line

 

obj.Position = newPoint

 

 

to

 

CallByName(obj, "Position", vbLet, newPoint)

Hope this helps.

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 5 of 5
martin_winkler
in reply to: YuhanZhang

Hi, thanks...thats what i am looking for. Now it works fine.

 

Best Regards Martin

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

Post to forums  

Autodesk Design & Make Report