Author Topic: File Size  (Read 3653 times)

0 Members and 1 Guest are viewing this topic.

Robert98

  • Guest
File Size
« on: March 09, 2015, 03:17:20 PM »
Hi Friends
I want get size of active drawing , by this line of code in VB, but I get an Error.Please  somebody help me about correct form of this code .
Code - vb.net: [Select]
  1.  Dim length as long = new System.IO.FileInfo(path).Length
  2.  

BillZndl

  • Guest
Re: File Size
« Reply #1 on: March 09, 2015, 04:02:10 PM »
what kind of error?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: File Size
« Reply #2 on: March 09, 2015, 11:21:26 PM »
What is the value of the 'path' variable ??
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.

Robert98

  • Guest
Re: File Size
« Reply #3 on: March 10, 2015, 02:34:19 PM »
Hello
Thank you BillZndl  and Kerry for replying .The path is an active drawing folder and I want to get the size of the active drawing in KB or MB .
Routine of the path is originally written by Kean Walmsley
Code - vb.net: [Select]
  1. Public Sub Path()
  2.         Dim doc As Document = Application.DocumentManager.MdiActiveDocument
  3.         Dim h_app As HostApplicationServices = HostApplicationServices.Current
  4.         Dim path As String = h_app.FindFile(doc.Name, doc.Database, FindFileHint.[Default])
  5.         doc.Editor.WriteMessage(vbLf &  path)
  6. End Sub
« Last Edit: March 10, 2015, 02:37:44 PM by Robert98 »

BillZndl

  • Guest
Re: File Size
« Reply #4 on: March 10, 2015, 03:27:53 PM »
You did say what error you are getting but if it's eFilerError,
most likely you're running your code in a new/unsaved drawing.
If I check for an unsaved drawing, the code works find.
Sorry but I only know C#.

Code - C#: [Select]
  1.  int title = Convert.ToInt32(AcadApp.GetSystemVariable("DWGTITLED"));
  2.  
  3.             if (title > 0 )
  4.             {
  5.                 string path = h_app.FindFile(doc.Name, doc.Database, FindFileHint.Default);                                    
  6.                 FileInfo info = new FileInfo(path);
  7.                 size = info.Length;
  8.                 ed.WriteMessage("\nPath: " + path);
  9.                 ed.WriteMessage("\nFileSize: " + size);
  10.             }
  11.             else
  12.             {
  13.                 ed.WriteMessage("\nFile not found");
  14.             }
  15.  

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: File Size
« Reply #5 on: March 10, 2015, 03:31:44 PM »
You can try this way (if the file isn't already saved, db.Filename returns the template path):

Code - C#: [Select]
  1. Document doc = Application.DocumentManager.MdiActiveDocument;
  2. Database db = doc.Database;
  3. Editor ed = doc.Editor;
  4. ed.WriteMessage("\n{0} Ko", new System.IO.FileInfo(db.Filename).Length / 1024);
Speaking English as a French Frog

BillZndl

  • Guest
Re: File Size
« Reply #6 on: March 10, 2015, 04:25:37 PM »
You can try this way (if the file isn't already saved, db.Filename returns the template path):

Much better! 8)

Robert98

  • Guest
Re: File Size
« Reply #7 on: March 11, 2015, 12:35:56 PM »
Hello
Thank you BillZndl  and gile for replying .
I used both suggestions. gile's code worked properly but, when I run BillZndl's I get an error like this one :

Quote
Error   3   'GetSystemVariable' is not a member of 'Autodesk.AutoCAD.ApplicationServices.Document'.
Error   4   'EditorWriteMessage' is not a member of 'Autodesk.AutoCAD.ApplicationServices.Document'.   

Here is my code:
Code: [Select]
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports System.IO


Public Class Class1
    <CommandMethod("PS")> _
    Public Sub DrawingPath()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim h_app As HostApplicationServices = HostApplicationServices.Current
        Dim title As Integer = Convert.ToInt32(doc.GetSystemVariable("DWGTITLED"))

        If title > 0 Then
            Dim path As String = h_app.FindFile(doc.Name, doc.Database, FindFileHint.[Default])
            Dim info As New FileInfo(path)
            Dim size As Long = info.Length
            doc.Editor.WriteMessage(vbLf & "Path: " & path)
            doc.EditorWriteMessage(vbLf & "FileSize: " & size)
        Else
            doc.Editor.WriteMessage(vbLf & "File not found")
        End If

    End Sub
End Class


Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: File Size
« Reply #8 on: March 11, 2015, 12:51:02 PM »
Robert, the GetSystemVariable is applicable to the Application, not the Document (re-read Bill's post).
You omitted a '.' in the line just above the Else.

BillZndl

  • Guest
Re: File Size
« Reply #9 on: March 11, 2015, 01:27:09 PM »
Yup,
The using statement for AcadApp is:
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

Then:
AcadApp.GetSystemVariable("DwgTitled");

Thanks Jeff!


MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: File Size
« Reply #10 on: March 12, 2015, 07:48:47 AM »
Yup,
The using statement for AcadApp is:
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

Then:
AcadApp.GetSystemVariable("DwgTitled");

Thanks Jeff!


You shouldn't wrap the Application in a Using statement.  The Application scope is outside your method and AutoCAD is handling its disposal.
Revit 2019, AMEP 2019 64bit Win 10

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: File Size
« Reply #11 on: March 12, 2015, 08:49:07 AM »
Yup,
The using statement for AcadApp is:
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

Then:
AcadApp.GetSystemVariable("DwgTitled");

Thanks Jeff!


You shouldn't wrap the Application in a Using statement.  The Application scope is outside your method and AutoCAD is handling its disposal.

I think the 'using' here isn't a 'statement', rather a 'directive' used to define an alias (see here)
Speaking English as a French Frog

BillZndl

  • Guest
Re: File Size
« Reply #12 on: March 12, 2015, 09:46:49 AM »

I think the 'using' here isn't a 'statement', rather a 'directive' used to define an alias (see here)

Er, yes, I should have said directive not statement. My bad.
Learn something new everyday!
Thanks.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: File Size
« Reply #13 on: March 12, 2015, 11:39:54 AM »
Yup,
The using statement for AcadApp is:
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

Then:
AcadApp.GetSystemVariable("DwgTitled");

Thanks Jeff!
Your Welcome