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.
Best Regards Martin
Solved! Go to Solution.
Solved by YuhanZhang. Go to Solution.
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?
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
You can change the line
obj.Position = newPoint
to
CallByName(obj, "Position", vbLet, newPoint)
Hope this helps.
Hi, thanks...thats what i am looking for. Now it works fine.
Best Regards Martin