Hi Tertia,
I'm sorry, been busy all day.
I did see that someone posted an example of VBScripting using FSO and it looks good, however it had attributes and all. That is cool, you can do a lot with Scripting,
Generally, VBScripting code is placed into a .txt file, then you do Saveas a .vbs file.
At which point you can simply double click the file to execute it. I have done some cool script then open acad and do some things. The other cool thing about VBScritping code is that it can be used in VBA as well, as long as you set a reference to the object that you need in VBA.
OK, well in the below example, the first Sub, I am simply writing out the layers to a text file, it will appear on your desktop.
Then in the second example, the file will be read from and assigned to a variable which then will display your layers in a msgbox in VBA.
Ok, that is cool, right? Well, how does that help you?
We would do something similar, only we are writing out an event, such as Save
Now, Tertia, the file I am referring to is not just a .dvb file, it is the acad.dvb file. Are you using that particular file?
Here yiou go, i will attach mine, so that you can see it.
Place it in your ACAD-Support directory, fire up ACAD and it will be automatically loaded.
Then, in the .dvb file, click on Thisdrawing and you will see the events I have coded. If you have not used it, you will find it extremely helpful.
You see, each drawing has document level events, but what are you going to do, write code in every drawing? Of course not. So, The ACAD.dvb file loads automatically on startup and is in The User's VBA environment all of the time, independent of any drawings. In there we can access drawing and app level events. So, it is very important that you use that file, if this is to work properly. You will find it in your support directory, but in mine, there is already examples that I can share with you.
Ok, so after you look at that file, realizing that this can be loaded into each person's support directory, which will load each time they fire up ACAD, you now have all events accessible to each user, all of the time.
Ok, so, once we have that ready, we can then grab the Begin or End Save Event.
With the below code, run it from a Sub in VBA and you will see that we can send ACAD info out to a text file and read it back into ACAD.
We can write directly to Excel and that might make the most sense. Let me ask you , have you written any VBA code in Excel? If you had the code, we can just put it into ACAD-VBA
If not, then I am not sure what to do; I would have to see the spread sheet etc. etc. in order to know precisely what to do.
Ok, well try loading the acad.dvb file, play with that a bit, then try the below code.
There is also a Begin Open File and a New Drawing Event in The App events, if you'd prefer that direction.
Let me know what you decide and we will see if we can go forward.
Tertia, the file would not attachas a .dvb file, so I changed the extension to xls in order to pass it to you
After you download it, change the extension back to dvb and you should be fine
Have a good night
ML
Public FSO As Variant, Username As Variant
Public Dwgname As String
Sub WriteToText()
'This will write the .txt file to your desktop
Dim FSO As Variant
Dim MyFile As Variant
Dim Layr As AcadLayer
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = CreateObject("WScript.Network")
Username = WshNetwork.Username
Dwgname = UCase(Left$(ThisDrawing.Name, Len(ThisDrawing.Name) - 4))
'Dwgname = "Layers"
Set MyFile = FSO.CreateTextFile("C:\Documents and Settings\" & Username & "\Desktop\" & Dwgname & ".txt", True)
For Each Layr In ThisDrawing.Layers
MyFile.WriteLine Layr.Name
Next Layr
MyFile.Close
End Sub
Sub ReadTextFile()
'This will read the .txt file from your desktop into ACAD
Dim Stream As Variant
Dim Textstr As String
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = CreateObject("WScript.Network")
Username = WshNetwork.Username
Dwgname = UCase(Left$(ThisDrawing.Name, Len(ThisDrawing.Name) - 4))
Set Stream = FSO.OpenTextFile("C:\Documents and Settings\" & Username & "\Desktop\" & Dwgname & ".txt")
'Set FSO = Nothing
Textstr = ""
'While there are lines to read, continue on to the end of the file.
'If the file is empty, we will reach the end of the stream and the variable Textstr will be returned as null.
Do While Not Stream.AtEndOfStream
Textstr = Textstr & Stream.ReadLine & vbCrLf 'or VbNewline
Loop
'Set Stream = Nothing
If Textstr "" Then
MsgBox Textstr
Else
MsgBox "The file you selected is empty"
End If
Stream.Close
End Sub