AutoCAD Plant 3D provides a command to share a plant project to the ACC cloud: PLANTPROJECTCOLLABORATION.
For more details, refer to To Share a Plant Project to the Cloud.
However, this command poses a challenge for automation, as it requires user interaction. To overcome this limitation, we can use the Plant 3D API to automate the process of sharing the plant project to the cloud.
The code snippet below demonstrates how to upload a Plant3D project to Collaboration for Plant3D asynchronously. The code emits a CLI progress indicator. It takes the hub name, project ID, and folder ID as input parameters.
///
/// Uploads a Plant3D project to Collaboration for Plant3D asynchronously
/// Emits a CLI progress indicator
///
///
///
///
///
public static async Task UploadProjectAsync(
string hubName, string projectId, string folderId)
{
using CancellationTokenSource cts = new();
try
{
// TODO: Add support for Vault and SQL Server projects
PlantProject plantPrj = PlantApplication.CurrentProject;
string projPath = plantPrj.ProjectFolderPath;
// Server login
DocLogIn login = Commands.ServiceLogIn(Commands.CloudServiceName);
if (login == null)
{
Commands.PlantCloudLogin();
login = Commands.ServiceLogIn(Commands.CloudServiceName);
if (login == null) return;
}
// Select Docs Hub and Project
DocA360Project docProject = await Task.Run(() =>
{
var hubs = login.SelectA360Hubs(null, cts.Token);
var hub = hubs?.FirstOrDefault(x => x.A360HubId == hubName);
var projects = hub != null
? login.SelectA360ProjectsFromHub(hub, cts.Token)
: null;
var proj = projects?.FirstOrDefault(x => x.A360ProjectId == projectId);
// Check if the project root is the target folder
if (proj != null && proj.RootFolderUrn == folderId)
return proj; // Return the project itself
// Otherwise, search subfolders
return login.SelectA360ProjectSubFolders(proj, cts.Token)
?.FirstOrDefault(x => x.RootFolderUrn == folderId) ?? proj;
}, cts.Token);
if (docProject == null) return;
// Copy project to CollaborationCache
string destPath = Path.Combine(
Commands.P360WorkingFolder.Trim(), plantPrj.Name);
Utils.BackupProjectFiles(
new DirectoryInfo(projPath), new DirectoryInfo(destPath));
// Convert SQL Server project to SQLite if necessary
var pid = plantPrj.ProjectParts["PnId"];
if (pid?.DataLinksManager.GetPnPDatabase().DBEngine.ToString()
!= PnPDatabase.SQLiteEngineClass)
{
ConvertSQLServerProjectToSQLiteProject(
destPath, plantPrj.Username, plantPrj.Password, cts.Token);
}
plantPrj.Close();
// Load new project
PlantProject prj = PlantProject.LoadProject(
Path.Combine(destPath, "Project.xml"), true, null, null);
// Ensure project structure and collect XRefs
EnsureProjectFoldersExist(prj);
var assoc = CollectXrefs(prj);
// Share project
PnPDocumentServerFactory factory =
PnPDocumentServerFactoryRegistry.GetFactory(
Commands.CloudServiceName);
DocumentServer docsrv = factory.CreateInstance(Guid.NewGuid().ToString());
docsrv.SignIn(login, null);
// Start progress indicator
Task progressTask = ShowProgressAsync(cts.Token);
try
{
PrintMsg("Starting EnableDocumentManagement...");
await Task.Run(() =>
{
prj.EnableDocumentManagement(
docsrv, string.Empty, string.Empty, docProject, assoc, cts.Token);
cts.Token.ThrowIfCancellationRequested();
}, cts.Token);
PrintMsg("EnableDocumentManagement completed successfully.");
}
catch (OperationCanceledException ex)
{
PrintMsg($"Upload canceled: {ex.Message}");
throw;
}
catch (Exception ex)
{
PrintExceptionDetails(ex);
throw;
}
finally
{
cts.Cancel(); // Stop progress
await progressTask;
prj.Close();
}
}
catch (OperationCanceledException)
{
PrintMsg("Upload operation was canceled.");
throw;
}
catch (Exception ex)
{
PrintExceptionDetails(ex);
throw;
}
}
Full source code and a demo working sample Run is provided in Github Project

Leave a Reply to lis tenCancel reply