Project Files

Project Files
This container holds Files registered with the File Manager.

Methods

GetFiles

Gets all the File References that are associated with the specified container.

Return     The set of file references associated with the container.
    Type     DataReferenceSet
Example

This example prints the location of files for two different components of a system.

    system1 = GetSystem(Name="Static1")
    geometry1 = system1.GetContainer(ComponentName="Geometry")
    for fileRef in geometry1.GetFiles():
       print fileRef.Location 
    >>> C:\Users\myUser\Projects\static1_files\dp0\SYS\DM\SYS.agdb
    >>> E:\data\Models\pipe.x_t
    model1 = system1.GetContainer(ComponentName="Model")
    for fileRef in model1.GetFiles():
       print fileRef.Location
    >>> C:\Users\myUser\Projects\static1_files\dp0\global\MECH\SYS.engd
    >>> C:\Users\myUser\Projects\static1_files\dp0\global\MECH\SYS.mechdb


Data Entities

FileReference

The data entity that represents a file that is part of the project.

Properties

Directory

A string that contains the path to the directory containing the file.

Type     string
Read Only    Yes
DisplayText

The general property that defines the user-visible name of an entity. This property is defined for all data entities but is used only in those entities that present a label in the user interface.

Type     string
Read Only    No
Exists

A value indicating whether the file exists.

Type     bool
Read Only    Yes
FileName

The name of the file, including the extension.

Type     string
Read Only    Yes
LastModifiedTime

The time at which this file was most recently modified.

Type     DateTime
Read Only    Yes
Location

The full path to the local file including the directory and file name.

Type     string
Read Only    No
Size

The size of the file in bytes.

Type     long
Read Only    Yes

Methods

Copy

Copies a file to a target directory.

Return     A reference to the created file is returned in this argument.
    Type     DataReference

Required Arguments

DestinationDirectoryPath    The full path to the destination directory.
    Type     string
Overwrite    Specifies whether to overwrite an existing files of the same name. Note: A registered file may not be overwritten.
    Type     bool
Example

The following example illustrates proper CopyFileByReference command invocation:

    fileRef = GetRegisteredFileQuery(FilePath=r"path_to_file")
    fileRefCopy = fileRef.Copy(DestinationDirectoryPath=r"path_to_copy_file", Overwrite=True, CopyReferenceCount=False)

Delete

Deletes the specified file

Optional Arguments

BackUp    Specifies whether to back up the file before deletion. This optional argument's default value is true.
    Type     bool
    Default Value    True
DeleteIfShared    Specifies whether a registered file should be deleted even if it is still in use. This optional argument's default value is true. If this argument's value is false, an exception will be thrown if a shared file is encountered. To avoid the exception, set ErrorIfShared to false.
    Type     bool
    Default Value    False
ErrorIfShared    Specifies whether to throw an exception when trying to delete a shared file if DeleteIfShared is set to false.
    Type     bool
Example

The following example illustrates a deletion of a registered file via a file reference. The file will be deleted if even if it is still in use. Note that the file will be backed up.

    fileRef = GetRegisteredFile(FilePath=r"C:\Users\anyuser\path-to-file.extension")
    fileRef.Delete(DeleteIfShared=True,
                   BackUp=True)

The next example illustrates a deletion of a registered file via a file reference without a forced deletion. If the file is shared, an error will not occur, and the file reference count will be decremented.

    fileRef = GetRegisteredFile(FilePath=r"C:\Users\anyuser\path-to-file.extension")
    fileRef.Delete(ErrorIfShared=False)

Move

Moves a file to a new directory.

Required Arguments

NewDirectoryPath    The full path to the destination directory.
    Type     string

Optional Arguments

BackUp    Specifies whether to back up the file before the move. This optional argument's default value is true.
    Type     bool
    Default Value    True
Example

The following example illustrates proper MoveFileByReference command invocation:

    fileRef = GetRegisteredFileQuery(FilePath=r"path_to_file")
    fileRefCopy = fileRef.Move(NewDirectoryPath=r"path_to_move_file", Backup=False)

Rename

Renames a file.

Required Arguments

NewName    The new file name, excluding the directory path. To change the directory, see MoveFileCommand.
    Type     string

Optional Arguments

BackUp    Specifies whether to back up the file before renaming it. This optional argument's default value is true.
    Type     bool
    Default Value    True
Example

The following example illustrates proper RenameFileByReference command invocation:

    fileRef = GetRegisteredFileQuery(FilePath=r"path_to_file")
    fileRefCopy = fileRef.Rename(NeName="new_file_name", BackUp=True)

Repair

Repairs a file that is referenced in the project but cannot be found on disk. If the file is expected to be found under the project directory, then this command will copy the new file to the expected location rather than link to the new file in its current location. Use SetFilePathCommand to link to a file in a new location.

Required Arguments

FilePath    A full path to the file in its updated location.
    Type     string