Hello,
I am trying to use CreateNewLocal to create a local file from a central file.
Unfortunately, the results of the creation is a new central file on the new target path and not a local file.
Here is a sample of the code. Could you take a look and let me know if something is wrong.
Thanks,
ModelPath sourcePath = ModelPathUtils.ConvertUserVisiblePathToModelPath("c:\temp\Central Model.rvt");
String targetName = "c:\temp\Central Model" + "_" + uiapp.Application.Username + ".rvt";
ModelPath targetPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(targetName);
try
{
WorksharingUtils.CreateNewLocal(sourcePath, targetPath);
BasicFileInfo basicfileinfo = BasicFileInfo.Extract(targetName);
if (basicfileinfo.IsCentral)
{
TaskDialog.Show("Debug", "IsCentral");
}
if (basicfileinfo.IsLocal)
{
TaskDialog.Show("Debug", "IsLocal");
}
}
catch (Autodesk.Revit.Exceptions.CentralModelAccessDeniedException e)
{
TaskDialog.Show(EnoviaAddPanel.ErrorText, "Create = " + e.Message);
break;
}
catch (Autodesk.Revit.Exceptions.CentralModelContentionException e)
{
TaskDialog.Show(EnoviaAddPanel.ErrorText, "Create = " + e.Message);
break;
}
catch (Autodesk.Revit.Exceptions.CentralModelException e)
{
TaskDialog.Show(EnoviaAddPanel.ErrorText, "Create = " + e.Message);
break;
}
catch (Autodesk.Revit.Exceptions.FileArgumentAlreadyExistsException e)
{
TaskDialog.Show(EnoviaAddPanel.ErrorText, "Create = " + e.Message);
break;
}
catch (Autodesk.Revit.Exceptions.RevitServerCommunicationException e)
{
TaskDialog.Show(EnoviaAddPanel.ErrorText, "Create = " + e.Message);
break;
}
catch (Autodesk.Revit.Exceptions.RevitServerInternalException e)
{
TaskDialog.Show(EnoviaAddPanel.ErrorText, "Create = " + e.Message);
break;
}
Solved! Go to Solution.
Solved by jeremy_tammik. Go to Solution.
Dear Pierre,
Thank you for your query.
I have asked the developer team for you.
Cheers,
Jeremy
Thank you for raising this again. Pierre, did you find a solution? I never heard back from the development team on this. I raised the issue with them again and hope for a better result this time around.
No, I haven't found a solution yet. I left this part of my project on hold and work on another while waiting for a reponse.
Thank you for the info. OK, let's hope that the devteam can help.
They may ask for a reproducible case. That is normally the first step:
https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b
Then they can also check your code.
There was this post recently where it was stated that the .IsLocal read incorrectly until the file is saved (BasicFileInfo not updated until first saving). This could be related to that but if WorksharingUtils.CreateNewLocal is not updating this then I don't know what distinguishes it from just copying the file via other means?
https://forums.autodesk.com/t5/revit-api-forum/iscentral-islocal/m-p/10019279/highlight/true#M52728
What are we trying to achieve with WorksharingUtils.CreateNewLocal. Is this method intended to prevent the warning dialogue that the file has been copied from central and will become a new local when saved? Or is it more to do with copying central file into a local from remote servers?
@RPTHOMAS108 yup you're definitely right! I just tried it on my side and saving does the trick.
Just as a reference, here is what I've done for testing:
// Open the document
UIDocument localUiDocument = uiApplication.OpenAndActivateDocument(localFileName);
// Save document to update IsLocal property
localUiDocument.Document.Save();
BasicFileInfo i = BasicFileInfo.Extract(localFileName);
bool cent = i.IsCentral;
bool loc = i.IsLocal;
And, after saving, the booleans are correct:
cent = false
local = true
Thanks mate!
So, do you mean that you simply have to call Save after the CopyToLocal call?
Apparently yup, after the CreateNewLocal call.
I tried to edit my reply above as I missed an important part of the code, but couldn't. Doing it here:
// Create new local file
WorksharingUtils.CreateNewLocal(sourceFile, targetFile);
// Open the document
UIDocument localUiDocument = uiApplication.OpenAndActivateDocument(localFileName);
// Save document to update IsLocal property
localUiDocument.Document.Save();
BasicFileInfo i = BasicFileInfo.Extract(localFileName);
bool cent = i.IsCentral;
bool loc = i.IsLocal;
Although, it seems that saving the document so that the IsLocal property update to true is merely a formality.
I tried without saving the file and, although the IsLocal property is false (and IsCentral is true), the actual document in Revit shows the correct connection to the correct central file (under the Collaboration tab in the sync options).
I hope this makes sense.
Can't find what you're looking for? Ask the community or share your knowledge.