CreateNewLocal API

CreateNewLocal API

pmeigneux
Advocate Advocate
2,287 Views
9 Replies
Message 1 of 10

CreateNewLocal API

pmeigneux
Advocate
Advocate

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;

                    }

 

0 Likes
Accepted solutions (1)
2,288 Views
9 Replies
Replies (9)
Message 2 of 10

jeremytammik
Autodesk
Autodesk

Dear Pierre, 

 

Thank you for your query.

 

I have asked the developer team for you.

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 10

Anonymous
Not applicable

I have the same exact issue. Any new finding??

0 Likes
Message 4 of 10

jeremy_tammik
Alumni
Alumni

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.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 5 of 10

pmeigneux
Advocate
Advocate

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.

0 Likes
Message 6 of 10

jeremy_tammik
Alumni
Alumni
Accepted solution

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.

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 7 of 10

RPTHOMAS108
Mentor
Mentor

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?

Message 8 of 10

Anonymous
Not applicable

@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!

0 Likes
Message 9 of 10

jeremy_tammik
Alumni
Alumni

So, do you mean that you simply have to call Save after the CopyToLocal call?

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 10 of 10

Anonymous
Not applicable

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.

0 Likes