Deleting materials and saved file size

Deleting materials and saved file size

nagahhh
Contributor Contributor
434 Views
3 Replies
Message 1 of 4

Deleting materials and saved file size

nagahhh
Contributor
Contributor

Hi there,

 

On family document, I deleted unused materials and saved it through api . But family file size did not reduce as I expected. I tried it by manulal like attached files and result was the same.

Can I reduce the file size somehow? Actually, the number of materials are 100 and file size is over 2MB. 

 

Here is my source code and please find attached file.

 

protected void DeleteUnusedMaterials()
{
Document doc = sData.FamilyDocument;

List<ElementId> MaterialIds = new List<ElementId>();

FilteredElementCollector materialCollector = new FilteredElementCollector(doc);
ICollection<Element> materials = materialCollector.OfClass(typeof(Material)).ToElements();
foreach (Element m in materials)
{
if (m.Name.Contains("ShIP_base"))
{
MaterialIds.Add(m.Id);
}
}

using (Transaction t = new Transaction(doc, "Delete unused materials"))
{
t.Start();
foreach (var id in MaterialIds)
{
doc.Delete(id);
}
t.Commit();
}
}

0 Likes
Accepted solutions (1)
435 Views
3 Replies
Replies (3)
Message 2 of 4

RPTHOMAS108
Mentor
Mentor

The files you highlighted in the images are nowhere near 2 Mb in size (not even 1 Mb).

 

They are reasonable sizes for family files.

Message 3 of 4

nagahhh
Contributor
Contributor

Hi Richard,

 

Thank you for your reply.

 

Our custormer wants to make the family file size smaller because they design some plans like apartment or condminium which has many same room plans. For instance, a room has a build-in kitchen, and there are 100 rooms in the apartment, total  revit project file will be bigger. 

 

I wonder why the file size does not decrease even after the materials are deleted. it seems that some information of deleted materials are stile remain in the saved file even after I delete materials on material dialog. 

 

I have attached family template files. I use ShIP.rft in my add-in.

I made ShIP.rft from 一般モデル(メートル単位).rft(Generic Model of japanese version).

 

The filr size of the original one(一般モデル(メートル単位).rft) is only 396KB, and that of deletet materials file is still 2040KB. Why? 

 

 

0 Likes
Message 4 of 4

nagahhh
Contributor
Contributor
Accepted solution

I have got solution for this problem.

You can reduce family file size about 2MB.

Here is my source code.

I hope this helps you.

 

// Load family
LoadFamilyUnified();

 

// Reduce file size

ReduceFileSize();

 

// Reload family
LoadFamilyUnified();

 

public void LoadFamilyUnified()
{
Family family;
Document doc = sData.CommandData.Application.ActiveUIDocument.Document;

Transaction transaction = new Transaction(doc, "Load family");
try
{
transaction.Start();
SFamilyLoadOption sFamilyLoadOption = new SFamilyLoadOption();
bool loadSucess = doc.LoadFamily(sData.FamilyFileName, sFamilyLoadOption, out family);
transaction.Commit();
if (!loadSucess)
{
TaskDialog.Show("ShIP", "Faled to load family");
}

sData.FamilyUnified = family;
}
catch (Exception e)
{
string msg = e.Message + "\n" + e.StackTrace;
TaskDialog.Show("Exception", msg);
transaction.RollBack();
}

}

 

protected virtual void ReduceFileSize()
{
Document familyDoc = sData.FamilyDocument;
Document doc = sData.CommandData.Application.ActiveUIDocument.Document;
var family = sData.FamilyUnified;

 

Document docfamily = doc.EditFamily(family);

SaveAsOptions options = new SaveAsOptions();
options.OverwriteExistingFile = true;
docfamily.SaveAs(sData.FamilyFileName, options);
}

0 Likes