Robert98 发表于 2015-3-9 15:17:20

文件大小

嗨,朋友们我想通过VB中的这行代码获得活动绘图的大小,但是我得到了一个Error.Please有人帮助我了解此代码的正确形式。Dim long as long=newSystem.IO.FileInfo(path),长度。

**** Hidden Message *****

BillZndl 发表于 2015-3-9 16:02:10

什么样的错误?

Kerry 发表于 2015-3-9 23:21:26

路径变量的值是多少??

Robert98 发表于 2015-3-10 14:34:19

您好谢谢BillZndl和Kerry的回复,该路径是一个活动图形文件夹,我想获得活动图形的大小,以KB或MB为单位。 Path的例程最初是由Kean Walmsley编写的。
将文档显示为文档=应用程序,document manager . MdiActiveDocument 。
Dim h _ app As HostApplicationServices = HostApplicationServices,当前。
Dim path As String = h_app,FindFile(doc,名字,医生。数据库,FindFileHint。[默认])。
doc,editor . write message(vbLf & path)。
结束Sub。

BillZndl 发表于 2015-3-10 15:27:53

您确实说过您遇到的错误,但如果它是eFilerError,则很可能您正在新的/未保存的图形中运行代码。如果我检查未保存的绘图,代码工作找到。对不起,但我只知道C#。 int title = Convert.ToInt32(AcadApp.GetSystemVariable(“DWGTITLED”));。

如果 (标题 > 0 )。
{。
字符串路径 = h_app,FindFile(doc.姓名,文档。Database, FindFileHint.Default);                                 。
FileInfo info = new FileInfo(path);。
大小 = 信息,长度;。
编辑,WriteMessage(“\nPath: ” + path);。
编辑,WriteMessage(“\nFileSize: ” + size);。
}。
还。
{。
编辑,WriteMessage(“\nFile not found”);。
}。

gile 发表于 2015-3-10 15:31:44

您可以尝试这种方式(如果文件尚未保存,db.Filename返回模板路径):Document doc=Application.DocumentManager.MdiActiveDocument;。
数据库db=doc.Database;。
编辑=doc.Editor;。
ed.WriteMessage("\n{0}Ko",新System.IO.FileInfo(db.Filename)。长度/1024);。

BillZndl 发表于 2015-3-10 16:25:37


好多了!

Robert98 发表于 2015-3-11 12:35:56

您好
感谢BillZndl和gile的回复。
我使用了两个建议。gile的代码工作正常,但是当我运行BillZndl时,我得到了如下错误:
这是我的代码:
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
   _
    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.)
            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 发表于 2015-3-11 12:51:02

Robert,GetSystemVariable适用于应用程序,而不是文档(请重新阅读Bill的帖子)<您省略了一个“.”在Else正上方的队列中。

BillZndl 发表于 2015-3-11 13:27:09

是的,
AcadApp的使用语句是:
使用AcadApp=Autodesk.AutoCAD.ApplicationServices.Application
AcadApp。GetSystemVariable(“DwgTitled”)
页: [1] 2
查看完整版本: 文件大小