打开、宏、关闭,然后是Lo
大家好,使用一种简单的方法打开整个dwg堆栈,在其上运行一两个宏,然后再次关闭。
可能一次一个-例如:让bacth文件将dwg调用到acad 2009,运行宏或脚本调用宏,然后关闭dwg并打开下一个以重复任务。
我找到了一种在DIESEL中实现这一点的方法,但它最多适用于8个drg。
我找到了一种方法,可以同时使用lisp代码、脚本和批处理文件来实现这一点,但速度太慢,效果不理想。
目前,我需要做的是在将一个充满文件的目录加载到autocad后单击一次宏,然后单击一个按钮,宏在完成后关闭文件。
如果没有自动单击程序,我该如何自动执行此操作,以便宏将重新运行以生成下一个dwg? 这里可能有一个VBA解决方案。
这是一个模块*,递归查找给定类型的所有文件,然后为每个文件调用一个子例程。
如果您已经有了一些执行这些特定操作的代码,那么在“DoSomethingWithFile”例程中调用主例程。
这是一个通用模块,可以(重新)用于任何VBA操作,无论是在Acad、Excel等中运行,因此,其中没有Autocad命令,包括打开或关闭图形。
例如,使用文件类型“*.dwg”调用主“FindAllFiles”例程;例如,起始路径“Y\MyDwgs\Temp”。
未经修改的“DoSomethingWithFile”例程仅将找到的所有文件列出到调试窗口。请记住,此例程是递归的-它深入到您在“FindAllFiles”主例程的“StartPath”参数中传递的文件夹下的所有子文件夹。
----剪断------------------------------------
Option Explicit
Private Const vbDot = 46
Private Const MAX_PATH As Long = 260
Private Const INVALID_HANDLE_VALUE = -1
Private Const vbBackslash = "\"
Private Const ALL_FILES = "*.*"
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Private Declare Function FindClose Lib "kernel32" _
(ByVal hFindFile As Long) As Long
Private Declare Function FindFirstFile Lib "kernel32" _
Alias "FindFirstFileA" (ByVal lpFileName As String, _
lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" _
Alias "FindNextFileA" (ByVal hFindFile As Long, _
lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function lstrlen Lib "kernel32" _
Alias "lstrlenW" (ByVal lpString As Long) As Long
Private Declare Function PathMatchSpec Lib "shlwapi" _
Alias "PathMatchSpecW" (ByVal pszFileParam As Long, _
ByVal pszSpec As Long) As Long
Dim sFileExt As String
Dim sFileRoot As String
Public Sub FindAllFiles(FileType As String, StartPath As String)
' recursively searches a passed path for files of a given type
' FileType: a wildcard string of the file extension, ie; "*.dwg" or "*.xls"
sFileRoot = QualifyPath(StartPath) 'start path
sFileExt = FileType 'file type of interest
Call SearchForFiles(sFileRoot)
End Sub
Private Sub SearchForFiles(sRoot As String)
Dim WFD As WIN32_FIND_DATA
Dim hFile As Long
hFile = FindFirstFile(sRoot & ALL_FILES, WFD)
If hFile <> INVALID_HANDLE_VALUE Then
Do
'if a folder, and recurse specified, call method again
If (WFD.dwFileAttributes And vbDirectory) Then
If Asc(WFD.cFileName) <> vbDot Then
SearchForFiles sRoot & TrimNull(WFD.cFileName) & vbBackslash
End If
Else
'must be a file..
If MatchSpec(WFD.cFileName, sFileExt) Then
DoSomethingWithFile sRoot & TrimNull(WFD.cFileName)
End If 'If MatchSpec
End If 'If WFD.dwFileAttributes
Loop While FindNextFile(hFile, WFD)
End If 'If hFile
Call FindClose(hFile)
End Sub
Private Function QualifyPath(sPath As String) As String
' formats passed path string to be used in recursive API search
If Right$(sPath, 1) <> vbBackslash Then
QualifyPath = sPath & vbBackslash
Else
QualifyPath = sPath
End If
End Function
Private Function TrimNull(startstr As String) As String
' trims NULL char (ascii 0) from strings returned by API calls
TrimNull = Left$(startstr, lstrlen(StrPtr(startstr)))
End Function
Private Function MatchSpec(sFile As String, sSpec As String) As Boolean
' uses API version of the "LIKE" command
MatchSpec = PathMatchSpec(StrPtr(sFile), StrPtr(sSpec))
End Function
Private Sub DoSomethingWithFile(FoundFileName As String)
' use this routine to do something with each file found
' we'll do nothing but print out the filename found
Dim FoundName As String: FoundName = FoundFileName
Debug.Print FoundName
End Sub
如果你能使用VB。net,然后我可以提供一些代码,甚至不用打开文件就可以为您完成。在一些相当复杂的脚本上,我能在几秒钟内完成100幅图画的表现。
让我知道,如果有兴趣的话,我可以提供一些建议。
干杯 我熟悉vb dot net的操作方式,但不知道如何将其应用于acad 09。
我可能需要更多关于如何实际实现VBA的细节。
我开始使用。net,并且会对您提到的代码非常感兴趣。请邮寄!。
禅宗
基本上,我只需要一个立足点,了解如何在autocad中使用VBA,从那里我可以学到一些东西并进行实验。但在我读到这个论坛之前,我认为lisp和deisel是我唯一的选择。
那么,尽管看起来简单明了,但第一步是什么?
由于您之前没有做过VBA,我将从查找一般VBA网站开始,该网站提供了一些基本教程,您可以访问一些AutoCAD特定的网站:以下两个网站只是其中的一部分,但我发现这两个网站到目前为止最有帮助:
http://rkmcswain.blogspot.com/我相信这是来自这个论坛里的人们。
http://blog.jtbworld.com是另一个我发现不仅对AutoCAD有用而且对其他办公产品也有用的网站。
如果你想要的话,我可以发布我找到的VBA教程网站。。。
禅宗 我熟悉ACCESS中的VBA,在过去做过很多数据库工作。
对于指针,我将开始我的旅程,进入等待我的阅读英里。
页:
[1]