Page 1 of 1

Struggling with swAddMateError_e Enumeration in Python

Posted: Thu Sep 23, 2021 11:07 am
by bentlybobcat
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/englis ... Mate3.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

Re: Struggling with swAddMateError_e Enumeration in Python

Posted: Thu Sep 23, 2021 2:37 pm
by AlexB
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

Re: Struggling with swAddMateError_e Enumeration in Python

Posted: Fri Sep 24, 2021 7:44 am
by bentlybobcat
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.... :(

thanks

Bently

Re: Struggling with swAddMateError_e Enumeration in Python

Posted: Fri Sep 24, 2021 8:41 am
by bentlybobcat
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....

Re: Struggling with swAddMateError_e Enumeration in Python

Posted: Fri Sep 24, 2021 9:05 am
by bentlybobcat
Got it.....

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

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

jeebus....

Re: Struggling with swAddMateError_e Enumeration in Python

Posted: Fri Sep 24, 2021 9:40 am
by AlexB
bentlybobcat wrote: Fri Sep 24, 2021 9:05 am 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!