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
Struggling with swAddMateError_e Enumeration in Python
- bentlybobcat
- Posts: 64
- Joined: Tue Sep 21, 2021 8:43 am
- x 3
- x 48
Re: Struggling with swAddMateError_e Enumeration in Python
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.
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.
- bentlybobcat
- Posts: 64
- Joined: Tue Sep 21, 2021 8:43 am
- x 3
- x 48
Re: Struggling with swAddMateError_e Enumeration in Python
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
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
- bentlybobcat
- Posts: 64
- Joined: Tue Sep 21, 2021 8:43 am
- x 3
- x 48
Re: Struggling with swAddMateError_e Enumeration in Python
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....
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
- bentlybobcat
- Posts: 64
- Joined: Tue Sep 21, 2021 8:43 am
- x 3
- x 48
Re: Struggling with swAddMateError_e Enumeration in Python
Got it.....
Thanks to http://joshuaredstone.blogspot.com/2015/
longstatus = win32com.client.VARIANT(pythoncom.VT_BYREF | prythoncom.VT_I4, 1)
jeebus....
Thanks to http://joshuaredstone.blogspot.com/2015/
longstatus = win32com.client.VARIANT(pythoncom.VT_BYREF | prythoncom.VT_I4, 1)
jeebus....
Bent
Re: Struggling with swAddMateError_e Enumeration in Python
That's an interesting workaround. Glad you found the answer!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....