Struggling with swAddMateError_e Enumeration in Python

Greetings all,

I got a wild hair to apply my rudimentary python skills to write macros for SolidWorks.

I’m making good progress. Some interesting gyrations to jump through, but I’m establishing a good book of knowledge to use in the future.

But I’m hamstrung on the longstatus parameter used in AddMate3 https://help.solidworks.com/2015/english/api/sldworksapi/SOLIDWORKS.Interop.sldworks~SOLIDWORKS.Interop.sldworks.IAssemblyDoc~AddMate3.html

In the VBA script that I’m using as a go-by, longstatus is defined as:

Dim longstatus as SwConst.swAddMateError_e

I’ve created a python class with the swAddMateError_e enum, to use in defining longstatus, but every variation I use gets kicked back.

I’ve tried to set longstatus to 0, which technically should work, but get a type mismatch.

Help!

Bently

If I understand correctly, this is relatively common with solidworks constants. If you convert them to an integer wherever you use them, they should work.

This example is with c# but any constants need to be cast to an integer. Any variables that are returned by solidworks functions, such as the errors and warnings, are defined as integers.
image.png

Thanks.

Well with the untyped nature of python, you have to assign a value to longstatus prior to usage.

I’ve tried casting longstatus to an int using int(), but I get the following:

pywintypes.com_error:(-2147352571, ‘Type mismatch.’, None, 13)

I’ve looked around and can’t find any reference to this… :frowning:

thanks

Bently

Argh…

Playing with the VBA code that I’m translating, if I replace longstatus with 0, it works just fine.

Need a pulling hair out emoji…

Got it…

Thanks to http://joshuaredstone.blogspot.com/2015/

longstatus = win32com.client.VARIANT(pythoncom.VT_BYREF | prythoncom.VT_I4, 1)

jeebus…

That’s an interesting workaround. Glad you found the answer!