Python pass ref int as parameter


Mr. Sha

The tlb library in my python project passes win32com.client. I've easily used a number of built-in functions, but one of the main functions takes a list of arguments for two of them marked as ref int. When I try to pass a python integer to the function, I get pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 5)errors, apparently because of some wrong arguments passed to the object.
Here is my python code:

import sldworksPython as solidWorks
import sldconstPython as solidConst
import win32com.client


swApp: solidWorks.ISldWorks = win32com.client.Dispatch(solidWorks.SldWorks.CLSID)
swConst = solidConst.constants

fileName = "Assem Of Hinge.SLDASM"
docType = int(swConst.swDocASSEMBLY)
config = int(swConst.swOpenDocOptions_AutoMissingConfig)
error = int(swConst.swFileNotFoundError)
warning = int(swConst.swFileLoadWarning_AlreadyOpen)

print(type(error))

swApp.OpenDoc6(
    fileName,    
    docType,
    config,
    error,
    warning
)

Here is the openDoc6 function:

ModelDoc2 OpenDoc6(string FileName, int Type, int Options, string Configuration, ref int Errors, ref int Warnings);

This error freaks me out, I really don't want to use C# for this project. thank you for your help

Mr. Sha

Thanks to @BoarGules, I just downloaded a software library called pySW. I was wondering how these functions work there, so I just checked them out and figured out how I should pass an integer as a reference to a C# function.

I add my solution below:

import sldconstPython as solidConst
import win32com.client
import pythoncom
import pySW



swApp: solidWorks.ISldWorks = win32com.client.Dispatch(solidWorks.SldWorks.CLSID)
swConst = solidConst.constants

fileName = "Assem Of Hinge.SLDASM"
docType = swConst.swDocASSEMBLY
docOpts = swConst.swOpenDocOptions_AutoMissingConfig
error = win32com.client.VARIANT(pythoncom.VT_BYREF | pythoncom.VT_I4, swConst.swFileNotFoundError)
warning = win32com.client.VARIANT(pythoncom.VT_BYREF | pythoncom.VT_I4, swConst.swFileLoadWarning_AlreadyOpen)

swApp.OpenDoc6(fileName, docType, docOpts, "", error, warning)

This is weird because VScode doesn't suggest any pythoncomconstants for me. Anyway, hope this will help someone facing this kind of problem.

Related


Pass literal as const ref parameter

innocent bystander Imagine the following simplified code: #include <iostream> void foo(const int& x) { do_something_with(x); } int main() { foo(42); return 0; } (1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew

Pass literal as const ref parameter

innocent bystander Imagine the following simplified code: #include <iostream> void foo(const int& x) { do_something_with(x); } int main() { foo(42); return 0; } (1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew

Pass literal as const ref parameter

innocent bystander Imagine the following simplified code: #include <iostream> void foo(const int& x) { do_something_with(x); } int main() { foo(42); return 0; } (1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew

Pass parameter to $ref in OpenAPI 3

some development Suppose I have the following schema for later use $ref: "schemas": { "Order": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "petI

Pass literal as const ref parameter

innocent bystander Imagine the following simplified code: #include <iostream> void foo(const int& x) { do_something_with(x); } int main() { foo(42); return 0; } (1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew

Pass literal as const ref parameter

innocent bystander Imagine the following simplified code: #include <iostream> void foo(const int& x) { do_something_with(x); } int main() { foo(42); return 0; } (1) Besides optimization, what happens when 42 is passed to foo? Does the compiler stick 42 somew

Pass parameter to $ref in OpenAPI 3

some development Suppose I have the following schema for later use $ref: "schemas": { "Order": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "petI

Pass delegate/event as ref generic parameter

Sergio Romero We are dealing with a lot of legacy WinForms code and are slowly refactoring, breaking down dependencies, implementing the MVP pattern and moving logic from forms and user controls into the presenter. We've added Castle Windsor, which creates a V

Pass ref as function parameter React Native

Brinto In the current code, I use ref to change TextInputthe style of a component that uses a function in a method setNativeProps. class RegisterScreen extends Component { constructor(props) { super (props) this.state = { border

Pass ref as function parameter React Native

Brinto In the current code, I use ref to change TextInputthe style of a component that uses a function in a method setNativeProps. class RegisterScreen extends Component { constructor(props) { super (props) this.state = { border

How to pass parameter to member variable by ref?

JS Pretty new to C#, coming from a C++ background a long time ago, so I seem to be having trouble transitioning from pointers to refs in C#. I have a class (EColour) created with the constructor shown. I assign (or at least try to) a reference to cellTemplate

Pass ref as function parameter React Native

Brinto In the current code, I use ref to change TextInputthe style of a component that uses a function in a method setNativeProps. class RegisterScreen extends Component { constructor(props) { super (props) this.state = { border

Pass ref as function parameter React Native

Brinto In the current code, I use ref to change TextInputthe style of a component that uses a function in a method setNativeProps. class RegisterScreen extends Component { constructor(props) { super (props) this.state = { border

Pass delegate/event as ref generic parameter

Sergio Romero We are dealing with a lot of legacy WinForms code and are slowly refactoring, breaking down dependencies, implementing the MVP pattern and moving logic from forms and user controls into the presenter. We've added Castle Windsor, which creates a V

Pass ref as function parameter React Native

Brinto In the current code, I use ref to change TextInputthe style of a component that uses a function in a method setNativeProps. class RegisterScreen extends Component { constructor(props) { super (props) this.state = { border

Pass ref as function parameter React Native

Brinto In the current code, I use ref to change TextInputthe style of a component that uses a function in a method setNativeProps. class RegisterScreen extends Component { constructor(props) { super (props) this.state = { border

C# pass int[] (array) with and without ref

Bulgari boy I'm a little confused about this because I've read about an int[] array, even though int is a primitive type, since it's an array, it's a reference type variable. What is the difference between such methods: public static void ChangeSomething(ref i

C# pass int[] (array) with and without ref

Bulgari boy I'm a little confused about this because I've read about an int[] array, even though int is a primitive type, since it's an array, it's a reference type variable. What is the difference between such methods: public static void ChangeSomething(ref i

Pass char to method with int parameter

Hussein Zawawi: The output of the following code is 123because substringfrom beginIndex to EndIndex-1. However, I'm surprised how this is understood as 3(int) charhere , since substringthere are two integers. What is the concept behind this? String x = "12345"

Pass char to method with int parameter

Hussein Zawawi: The output of the following code is 123because substringfrom beginIndex to EndIndex-1. However, I'm surprised how this is understood as 3(int) charhere , since substringthere are two integers. What is the concept behind this? String x = "12345"

pass function as parameter in python

Salvador Dali: Suppose I want to calculate the following f(f(...f(x)..). Basically, many functions themselves. Currently, I am doing the following to achieve this result (and return all intermediate steps): def iterator(function, x, n=4): x = float(x)

pass function as parameter in python

Salvador Dali: Suppose I want to calculate the following f(f(...f(x)..). Basically, many functions themselves. Currently, I am doing the following to achieve this result (and return all intermediate steps): def iterator(function, x, n=4): x = float(x)

Pass array as parameter in Python

salad I'm not sure if this is possible, but I'm trying to create a Python program to identify polynomials and identify all their properties. I'm trying to make a function similar to a switch() function, and I'm going to create hundreds of functions around each

Pass method as parameter on python

Seebach 1 Can I pass methods as arguments on python? I want to do something like if anything is an instance of an object with a foo method: def access_to(class=anything, method="foo"): return class.method (Note that obviously the Anything instance has no attri

Python :: pass list as parameter

8th Borges responsesIn pyen, the thin library for music data returns a dictionary in this way: {u'id': u'AR6SPRZ1187FB4958B', u'name': u'Wilco'} I am looping and printing the artists: response = en.get('artist/search', artist_location='Chicago') artists = re

Pass array as parameter in Python

salad I'm not sure if this is possible, but I'm trying to create a Python program to identify polynomials and identify all their properties. I'm trying to make a function similar to a switch() function, and I'm going to create hundreds of functions around each

pass function as parameter in python

Salvador Dali Suppose I want to calculate the following f(f(...f(x)..). Basically, many functions themselves. Currently, I am doing the following to achieve this result (and return all intermediate steps): def iterator(function, x, n=4): x = float(x) a

pass function as parameter in python

Salvador Dali: Suppose I want to calculate the following f(f(...f(x)..). Basically, many functions themselves. Currently, I am doing the following to achieve this result (and return all intermediate steps): def iterator(function, x, n=4): x = float(x)

Pass array as parameter in Python

salad I'm not sure if this is possible, but I'm trying to create a Python program to identify polynomials and identify all their properties. I'm trying to make a function similar to a switch() function, and I'm going to create hundreds of functions around each