Author Topic: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?  (Read 4420 times)

0 Members and 1 Guest are viewing this topic.

thenndral

  • Guest
Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« on: April 14, 2014, 03:20:43 AM »
Hi,

Is it possible to Get Create Date and Time without open drawing using GETSYSTEMVARIABLE?
ie. Open drawing in memory and Receive Date and Time.

Give me suggestion.

Thanks,
thenndral

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #1 on: April 14, 2014, 03:45:22 AM »

Would it be simpler to check the file properties using something like

Code - C#: [Select]
  1. DateTime fileCreatedDate = File.GetCreationTime(@"K:\Example\MyTest.dwg");

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

thenndral

  • Guest
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #2 on: April 14, 2014, 05:05:35 AM »
Hi Kerry,

Thanks for your quick reply.

This code retirieve current date and time ie."Drawing1.dwg". It did not get date and time from the path.Please check the image.

Code: [Select]
[CommandMethod("TTS")]
        public void Time_tracking()
        {

            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            DateTime fileCreatedDate = File.GetCreationTime(@"D:\AutoCAD\testing\template.dwg");
            ed.WriteMessage("\nFile selected was \"{0}\".\n", fileCreatedDate);

}


I'm newbie for customization Autocad with using C#. I studying and as well as coding for my project.
Actually I'm Using your previous code from the below link.
http://www.theswamp.org/index.php?topic=41190.msg463482#msg463482

In your previous code working fine but it works after open the drawing then we could able to retrieve Date and time of the opened dwg file.
but my requirement is,
1.  open Drawing contain folder[may be 20 files or more]
2. Get filenames from memory
3. Retrieve file Date and time one by one.

Please give me suggestions.If you have any sample code it will be much appreciated.

Thanks in advance,
thenndral



Jeff H

  • Needs a day job
  • Posts: 6150
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #3 on: April 14, 2014, 12:15:38 PM »
Because TDCREATE is set when a drawing is created from a template.
So guessing will only work for .dwg and not .dwt.

thenndral

  • Guest
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #4 on: April 14, 2014, 09:40:15 PM »
Hi,

Thanks Jeff and Kerry.

I got code from forum, I modify according to my requirement.It's working fine.
Here is the code.

I have some question.

1. How to select folder instead of selecting multiple files. I need to select folder and loop go inside sub-folder[if exists] and check if drawing file exists or not, if exists  then retrieve Date and time.
2. I need to compare date and time for template.dwg[1 file]  with ans_sheet.dwg[ may be more than 20+ files ]. Which is the best method to compare two date and time.
3. How to get milliseconds?
Code: [Select]
AcadApp.ShowAlertDialog("Last Updated:" + ans_db.Tdcreate.ToOADate() + 2415018.5);Then I receive Julian Date. I have kerry's Code for converting Julian Date to Date and time, but I don't know how to convert into milliseconds. How to make it to millisecond.

Kerry code for converting Julian Date:
http://www.theswamp.org/index.php?topic=41190.msg463482#msg463482


Code - C#: [Select]
  1. [CommandMethod("TTS_1")]
  2.         public void Time_tracking()
  3.         {
  4.             Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  5.             Autodesk.AutoCAD.Runtime.Exception EX = new Autodesk.AutoCAD.Runtime.Exception();
  6.             ArrayList objArray = new ArrayList();
  7.  
  8.             try
  9.             {
  10.                 string blockQualifiedFileName;
  11.                 OpenFileDialog Ans_Sheet = new OpenFileDialog("Select a file using an OpenFileDialog", null,
  12.                                 "dwg; dwf; *",
  13.                                 "SelectFileTest",
  14.                                 OpenFileDialog.OpenFileDialogFlags.AllowMultiple
  15.                               );
  16.                 System.Windows.Forms.DialogResult ans_dr = Ans_Sheet.ShowDialog();
  17.                 if (ans_dr == System.Windows.Forms.DialogResult.OK)
  18.                 {
  19.                     string[] str_tot_file = Ans_Sheet.GetFilenames();
  20.                     foreach (string fname in str_tot_file)
  21.                     {
  22.                         Database ans_db = new Database(false, true);
  23.                         blockQualifiedFileName = fname.ToString();
  24.                         ans_db.ReadDwgFile(blockQualifiedFileName, System.IO.FileShare.Read, true, string.Empty);
  25.  
  26.                         using (Transaction acTrans = ans_db.TransactionManager.StartTransaction())
  27.                         {
  28.  
  29.                             objArray.Add("\n------------------------------");
  30.                             objArray.Add("\nFile Name : " + blockQualifiedFileName);
  31.                             objArray.Add("\nCreate Date :" + ans_db.Tdcreate);
  32.                             objArray.Add("\nUpdate Date :" + ans_db.Tdupdate);
  33.  
  34.                             acTrans.Dispose();
  35.                         }
  36.                         ans_db.Dispose();
  37.                     }
  38.                     foreach (string fneame in objArray)
  39.                     {
  40.                         ed.WriteMessage(fneame.ToString());
  41.                     }
  42.                 }
  43.             }
  44.             catch
  45.             {
  46.                 AcadApp.ShowAlertDialog("Can't to read the drawing { }");
  47.             }
  48.         }
  49.  


Thanks in advance,
thenndral



edit:kdub :-> formatting code=csharp
« Last Edit: April 16, 2014, 01:17:11 AM by Kerry »

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #5 on: April 15, 2014, 02:25:35 AM »
Here is what I use to for a add-in loader to copy new files to local machines from a network that is read from xml files but think you could rip out and alter for your needs. For example see FileSystemInfo.CreationTimeUtc

Might wait for other replies but I would use FileInfo and DirectoryInfo classes, and if using .NET 4.0 you get EnumerateFileSystemObjects, EnumerateFiles, EnumerateDirectories etc.....

You can check all you want if a file exists but always a chance it will be deleted, moved, etc.... between check and whatever your doing with file so always need to handle errors. Probably needs more like checking if drive IsReady etc...

Only example thought of off hand
Code - C#: [Select]
  1.         private Dictionary<FileSystemInfo, SystemException> CopyFiles(DirectoryInfo sourceDirectory, DirectoryInfo destinationDirectory, ICollection<string> extensionFilters, bool copySubDirectories)
  2.         {
  3.             var exceptions = new Dictionary<FileSystemInfo, SystemException>();
  4.  
  5.             return CopyFiles(sourceDirectory, destinationDirectory, extensionFilters, copySubDirectories, exceptions);
  6.         }
  7.         private Dictionary<FileSystemInfo, SystemException> CopyFiles(DirectoryInfo sourceDirectory, DirectoryInfo destinationDirectory, ICollection<string> extensionFilters, bool copySubDirectories, Dictionary<FileSystemInfo, SystemException> exceptions)
  8.         {
  9.            
  10.             if (!destinationDirectory.Exists)
  11.             {
  12.                 try
  13.                 {
  14.                     destinationDirectory.Create();
  15.                 }
  16.                 catch (IOException ex)
  17.                 {
  18.                     exceptions.Add(destinationDirectory, ex);
  19.                 }
  20.                 catch (SecurityException se)
  21.                 {
  22.                     exceptions.Add(destinationDirectory, se);
  23.                 }
  24.             }
  25.            
  26.             foreach (var fi in sourceDirectory.GetFilteredFiles(extensionFilters))
  27.             {
  28.  
  29.                 FileInfo newFile = new FileInfo(Path.Combine(destinationDirectory.FullName, fi.Name));
  30.  
  31.  
  32.                 if (!newFile.Exists)
  33.                 {
  34.                     try
  35.                     {
  36.                         fi.CopyTo(newFile.FullName);
  37.                     }
  38.                     catch (IOException ex)
  39.                     {
  40.                         exceptions.Add(newFile, ex);
  41.                     }
  42.                     catch (SecurityException se)
  43.                     {
  44.                         exceptions.Add(newFile, se);
  45.                     }
  46.                 }
  47.                 else if (fi.LastWriteTimeUtc > newFile.LastWriteTimeUtc)
  48.                 {
  49.                     try
  50.                     {
  51.                         fi.CopyTo(newFile.FullName, true);
  52.                     }
  53.                     catch (IOException ex)
  54.                     {
  55.                         exceptions.Add(newFile, ex);
  56.                     }
  57.                     catch (SecurityException se)
  58.                     {
  59.                         exceptions.Add(newFile, se);
  60.                     }
  61.                 }
  62.  
  63.  
  64.             }
  65.  
  66.             if (copySubDirectories)
  67.             {
  68.                 foreach (var subDi in sourceDirectory.EnumerateDirectories())
  69.                 {
  70.                     var tempDI = new DirectoryInfo(Path.Combine(destinationDirectory.FullName, subDi.Name));
  71.                     CopyFiles(subDi, tempDI, extensionFilters, true, exceptions);
  72.                 }
  73.             }
  74.             return exceptions;
  75.         }
  76.         private DirectoryInfo ExpandDirectoryPath(string unExpandedPath)
  77.         {
  78.             return new DirectoryInfo(Environment.ExpandEnvironmentVariables(unExpandedPath));
  79.         }
  80.  

Code - C#: [Select]
  1.   public static class DirectoryInfoExtensions
  2.     {
  3.         internal static IEnumerable<FileInfo> GetFilteredFiles(this DirectoryInfo sourceDirectory,
  4.             ICollection<string> extensions)
  5.         {
  6.             if (extensions.Count == 0)
  7.             {
  8.                 return sourceDirectory.EnumerateFiles();
  9.             }
  10.             return sourceDirectory.EnumerateFiles().Where(fi => extensions.Contains(fi.Extension));
  11.         }
  12.     }
  13.  

thenndral

  • Guest
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #6 on: April 15, 2014, 08:17:37 PM »
Thanks Jeff.

I will add error handle code and also waiting for some other inputs.

In the below code we can retrieve seconds and milliseconds[may be it will help for someone]
Code: [Select]
       
                double mil = 0;
                double time = (julianDate - Math.Floor(julianDate)) * 86400;
                double mm = Math.Floor(time / 60);
                mil = time - (mm * 60);

                var result = Math.Round(mil, 3, MidpointRounding.AwayFromZero);

Thanks again,
thenndral.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #7 on: April 15, 2014, 09:12:32 PM »

thenndral,

Not everyone knows that there are 86400 secondsPerDay
Looking back at my original code I cringe a little at the magic numbers I used.


Just for interest, can you demonstrate that the TDCREATE is different to the File.GetCreationTime(qualifiedFileName) ?
...






kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

thenndral

  • Guest
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #8 on: April 15, 2014, 10:41:03 PM »
Hi Kerry,

Thanks for your reply.

As I said before I'm newbie for customization for Autocad with C#. I don't have depth knowledge in both.
According to my requirement I'm studying and doing project.

well, Few weeks ago I search for "how to retrieve Date and Time", fortunately I found your previous code using [tdcreate] and I continue with yours. I did'nt come out of the box [TDCREATE]. After this post I came to know  using "File.GetCreationTime" we can get date and time.

then I check this code, I can't retrieve the date and time which I pass the parameter filename.It retrieves date and time for  drawing1.dwg or already opened file. ie. Current time

In your previous post
 //Just for interest, can you demonstrate that the TDCREATE is different to the File.GetCreationTime(qualifiedFileName) ?//

I start checking/testing what is the difference between those two.

1. I copied already created drawing file from D Drive to C Drive. filename : 45895.dwg
2. Open C:\45895.dwg in autocad.
3. Use Autocad Command, "time"  [retrieve both] [ Please check the image for reference]
   a. Current time
   b. times for this drawing   
4. I run the below code.
Code: [Select]
        [CommandMethod("T_time")]
        public void TT()
        {

            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            DateTime fileCreatedDate = File.GetCreationTime(@"C:\430101S1239.dwg");
            ed.WriteMessage("\nFile selected was \"{0}\".\n", fileCreatedDate);

        }
5. It retrieve Current time ie. today date and time I copied to "C Drive"
6. Next I run "TDCreate" Code
7. It returns, "Times for this drawing" both "Created" and "Updated"

I think the difference is,
File.GetCreationTime(qualifiedFileName) returns "Current time"
"tdcreate" and "tdupdate" returns "Times for this drawing".

Thanks for your interest, because of your Interest I learn today something :)

Thanks a lot,
thenndral

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #9 on: April 16, 2014, 03:47:43 AM »

thenndral,
Yes, It looks like the File properties are not necessarily the same as the TDCREATE system variable.
The file date can be later than the TDCreate date.


Code - C#: [Select]
  1. // Codehimbelonga kdub 4014.02.16.
  2. //
  3. using System;
  4. using System.IO;
  5. using System.Windows.Forms;
  6. using Autodesk.AutoCAD.Runtime;
  7. using Autodesk.AutoCAD.DatabaseServices;
  8. using Autodesk.AutoCAD.EditorInput;
  9.  
  10. using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
  11. using OpenFileDialog = Autodesk.AutoCAD.Windows.OpenFileDialog;
  12.  
  13. [assembly: CommandClass(typeof(FileDateTime.MyCommands))]
  14.  
  15. namespace FileDateTime
  16. {
  17.     public class MyCommands
  18.     {
  19.         // Application Session Command
  20.         [CommandMethod("Kdub_Test_Group", "T22", "T22_Local", CommandFlags.Modal | CommandFlags.Session)]
  21.         public void MySessionCmd()
  22.         {
  23.             Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
  24.  
  25.             var ofdResult = new OpenFileDialog("Select a file using an OpenFileDialog", null,
  26.                             "dwg; dwf; *",
  27.                             "File Date Test T22",
  28.                             OpenFileDialog.OpenFileDialogFlags.NoShellExtensions // .AllowMultiple
  29.                           );
  30.             DialogResult sdResult = ofdResult.ShowDialog();
  31.  
  32.             if (sdResult != System.Windows.Forms.DialogResult.OK) return;
  33.  
  34.             string remoteFileName = ofdResult.Filename;
  35.  
  36.             Database remoteDb = new Database(false, true);
  37.             using (remoteDb)
  38.             {
  39.                 try { remoteDb.ReadDwgFile(remoteFileName, System.IO.FileShare.Read, true, string.Empty); }
  40.                 catch (System.Exception)
  41.                 {
  42.                     ed.WriteMessage("\nUnable to read drawing file.");
  43.                     return;
  44.                 }
  45.                 Transaction tr = remoteDb.TransactionManager.StartTransaction();
  46.                 using (tr)
  47.                 {
  48.                     var remoteTdCreate = remoteDb.Tdcreate;
  49.                     var remoteTdUpdate = remoteDb.Tdupdate;
  50.                     var fileCreatedDate = File.GetCreationTime(remoteFileName);
  51.  
  52.                     AcadApp.ShowAlertDialog(
  53.                                             remoteFileName +
  54.                                             "\nGetCreationTime :" + fileCreatedDate +
  55.                                             "\nTDCreate :       " + remoteTdCreate +
  56.                                             "\nTDUpdate :       " + remoteTdUpdate);
  57.                     tr.Commit();
  58.                 }
  59.             }
  60.         }
  61.     }
  62. }
  63.  
  64.  
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #10 on: April 16, 2014, 04:10:20 AM »
Makes sense, the date persists within the dwg through file system operations which are technically new files

thenndral

  • Guest
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #11 on: April 16, 2014, 04:25:31 AM »
Hi,

Hi Kerry,

Thanks for your code . It takes me one step forward to my learning process.

one quick question, out of this topic.

To check whether student copied from another student drawing file or not. If Id.handle same more than 20 then student may copied from another student.

I'm comparing Id.Handle will not be same for all the student drawing. It must be unique. I hope i'm right.

for ex. compare 5 or more drawing entity Id.handle [within all the drawing]
aa.dwg
bb.dwg
cc.dwg
dd.dwg
ee.dwg

1. get all the aa.dwg entity and compare with other bb.dwg to ee.dwg entity id.handle.
for loop: 1st time
 aa.dwg---> bb.dwg
   cc.dwg
   dd.dwg
   ee.dwg
2nd time:
bb.dwg -->
   aa.dwg   
   cc.dwg
   dd.dwg
   ee.dwg
... upto compare all the drawing.


Can you give me some suggestion. how to achieve this?

Thanks  a lot,
thenndral

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #12 on: April 16, 2014, 04:44:11 AM »

 thenndral,
I don't have time to play at the moment, but I think it would be easy to get around that test
... just copy all entities a couple of times and delete all but the last.

The testing could become quite complicated I think.

I recall seeing a lisp code lots of years ago that was meant as a test for college student drawing integrity, but I have no idea where you'd find one now.

Perhaps you could write the entity type and some properties including the handle to a database and devise tests to run on the database.
The order of creation may be an indicator.
I don't know how creative someone who cheats would be ... perhaps it would be easier than I imagine to catch culprits.

Another option is to force logging ON and demand the submittal of the log file.   
Quote
Maintain a Log File
Writes the contents of the text window to a log file. (LOGFILEMODE system variable, see also LOGFILEPATH and LOGFILENAME)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #13 on: April 16, 2014, 05:11:50 AM »
Wblock and copying and pasting would make them unique and using a handle will not tell you who created it and will differ.
Every drawing will a certain number of handles the same like blocktable etc.....
I can not see that working.

If worried about students cheating just get Environment.UserName and add username to extensiondictionary or xdata and if use extensiondictionary make sure to set TreatElementsAsHard to true.

You could use a ObjectOverrule and override close and check if IsNewObject is true
If true check if contains entry in extension dictionary or xdata if does then do whatever you want maybe additional users one after another then you can see which student created and who copied from who.

Using Xdata or extension dictionary will clone with object but would need make sure anything meant to be shared to turn off overrule or create with default user.

Another thing to see if sharing actual drawings is if all drawings are required to be created from a dwt then you can check Database.FingerprintGuid Property which should be unique for any drawing created from a dwt. I guess there is a one in a butt billionth chance 2 guids will be the same but fail them anyways.
« Last Edit: April 16, 2014, 05:18:04 AM by Jeff H »

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #14 on: April 16, 2014, 05:21:56 AM »
That autolisp your speaking of the guy just tagged objects with xdata, try searching Autodesk University. He did not share his solution but explained it in a video at AU 4 or 5 years ago and I just listened to it in background but almost positive he was just tagging objects with xdata

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #15 on: April 16, 2014, 05:29:43 AM »
Don't listen to me and listen to Kerry.
Just require all drawings to be created from dwt, use logging as Kerry mentioned and you can see total edit time of file to make sure log matches.



 

thenndral

  • Guest
Re: Without open dwg get GETSYSTEMVARIABLE("TDCREATE")?
« Reply #16 on: April 16, 2014, 06:42:06 AM »
Hi Jeff & Kerry,

Thanks for your reply.

//Just require all drawings to be created from dwt, use logging as Kerry mentioned and you can see total edit time of file to make sure log matches.//

I will explain my whole scenerio.
1.Assume we are conduting Cad Exam. our exam centre are in different places. students can download template file from website. [filename = Template.dwg] after student save the drawing name in their examination code and Answering to question.

Once Student finish exam, upload answer sheet to server. I download from the server and have to validate.

Validation:
1. Check Student used template file or others file.
   my solution: using tdcreate, I can compare template file date and time with student answersheet. If it is not same, I will come to conclusion, student didnt use template file]
2.It is also possible to copy from one student drawing to another.
   My solution: I thought Id.Handle is not same for all the drawing may be certain amount of Id.handle possible to same. Now Jeff and kerry reply made me to think more.I think it is also a difficult process.

Could you give me some samples or related links or related to study.
It will help me more to achieve my task.

Thanks a lot,
thenndral