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 written a code in VBA, I am passing parameters to Python and creating a buffer there. After that I am passing that buffer layer and further processing in VBA again.

Here is the code for reference:

'Create Buffer using Python Shell
LayerPath = ""
LayerPath = GetWorkspacePathWithLayerName(EdgeLayer) & ".shp"
Dim OutputFolderPath As String
Dim OutputFileName As String
Dim OutputPath As String
Dim BuffDist As Double

OutputFolderPath = GetPath(EdgeLayer) & "\Buffer"
OutputFileName = Replace(getUniqueFileName("Buffer_" & EdgeLayer.Name), ".", "") & ".shp"
OutputPath = OutputFolderPath & "\" & OutputFileName

BuffDist = ConverUnitsFromMetersToMapUnits(txtMinAngle)

'TRYING to CALL PYTHON and PASSING Parameters
Shell "c:\Python26\ArcGIS10.0\Python.exe " & " D:\Createbuffer.py" & " " & LayerPath & " " & OutputPath & " " & BuffDist, vbMaximizedFocus

**addToCurrentView** OutputFolderPath, OutputFileName

I want VBA to halt addToCurrentView till Python shell completes its process (creating buffer). Right now it is giving error as there is a lock clash for the file. Can anyone help me as to how to do that.

Thanking in advance for the answers and comments

share|improve this question
    
Why don't you do it all in VBA or all in Python? Alternatively, can you run the Python as a subprocess? I'm not so familiar with VBA but I believe there is a 'WaitUntilFinished' switch for subprocesses in VBA similar to the check call in Python –  MappaGnosis Sep 30 '13 at 9:33
    
@MappaGnosis The code is written by someone else in VBA and Dissolving buffers is a major problem in VBA, so I am doing it in Python, but further processes are written in VBA. Also, this is a test I am doing because I want to shift partly VBA codes used in our organisation(time consuming one's) to Python. –  Swanand Sep 30 '13 at 9:37
    
GOT ANSWER: wrote a function for the shell to wait. First Declared functions CreateProcessA, WaitForSingleObject and CloseHandle. Used them in ShellWait() Function. –  Swanand Oct 1 '13 at 5:44

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.