Revit secondary development solution

According to the current program, there are several points improvement
1 log after each revit generated, it will not del, the next generation again, I found the log, would not be generated. The name of the log using the modified time stamp, each time running to generate separate log file.

Sample Code

string date = DateTime.Now.ToLongDateString().ToString() + DateTime.Now.ToLongTimeString();
date = date.Replace(":", "_");
roller.File = @"EventLogByrevit" + date + ".txt";

The code in log.cs in. Execution revit of command. This method is useful when debugging.

2 Model class, each time adding a drop of the original library, rebuild a separate library.
Increase in the Model class constructor

Database.SetInitializer <m member> (new DropCreateDatabaseAlways <m member> ());

3 DB field to add a time and see what time the saved data.

4 DB field added a file name, the file name is the full file name, so setting this property in the class time, to keep about 1,000 characters. Otherwise, the individual will be very long, while keeping the error.

5, when held, because to build more, from the website to build
on Negut console, execute the following command
Install-Package Z.EntityFramework.Extensions -Version 3.22.6
will install an Extension, it supports batch maintained.

6 is still very large amounts of data, then the data will be divided as a unit 10000, a method may reference points

     List<Entity.e构件实体> templist = new List<Entity.e构件实体>();
                       int separate = 10000;
            int mod整数 = count / separate;
            int mod余数 = count % separate;

            for (int j = 1; j <= mod整数; j++)
            {
                templist.AddRange(l构件实体列表.Skip((j-1) * separate).Take(separate));
                m.d构件实体数据处理.AddRange(templist);
                m.BatchSaveChanges();
                templist.Clear();
            }
            if (mod余数 != 0)
            {
                templist.AddRange(l构件实体列表.Skip(mod整数 * separate).Take(mod余数));
                m.d构件实体数据处理.AddRange(templist);
                m.BatchSaveChanges();
                                    templist.Clear();
            }
            Common.utility.WriteDebugLog("数据库存储结束,采用了batchsavechange的方法。");

Divided into 10 000 holds as a unit.

7 To facilitate discovery problems, increase the recording place in the system log, using
Common.utility.WriteDebugLog (string.Format ( "{0} is processing a file, the file name is {1}, {2} a total of files \ r \ n ", i, filename, filenameList.Count ()));
this format, the better.

8 execute all revit files in a directory in Revit.
Revit open a file, run the plug-in.
This plug-in following a start code
String @ path = "D: \. 1";
String [] = filenameList the Directory.GetFiles (path, "* .rvt", SearchOption.AllDirectories);

        app = commandData.Application.Application;
        Document doc;
        foreach (var x in filenameList)
        {
            Common.utility.WriteDebugLog(string.Format("个文件,文件名是{0}\r\n",x));
        }
        int i = 1;
        foreach (var filename in filenameList)
        {
            Common.utility.WriteDebugLog(string.Format("正在处理第{0}个文件,文件名是{1},一共有{2}个文件\r\n",i,filename, filenameList.Count()));
            i++;

9 ui的地方抽象一个类出来,将每个文档的处理逻辑放入到单独的一个类中

Guess you like

Origin blog.51cto.com/14540194/2437564