.NET

.NET

Reply
Active Contributor
Fredrik.Larsen
Posts: 46
Registered: ‎11-28-2012
Message 1 of 10 (785 Views)

Can I cache files manually? Faster xref when file cached

785 Views, 9 Replies
01-15-2013 03:48 AM

Hi

 

I have noticed that a file is xrefed much faster if the file has been opened at some point. (Wtih the file I tested with it was 45 sec vs 1,5 sec) This must mean that the file is cached and can very quickly opened later if it has been opened.

 

I have an application that xref other files as overlay xref's. This is very slow since the xrefed files haven't been opened. And it will be this slow every time i xref them since they are never opened. Is there a way I can cache the files manually or something like that?

ADN Support Specialist
Balaji_Ram
Posts: 694
Registered: ‎03-21-2011
Message 2 of 10 (751 Views)

Re: Can I cache files manually? Faster xref when file cached

01-22-2013 08:59 AM in reply to: Fredrik.Larsen

Hello Fredrik,

 

Sorry, I could not reproduce this behavior. Can you please let me if there is anything different from what I have been trying ?

 

Trial 1 :

Started AutoCAD 2013

Attached a large drawing as an overlay xref and timed it at 25 seconds.

Closed AutoCAD

 

Trial 2:

Started AutoCAD 2013

Opened the large drawing

Created a new drawing and attached the large drawing as an overlay xref and timed it. It was roughly the same (~ 25 seconds)

 

Please let me know the exact steps to reproduce this behavior.

 



Balaji
Developer Technical Services
Autodesk Developer Network

Active Contributor
Fredrik.Larsen
Posts: 46
Registered: ‎11-28-2012
Message 3 of 10 (737 Views)

Re: Can I cache files manually? Faster xref when file cached

01-23-2013 01:19 AM in reply to: Balaji_Ram

Hi

Are you sure the large drawing has never been opened on your machine before?

 

What I did, Step1:

I received a drawing from a coworker. Attached drawing as an overlay xref, timed it to 45 seconds. Closed AutoCAD

 

Step 2:

Opened the drawing. Closed AutoCAD

 

Step 3:

Opened empty file and attached drawing as overlay xref. Timed it to 1,5 seconds.

 

I think I found out why. AutoCAD generates "cached" files of some sort in C:\users\<user>\AppData\Local\Temp. Maybe that is why it can open it so fast if it has opened it before. 

 

This affects my program that xrefs files. A scenario is that the drawings that are going to be xrefed are on a network location, and will only be xrefed by the users of my program.

Moderator
Alexander.Rivilis
Posts: 1,406
Registered: ‎04-09-2008
Message 4 of 10 (732 Views)

Re: Can I cache files manually? Faster xref when file cached

01-23-2013 02:05 AM in reply to: Fredrik.Larsen

Maybe this is normal Windows / HDD cache?


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Active Contributor
Fredrik.Larsen
Posts: 46
Registered: ‎11-28-2012
Message 5 of 10 (715 Views)

Re: Can I cache files manually? Faster xref when file cached

01-24-2013 05:34 AM in reply to: Alexander.Rivilis

Hi again, I coworker of mine found this:

"

File format

New file format "AutoCAD 2013 Drawing" is used.

AutoCAD 2013 introduces a new file format that includes changes to the thumbnail preview file format, as well as new controls for graphics caching.
Thumbnail previews in the new AutoCAD 2013 DWG file format are now stored as PNG images, providing higher-quality thumbnail previews in a smaller file size. Image resolution is still controlled by the THUMBSIZE system variable. However, the maximum valid value has increased from 2 to 8. If you do not wish to include thumbnail previews in the drawing you can still use the RASTERPREVIEW system variable (or the new THUMBSAVE) to disable them. Note that only 3D drawings make use of a larger thumbnail. The UPDDATETHUMBSNOW and UPDATETHUMBNAIL system variables are no longer needed and have been removed from AutoCAD 2013.

When you save a drawing containing 3D Solids in the new AutoCAD 2013 file format, a graphics cache file is automatically stored in a folder named “GraphicsCache” under your user app data folder. Two new system variables, CACHEMAXTOTALSIZE and CACHEMAXFILES, enable you manage the cache files."

"

 

I am not sure how to use this information about the system variables. The simple thing i was thinking was to write a function that opens all dwg-files and closes them to read them to cache. Is this the best way?

 

I am having som trouble doing this. In the code under the document I open does not seem to be put as active document and if I set it as active document my function stops. 

 

public static void OpenAllFiles(string[] files)
        {
            foreach (string file in files)
            {
                bool opened = OpenFile(file);
                bool closed = CloseFile();
            }
        }

public static bool CloseFile()
        {
            DocumentCollection acDocMgr = AcadApp.DocumentManager;
            try
            {
                acDocMgr.MdiActiveDocument.CloseAndDiscard();
                return true;
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                return false;
            }
        }

        public static bool OpenFile(string strFileName)
        {
            DocumentCollection acDocMgr = AcadApp.DocumentManager;
            if ((File.Exists(strFileName)))
            {
                Document newDoc = acDocMgr.Open(strFileName, false);
                return true;
            }
            else
            {
                return false;
            }
        }

 

ADN Support Specialist
Balaji_Ram
Posts: 694
Registered: ‎03-21-2011
Message 6 of 10 (689 Views)

Re: Can I cache files manually? Faster xref when file cached

02-01-2013 07:56 AM in reply to: Fredrik.Larsen

Hi Fredrik,

 

Sorry for the delay.

 

Have you tried setting the "CACHEMAXFILES" to 0 ? This will ensure that AutoCAD does not perform the caching of the files. The behavior will then be like that of AutoCAD 2012 when we did not have such caching of drawings.

 

Regarding your query on opening all the drawings and ensuring that they get cached, it is possible but I am not sure if that is the best way. I will enquire with the engineering team and will let you know if there is a better way to do that.

 

Here is a sample code to open a set of drawings and close them without saving. The drawings seem to be getting cached.

 

[CommandMethod("Test", CommandFlags.Session)]
public void TestMethod()
{
    string[] files = { "C:\\Temp\\1.dwg", "C:\\Temp\\2.dwg" };

    try
    {
        foreach (String file in files)
        {
            if (!File.Exists(file))
                continue;

            Document doc = Application.DocumentManager.Open(file);

            doc.CloseAndDiscard(); 
        }
    }
    catch (System.Exception ex)
    {
        Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.Message);
    }
}

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Active Contributor
Fredrik.Larsen
Posts: 46
Registered: ‎11-28-2012
Message 7 of 10 (682 Views)

Re: Can I cache files manually? Faster xref when file cached

02-01-2013 12:49 PM in reply to: Balaji_Ram

Hi

 

Thanks for the answer. 

 

Have you tried setting the "CACHEMAXFILES" to 0 ? This will ensure that AutoCAD does not perform the caching of the files. The behavior will then be like that of AutoCAD 2012 when we did not have such caching of drawings.

 I do not want to set "CACHEMAXFILES" to 0. I want the files to be cached. This ensures that my application can xref the files very fast.

 

I will use the code you posted unless a better solution appears.

Active Contributor
Fredrik.Larsen
Posts: 46
Registered: ‎11-28-2012
Message 8 of 10 (655 Views)

Re: Can I cache files manually? Faster xref when file cached

02-06-2013 01:22 AM in reply to: Balaji_Ram

Hi again

 

Your code for openening and closing all files works allmost fine. The program stops if I run your function right after opening AutoCAD.

 

 

The reason seems to be that when you open an existing drawing when you've just opened AutoCAD the unsaved "Drawing1.dwg" that always shows up when opening AutoCAD is closed. So when I close the first drawing I opened no drawings are open anymore and the function stops.

 

It seems to work fine if you have done something with "Drawing1.dwg" or opened another drawing first since it will not be closed when opening a new drawing. 

 

Any ideas to handle this situation?

Employee
artc2
Posts: 206
Registered: ‎06-08-2010
Message 9 of 10 (643 Views)

Re: Can I cache files manually? Faster xref when file cached

02-06-2013 09:19 AM in reply to: Fredrik.Larsen

In case you weren't aware, the graphics cache is only of the solids data.  No other entity types have their graphics cached in the cache file.

ADN Support Specialist
Balaji_Ram
Posts: 694
Registered: ‎03-21-2011
Message 10 of 10 (626 Views)

Re: Can I cache files manually? Faster xref when file cached

02-07-2013 03:44 PM in reply to: Fredrik.Larsen

Thanks Art. Some of the drawings that I originally used while trying to reproduce the increase in Xref time did not have solids in them, which now explains why the results that I saw werent consistent. 

 

Fredrik,

How about using the accoreconsole.exe to have the drawings cached ?

 

1) Create a simple script file with "(princ "Done")"

  The script file does not perform any actual task.

 

2) Run AccoreConsole.exe and provide the drawing path and the script file path

    accoreconsole.exe /i "C:\Temp\Torus.dwg" /s "C:\Temp\Test.scr" /l en-US

 

I did find a new file getting created under "%appdata%\Autodesk\AutoCAD 2013 - English\R19.0\enu\GraphicsCache"

 

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.