Select to view content in your preferred language

Is it possible to start a model directly from an ArcMap-Toolbar?

2233
13
Jump to solution
05-02-2012 09:43 PM
MOHAMMEDHABBOUB
Deactivated User
Hello,

Is it possible to start a model (generated from model builder) directly from an ArcMap-Toolbar? I don't want to start the toolbox just for one frequently used tool.
I have 9.3 edition

thanks 🙂
0 Kudos
1 Solution

Accepted Solutions
MOHAMMEDHABBOUB
Deactivated User
Hello everybody,

I found a solution for this problem.. in fact it's another code (see image) and it works

reference: http://gis.stackexchange.com/questions/4952/run-model-arcmap-9-3-1

View solution in original post

0 Kudos
13 Replies
MOHAMMEDHABBOUB
Deactivated User
Anyone can help?
0 Kudos
DanLee
by Esri Regular Contributor
Esri Regular Contributor
The capability of adding your own toolbar and tools (models, scripts, or system tools) is in ArcGIS 10, but not in 9.3. What you can do is to create your own toolbox and add any of the above tools to it. This video shows how:
http://webhelp.esri.com/arcgisdesktop/9.2/tutorials/Spatial_10.htm

Hope that helps.
0 Kudos
MOHAMMEDHABBOUB
Deactivated User
Hi,
I have wrote this code, but an error appears (see image):

Option Explicit
Private Sub UIButtonControl1_Click()
Public Sub Test()



  Dim pGP As Object

  Set pGP = CreateObject("esriGeoprocessing.GPDispatch.1")



On Error GoTo EH

pGP.AddToolbox ("D:\DRASTIC_MODEL.tbx")



  pGP.MyModel



  Exit Sub

EH:

  MsgBox pGP.GetMessages(), vbOKOnly, "Test"

End Sub


End Sub


reference: http://support.esri.com/en/knowledgebase/techarticles/detail/31110


Anyone can help?
0 Kudos
NobbirAhmed
Esri Regular Contributor
You need to have two Sub or all the code in the Click event. Try this:

First, the Click event method:
Private Sub UIButtonControl1_Click()
    ' Call the Test method
    Test()
End Sub



The second method (Test) is the worker method:
Public Sub Test()
    ' Put all code here
    Dim pGP as Object
    ......
    .....
    EH:
    MsgBox pGP.GetMessages(), ......
End Sub



Let us know how it goes.
0 Kudos
MOHAMMEDHABBOUB
Deactivated User
Hi,

Well, I'm not sure that I did it right..

In the first method, I did not get it (how could I call test() method?)... see image "FirstMethod"
In second method, EH error appeared ... see image"Secondmethod"

I know that I'm  beginner in VB codes... but I have to learn
 
Thanks in advance
0 Kudos
NobbirAhmed
Esri Regular Contributor
Your whole code should like this:


Option Explicit

Private Sub UIButtonControl1_Click()
    ' Call the Test method
    Test()
End Sub

Public Sub Test()
    Dim pGP as Object
    Set pGP = CreateObject("esriGeoprocessing.GPDispatch.1")

    On Error GoTo EH
    pGP.AddToolbox ("D:\DRASTIC_MODEL.tbx")
    pGP.MyModel
    MsgBox pGP.GetMessages(), vbOkOnly, "Success"
    Exit Sub

EH:
    MsgBox pGP.GetMessages(), vbOkOnly, "Error"

End Sub


Let us know what message do you get?
0 Kudos
MOHAMMEDHABBOUB
Deactivated User
error in "Test()" illustrated in image
0 Kudos
NobbirAhmed
Esri Regular Contributor
I don't have a VBA compiler right now. If you google with 'how to call a VB sub' you'll get plenty of examples. I guess the call to Test sub should be:

Private Sub UIButtonControl1_Click()
    Test
End Sub
Without the braces '(' and ')'.
0 Kudos
MOHAMMEDHABBOUB
Deactivated User
yes that's right, now both solutions (method 1 and 2) give the same result
0 Kudos