Jump to content
Sign in to follow this  

Inserting a script in Model-Builder ArcGIS

Recommended Posts

Hello all,

I am looking for some tips about inserting a script in the model-builder...

I am actually building a model in the Arc-GIS model-builder. At one point I would like to insert a script that crosses information from two layers at one point of the model with a output layer, that will be used further along.

In Arcmap, I added the script with a right-click in my toolbox > add script...

After loading my script, I applied the following parameters:

-Two inputs, referring my layers that I use in the script (raster layer type) - One output, for the result (raster layer type)

I then go to my model and drag my script into it. I connect my two layers as inputs with the arrow and specify the output file name. All seems ok as the boxes appear with the correct colors.

I have to specify that I am working with a variable folder %folder% so I added that in my script.

When I validate my model it goes all blank, because it cannot find the input layers, as they are created in the model.

Can anybody help me please?

PS: Here is my script:

# ---------------------------------------------------------------------------
# calculator.py
# Created on: 2012-11-15 16:59:11.00000
# (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------[/background][/font][/color]
# Import arcpy module
import arcpy
# Check out any necessary licenses

# Local variables:
raster = "%Dossier%\Erosion.gdb\raster"
# Process: Calculatrice raster
arcpy.gp.RasterCalculator_sa("Con((\"%Surf_Drainee%\" > 12) & (\"%Surf_Drainee%\" <= 80) & (\"%Pente_Rclass%\" <= 24), \"%Pente_Rclass%\" + 1, Con((\"%Surf_Drainee%\" > 80) & (\"%Pente_Rclass%\" < 24), \"%Pente_Rclass%\" + 2, Con((\"%Surf_Drainee%\" > 80) & (\"%Pente_Rclass%\" == 24), \"%Pente_Rclass%\" + 1, \"%Pente_Rclass%\")))", raster)

Share this post

Link to post
Share on other sites

Try these,

-place the raster outside gdb and call the full name with extension (ie- raster.tiff)

-try the script on different raster layer without variable folder declaration and check if it works

-check if everything is ok with the raters (ie - projection).

Share this post

Link to post
Share on other sites

@ Maxsigma

If you still have the problem, can help in this regards.

In my first look, I guess you have problem in defining path. Use "\\" or "/" instead of "\" like: "c:\\Temp\\Demo.gdb\\raster" or "c:/Temp/Demo.gdb/raster" etc.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.