Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CreateNewLocal API

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
pmeigneux
1127 Views, 9 Replies

CreateNewLocal API

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;

                    }

 

9 REPLIES 9
Message 2 of 10
jeremytammik
in reply to: pmeigneux

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

Message 3 of 10
Anonymous
in reply to: jeremytammik

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

Message 4 of 10
jeremy_tammik
in reply to: Anonymous

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
Message 5 of 10
pmeigneux
in reply to: pmeigneux

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.

Message 6 of 10
jeremy_tammik
in reply to: pmeigneux

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
Message 7 of 10
RPTHOMAS108
in reply to: pmeigneux

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
in reply to: RPTHOMAS108

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

Message 9 of 10
jeremy_tammik
in reply to: Anonymous

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
Message 10 of 10
Anonymous
in reply to: jeremy_tammik

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.

Post to forums  

Autodesk Design & Make Report