Central Model

Central Model

stephen_harrison
Advocate Advocate
1,261 Views
7 Replies
Message 1 of 8

Central Model

stephen_harrison
Advocate
Advocate

First a little background I am using Revit 2018 and programming in C#.

I have developed an app to upgrade central models whilst retaining/updating links, however I would like to first perform a test to ensure the Central model is safe to upgrade without the loss of any data that may snot have been synchronized back to the central model.

Is this possible?

If so can you please point me in the right direction, any code examples would be much appreciated.

If not possible is there a more appropriate test I could undertake?

Thank you in advance for your assistance.

0 Likes
1,262 Views
7 Replies
Replies (7)
Message 2 of 8

stephen_harrison
Advocate
Advocate

Update

It would appear that testing the local models utilising:

BasicFileInfo.Extract(file path for Local Model).AllLocalChangesSavedToCentral does return bool if model changes have been Synchronized with the central model or not.

 

This now leaves me with the question of how to get the Local Model paths from the central model?

 

Any assistance much appreciated.

0 Likes
Message 3 of 8

stephen_harrison
Advocate
Advocate

UPDATE

Further to my last update I have had no success in finding a reference to Local Model paths within the Central Mode.

The more I have reflected upon this the more I realise it was highly unlikely this was a viable solution.

 

Therefore I am back to the beginning:

Is there a method to check the central model is up to date, all Local Models are synchronized back to the central model?

If so can you please point me in the right direction, any code examples would be much appreciated.

If not possible is there a more appropriate test I could undertake before upgrading the central model.

 

Any help much appreciated.

0 Likes
Message 4 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @stephen_harrison ,

 

try using these methods

https://www.revitapidocs.com/2020/67bb59c4-77cf-7cb4-d289-489ba85e09b2.htm 

https://www.revitapidocs.com/2016/7de73a7b-68f0-87f2-f6a9-97d824024877.htm 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 8

FAIR59
Advisor
Advisor

So basically you need to check if an Element is still "Borrowed" in the central model. I'm not aware of an API method you can call for all elements in one go. You'll need to open a (new) local file and check for each element your self.

 

private bool AreAllElementsRelinquished(Document doc)
{
	WorksetTable table = doc.GetWorksetTable();
	IList<WorksetPreview> wInfo =  WorksharingUtils.GetUserWorksetInfo(doc.GetWorksharingCentralModelPath());
	foreach(WorksetPreview info in wInfo)
	{
		if (!string.IsNullOrWhiteSpace( info.Owner)) return false;
	}
	IEnumerable<Element> types = new FilteredElementCollector(doc)
				.WhereElementIsElementType();
	foreach(Element e in types)
	{
		CheckoutStatus st = WorksharingUtils.GetCheckoutStatus(doc,e.Id);
		if(st != CheckoutStatus.NotOwned) return false;
	}
	IEnumerable<Element> elems = new FilteredElementCollector(doc)
		.WhereElementIsNotElementType();
	foreach(Element e in elems)
	{
		CheckoutStatus st = WorksharingUtils.GetCheckoutStatus(doc,e.Id);
		if(st != CheckoutStatus.NotOwned) return false;
	}
	return true;
}
0 Likes
Message 6 of 8

Moustafa_K
Collaborator
Collaborator

Hi,

have you tried: (not sure if this is what you are looking for?

var bf = BasicFileInfo.Extract(FilePath);
if (bf.IsCentral && !bf.AllLocalChangesSavedToCentral )
					{
						// "Ignored central file due to unsaved changes"						 
					}
Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 7 of 8

stephen_harrison
Advocate
Advocate

Thank you for the responces.

As I understand it and my initial tests would  lead me to believe this is correct, that utilising:

 

BasicFileInfo.Extract(file path for Local Model).AllLocalChangesSavedToCentral always returns true when utilised on the Central Model. This does however return the appropriate true or false result when utilised on the LocalModel.

 

As for "HasAllChangesFromCentral" and "SynchronizeWithCentralOptions"  these again are for utilisation on the LocalModel.

 

I am leaning towards the fact that the only solution available is to create a local model and check if each element is borrowed. The down side to this is how resource intensive the process can be.

 

The most efficient solution I believe would be if the central model  could some how store the location of the Local Models so that BasicFileInfo.Extract(file path for Local Model).AllLocalChangesSavedToCentral could be utilised.

 

Again, thankyou for your responses.

 

0 Likes
Message 8 of 8

Moustafa_K
Collaborator
Collaborator

hmmm.. well let's think a bit out of programming.

Practically you will not upgrade a central model without :

  1. asking the entire team to synchronize their work
  2. assuming the project is life and running, upgrading a shared model for architecture will also require the rest of disciplines. which means they all for each need to synchronize their works
  3. assuming the project is closed and you are only upgrading for the purpose of keeping the revit files upto score, then there is no need to sync local files as there is no one already working on.

by then you can use the api to upgrade the model.

 

another possible one which i do not recommend is to ask your team to copy their local files to a single shared one and loop through them all for syncing and then upgrade the central model. 

 

thoughts?

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes