Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Trying to fix a warning using the inventor API in vb.net

K.clement
Contributor

Trying to fix a warning using the inventor API in vb.net

K.clement
Contributor
Contributor

 

When using the 'CreateGeometryProxy' function of the inventor API in VB.Net,

Visual studio gives you this warning:

https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/error-messages/implicit-conv... 

 

Any idea on how i avoid this?

Code example:

oOcc.CreateGeometryProxy(oOccXZPlane, oOccXZPlane)

 

0 Likes
Reply
Accepted solutions (1)
292 Views
5 Replies
Replies (5)

WCrihfield
Mentor
Mentor

Hi @K.clement.  It would be difficult to diagnose without seeing more of the code, but based on the error link, it seems to be trying to convert one object type to another, and that won't work.  I know that specific function is designed to set the value of the second input variable (a pre-existing variable that is supposed to be defined as one of the 'proxy' type objects).  It looks to me like you are supplying the same variable for both input variables of the function, which it was not designed for.  The first variable is for the source object that it is to get/create a proxy for, and the second variable is to hold the new proxy object that was retrieved/created from the first variable.  If dealing with WorkPlane object, the first input variable can be either a WorkPlane or a WorkPlaneProxy, but the second input variable should be pre-defined as a WorkPlaneProxy Type object.  Technically, the WorkPlaneProxy Class is derived from the WorkPlane Class, so it may not normally throw an error when directly converting between the two within the iLogic environment, but I'm not sure about within the Visual Studio / VB.NET environment.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

K.clement
Contributor
Contributor

a bigger example:

 

Dim oADef As ComponentDefinition = g_inventorApplication.ActiveDocument.ComponentDefinition
Dim oAsmXYPlane As WorkPlane = oADef.WorkPlanes.Item(3) 'Assembly XY Plane
Dim oAsmZAxis As WorkAxis = oADef.WorkAxes.Item(3) 'Assembly Z Axis

 

Dim oODef As ComponentDefinition = oOcc.Definition
Dim oOccXYPlane As WorkPlane = oODef.WorkPlanes.Item(3) 'Occurrence XY Plane
Dim oOccZAxis As WorkAxis = oODef.WorkAxes.Item(3) 'Occurrence Z Axis
oOcc.CreateGeometryProxy(oOccXYPlane, oOccXYPlane)
oOcc.CreateGeometryProxy(oOccZAxis, oOccZAxis)

 

This is a bigger example, do note that :

- This Code works, (it only gives a annoying warning)

- Defining:  Dim x as workplaneproxy  /  oOcc.CreateGeometryProxy(oOccXYPlane, x) gives the same warning:

 

 

0 Likes

JelteDeJong
Mentor
Mentor

Looking at the code I expect this is not an iLogic rule. (But an addin?) Anyway, I guess that your function looks something like this:

Public Sub YourFunction(oOcc As ComponentOccurrence)
	Dim oADef As ComponentDefinition = g_inventorApplication.ActiveDocument.ComponentDefinition
	Dim oAsmXYPlane As WorkPlane = oADef.WorkPlanes.Item(3) 'Assembly XY Plane
	Dim oAsmZAxis As WorkAxis = oADef.WorkAxes.Item(3) 'Assembly Z Axis


	Dim oODef As ComponentDefinition = oOcc.Definition
	Dim oOccXYPlane As WorkPlane = oODef.WorkPlanes.Item(3) 'Occurrence XY Plane
	Dim oOccZAxis As WorkAxis = oODef.WorkAxes.Item(3) 'Occurrence Z Axis
	oOcc.CreateGeometryProxy(oOccXYPlane, oOccXYPlane)
	oOcc.CreateGeometryProxy(oOccZAxis, oOccZAxis)
End Sub

What I understand from the Microsoft link that you send is that your function is not defined correctly. 

Did you try using the keywords ByVal or ByRef? Something like this:

Public Sub YourFunction(ByVal oOcc As ComponentOccurrence)

or

Public Sub YourFunction(ByRef oOcc As ComponentOccurrence)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes

K.clement
Contributor
Contributor

You are correct, this is a addin, and this is indeed the function I made :winking_face:

I did not use 'byref or byval oOcc as ComponentOccurrence', but adding this to the sub argument does not fix the warning.

this might help:

Kclement_0-1661408784670.png

 

0 Likes

K.clement
Contributor
Contributor
Accepted solution

i figured it out, there is no mistake here, but this gets rid of the warning 

Dim objWorkPlane As Object
firstCompOcc.CreateGeometryProxy(nativeWorkPlane, objWorkPlane)

If TypeOf (objWorkPlane) Is WorkPlaneProxy Then
Dim proxyWorkPlane As WorkPlaneProxy
proxyWorkPlane = CType(objWorkPlane, WorkPlaneProxy)
End If

 

0 Likes