Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a dll and I'd like to call it in python. The dll needs of parameters. Do you know how to pass a radiobutton parameter and a checkbox parameter? thanks

share|improve this question
    
stackoverflow.com/questions/252417/… I am not sure if that helps. –  theJones Oct 25 '11 at 17:27
add comment

1 Answer

I am assuming you mean by your question that your Arc tool has a radiobutton and checkbox parameter in the interface (rather than 'radiobutton' and 'checkbox' being native types in whatever language you write the DLL in).

So - do you really need your DLL to know what flavour of user interface element the parameter came from, or would it be better if the DLL was agnostic of how it was called, and just did the computation?

Checkboxes pass from arc to python as booleans. Radio buttons - I didn't know you could make them, I thought you had to use a string with an input filter. Play around with the tool properties dialog to achieve this; create your parameters, select the string parameter, and then clicking on the '...' after 'Filter' will allow you to enter the values you want available.

Then in the python:

# call dll to cater to the user's colour preference (from radio button)
# depending on whether or not they are underwater (deduced from checkbox)

user_is_underwater = arcpy.GetParameter(0)
favourite_colour = arcpy.GetParameterAsText(1)

dll = ctypes.windll.LoadLibrary("mydllname.dll")
dll.dostuff(user_is_underwater,favourite_colour)

Ctypes will automatically convert favourite_colour to a C-style char*. So if your dll is written in C++ it will have to define

extern "C" __declspec(dllexport) void __stdcall dostuff(bool user_is_underwater, char* favourite_colour) 
{
    //do your stuff here, possibly including tests such as
    if (strcmp(favourite_colour,"RED"))
         ...
}

I assume you'll have other parameters and may also have to use ctypes to set a return type for dll.run, if it has one.

Alternatively, convert your strings to integers in the python, e.g.

favourite_colour = ctypes.c_int(['RED','GREEN'].index(arcpy.GetParameterAsText(1))

and pass them to the dll as integers; though you'll then need to keep three representations in sync: the script parameter dialog, that list in the python and a matching enum in the C.

share|improve this answer
    
thanks a lot I'll try –  Grazia Nov 9 '11 at 13:23
    
just to check, have you read this? help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… that's the best full tutorial; just look at my reply for reference specifically to your checkbox/radiobutton issues –  Sideshow Bob Nov 9 '11 at 16:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.