function [value, status] = evalinModel(model,evalStr)
    
    %   Copyright 2014 The MathWorks, Inc.
    value = [];
    status = true;
    
    modelWS = get_param(model,'ModelWorkspace');
    % Evaluate in model workspace, be careful of setting model dirty state
    sDirty = get_param(modelWS.ownerName,'Dirty');
    try
        % Model workspace variable. Evaluate in model workspace.
        value = modelWS.evalin(evalStr);
    catch E %#ok<NASGU>
        status = false;
    end
    set_param(modelWS.ownerName,'Dirty',sDirty);
    
    % Evaluate in global scope
    if ~status
        try
            value = evalinGlobalScope(model,evalStr);
            status = true;
        catch
            status = false;
        end
    end
end