def create_datafile_object(plexosfile, datafilename, datafilepath, copyfileto=''):
    if not os.path.exists(plexosfile):
        raise Exception('"{}" does not exist'.format(plexosfile))
        
    if not copyfileto == '':
        if os.path.exists(copyfileto):
            os.remove(copyfileto)
        copyfile(plexosfile, copyfileto)
        plexosfile = copyfileto
        
    # Create an object to store the input data
    db = DatabaseCore()
    db.Connection(plexosfile)

    # Add a scenario
    '''
    Int32 AddObject(
    	String strName,
    	ClassEnum nClassId,
    	Boolean bAddSystemMembership,
    	String strCategory[ = None],
    	String strDescription[ = None]
    	)
    '''
    db.AddObject(datafilename, ClassEnum.DataFile, True)

    # Create data and tag it with the scenario
    '''
    Int32 AddProperty(
    	Int32 MembershipId,
    	Int32 EnumId,
    	Int32 BandId,
    	Double Value,
    	Object DateFrom,
    	Object DateTo,
    	Object Variable,
    	Object DataFile,
    	Object Pattern,
    	Object Scenario,
    	Object Action,
    	PeriodEnum PeriodTypeId
    	)
    '''
    # alias
    add_prop = db.AddProperty[Int32,Int32,Int32,Double,Object,Object, \
                              Object,Object,Object,Object,Object,PeriodEnum]
    
    # parameters
    mem_id = db.GetMembershipID(CollectionEnum.SystemDataFiles, 'System', datafilename)
    enum_id = int(SystemDataFilesEnum.Filename) 
    
    # we'll add three property rows... monthly gas prices for 3 months
    params = [(mem_id, enum_id, 1, 0, None, None, None, datafilepath, None, None, None, PeriodEnum.Interval),]
    
    # invoke
    for p in params:
        add_prop.__invoke__(p)
    
    # Add the scenario to a model
    '''
    Int32 AddMembership(
    	CollectionEnum nCollectionId,
    	String strParent,
    	String strChild
    	)
    db.AddMembership(CollectionEnum.ModelScenarios, 'Q1 DA', scenario)
    '''
    
    # save the data set
    db.Close()
    
    # pass the plexos file path (.xml) whether copied or not
    return plexosfile
    '''
    if not db.CategoryExists(ClassEnum.Scenario, 'Added by API'):
        db.AddCategory(ClassEnum.Scenario, 'Added by API')

    # Add a scenario
    '''
    Int32 AddObject(
    	String strName,
    	ClassEnum nClassId,
    	Boolean bAddSystemMembership,
    	String strCategory[ = None],
    	String strDescription[ = None]
    	)
    '''
    scenario = 'API{:%Y%m%d%H%M}'.format(datetime.now())
    db.AddObject(scenario, ClassEnum.Scenario, True, 'Added by API')

    # Create data and tag it with the scenario
    '''
    Int32 AddProperty(
    	Int32 MembershipId,
    	Int32 EnumId,
    	Int32 BandId,
    	Double Value,
    	Object DateFrom,
    	Object DateTo,
    	Object Variable,
    	Object DataFile,
    	Object Pattern,
    	Object Scenario,
    	Object Action,
    	String strCategory
    	)
    '''
    db.AddCategory(ClassEnum.Generator, 'API')

    # Add an object (and the System Membership)
    '''
    Int32 AddObject(
    	String strName,
    	ClassEnum nClassId,
    	Boolean bAddSystemMembership,
    	String strCategory[ = None],
    	String strDescription[ = None]
    	)
    '''
    db.AddObject('ApiGen', ClassEnum.Generator, True, 'API', 'Testing the API')

    # Add memberships
    '''
    Int32 AddMembership(
    	CollectionEnum nCollectionId,
    	String strParent,
    	String strChild
    	)
    '''
    db.AddMembership(CollectionEnum.GeneratorNodes, 'ApiGen', '101')
    db.AddMembership(CollectionEnum.GeneratorFuels, 'ApiGen', 'Coal/Steam')
    db.AddMembership(CollectionEnum.ReserveGenerators, 'Spin Up', 'ApiGen')

    # Get the System.Generators membership ID for this new generator
    '''