To solve this problem, we first need to define the decision variables and the objective function. Let's denote the number of model trains as \(T\) and the number of model planes as \(P\). The objective is to maximize profit, which is $7 per model train and $9 per model plane. Thus, our objective function can be written as: Maximize \(7T + 9P\).

The constraints are based on the time available for building and painting. For building, each model train takes 30 minutes, and each model plane takes 40 minutes, with a total of 5000 minutes available. This gives us the constraint \(30T + 40P \leq 5000\). For painting, each model train takes 40 minutes, and each model plane takes 50 minutes, with a total of 6000 minutes available, leading to the constraint \(40T + 50P \leq 6000\).

Additionally, we have non-negativity constraints since the number of model trains and planes cannot be negative: \(T \geq 0\) and \(P \geq 0\).

Here is how this problem can be represented in Gurobi Python code:

```python
from gurobipy import *

# Create a new model
m = Model("Model_Trains_Planes")

# Define the decision variables
T = m.addVar(vtype=GRB.INTEGER, name="model_trains", lb=0)
P = m.addVar(vtype=GRB.INTEGER, name="model_planes", lb=0)

# Set the objective function
m.setObjective(7*T + 9*P, GRB.MAXIMIZE)

# Add constraints
m.addConstr(30*T + 40*P <= 5000, "building_time")
m.addConstr(40*T + 50*P <= 6000, "painting_time")

# Optimize the model
m.optimize()

# Print the solution
if m.status == GRB.OPTIMAL:
    print("Optimal solution found:")
    print(f"Model Trains: {T.x}")
    print(f"Model Planes: {P.x}")
    print(f"Maximum Profit: ${7*T.x + 9*P.x}")
else:
    print("No optimal solution found")
```