Struggling with swAddMateError_e Enumeration in Python

Programming and macros
User avatar
bentlybobcat
Posts: 64
Joined: Tue Sep 21, 2021 8:43 am
Answers: 0
x 3
x 48

Struggling with swAddMateError_e Enumeration in Python

Unread post 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
Bent
User avatar
AlexB
Posts: 498
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 267
x 444

Re: Struggling with swAddMateError_e Enumeration in Python

Unread post 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
User avatar
bentlybobcat
Posts: 64
Joined: Tue Sep 21, 2021 8:43 am
Answers: 0
x 3
x 48

Re: Struggling with swAddMateError_e Enumeration in Python

Unread post 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
Bent
User avatar
bentlybobcat
Posts: 64
Joined: Tue Sep 21, 2021 8:43 am
Answers: 0
x 3
x 48

Re: Struggling with swAddMateError_e Enumeration in Python

Unread post 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....
Bent
User avatar
bentlybobcat
Posts: 64
Joined: Tue Sep 21, 2021 8:43 am
Answers: 0
x 3
x 48

Re: Struggling with swAddMateError_e Enumeration in Python

Unread post by bentlybobcat »

Got it.....

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

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

jeebus....
Bent
User avatar
AlexB
Posts: 498
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 28
x 267
x 444

Re: Struggling with swAddMateError_e Enumeration in Python

Unread post 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!
Post Reply