save file - error WHERST

save file - error WHERST

ZEH1985
Contributor Contributor
2,042 Views
10 Replies
Message 1 of 11

save file - error WHERST

ZEH1985
Contributor
Contributor

Hello,
I have a script here that I use to edit the dimensions in AutoCAD and then close the file. If I then open the file again, I get the message that an error was detected during opening and the "WHERST" command should be used.
For saving and closing I use:

 

Call ThisDrawing.Close (True)

 

Funny thing is, if I comment out this line and do the save and close manually, I don't get this message. I had already tried this variant:

 

ThisDrawing.Save
ThisDrawing.Close

 

Unfortunately without success. What's going wrong? All files are local and the user has write access to the directory.

Many thanks in advance.

0 Likes
Accepted solutions (1)
2,043 Views
10 Replies
Replies (10)
Message 2 of 11

Ed__Jobe
Mentor
Mentor

Can you post your code and a sample file?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 3 of 11

ZEH1985
Contributor
Contributor

Hey Ed,

 

thanks for your answer. Here is the code I use:

Sub BemEdit()
    
    Dim Sset As AcadSelectionSet
    Dim Auswahl As AcadObject
    Dim Bemass As AcadDimension
    Dim FilterType(0) As Integer
    Dim FilterData(0) As Variant
    
    
    Dim i As Integer
    'i = 0
    For i = 1 To ThisDrawing.SelectionSets.Count - 1
        
        ThisDrawing.SelectionSets.Item(i).Delete
        i = i + 1
    Next
    
    On Error Resume Next
    Set Sset = ThisDrawing.SelectionSets.Add("TEST_SSET")
    If Err <> 0 Then
        Set Sset = ThisDrawing.SelectionSets("Test_SSet")
        Sset.Clear
        Err.Clear
    End If
    
    On Error GoTo 0
    
    FilterType(0) = 0
    FilterData(0) = "Dimension"
    'Sset.Select acSelectionSetAll, , , FilterType, FilterData
    Call Sset.Select(acSelectionSetAll, , , FilterType, FilterData)
    
    Dim SBemStringOrg As String
    
    For Each Auswahl In Sset
        
        Set Bemass = Auswahl
        'Bemass.TextOverride = MTRunden(Bemass.Measurement)
        Bemass.TextOverride = Replace(Bemass.TextOverride, "\fArial|b0|i0;\H0.0000;", "")
    Next Auswahl
    
    
    Sset.Clear
    
    'ThisDrawing.Save
    ThisDrawing.Close (True)
   
    
End Sub

 

Many Thanks and have a nice day.

0 Likes
Message 4 of 11

Ed__Jobe
Mentor
Mentor

The function MtRunden appears to be missing from the sample.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 11

ZEH1985
Contributor
Contributor

Hello Ed

the function is commented out. The line can also be deleted.
Or am I wrong?

0 Likes
Message 6 of 11

Ed__Jobe
Mentor
Mentor

Sorry, I didn't catch that.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 11

ZEH1985
Contributor
Contributor

No problem. I am happy if there is a solution to the problem ...

0 Likes
Message 8 of 11

ZEH1985
Contributor
Contributor

Hello Ed,

could you please test the code? The behavior in connection with reopening the drawing is different if you comment out the line "ThisDrawing.Close (True)".

I don't understand why and support sends me to ADN.

 

Thanks a lot.

0 Likes
Message 9 of 11

norman.yuan
Mentor
Mentor
Accepted solution

I believe the last line of code:

 

ThisDrawing.Close (True)

 

should have been

 

ThisDrawing Close True

 

or

 

Call ThisDrawing.Close(True) 

 

Since your original post was Call ThisDrawing.Close(True), so, it could only be accidentally made error when you post the entire subroutine code,

 

Anyway, you did not mention which AutoCAD vertical and its version you are using, but I guess you are not using plain AutoCAD; or at least the drawing you provided was not last saved by plain AutoCAD. Even the drawing is AutoCAD 2010 format, many AutoCAD verticals creates drawing that is not backward compatible, even the DWG format is the same. For example, for C3D, if a drawing, which was created/saved in previous C3D version, is opened in later C3D, new AEC data could be added automatically, while the DWG format remains the same. Once the drawing is saved, and you try to open it in older version C3D, you would get prompt of data loss, or even error. 

 

The same thing could apply to other AutoCAD verticals (again no idea what you are using).

 

So, I'd think your issue is not because of VBA code, rather the version of AutoCAD verticals in combination of DWG format versions being used currently and used to create the drawing made the situation complicated.

 

I'd try to firstly to make the AutoCAD vertical that runs your code to save drawing to latest DWG format in Drawing Open/Save options before running the code.

Norman Yuan

Drive CAD With Code

EESignature

Message 10 of 11

ZEH1985
Contributor
Contributor

Hello Norman Yuan,

thank you for your feedback.
The tip with the AutoCAD version or application was very good.
We use the following:
- AutoCAD Mechanical 2020
- By default, we have set in Mechanical that this is saved as AutoCAD DWG 2010.

Now I've tried the following:
- Pure AutoCAD 2020 started
- Standard setting for saving checked -> AutoCAD 2010 DWG
- VBA macro loaded and executed
- File opened again -> no error appears

That’s great, but I don’t understand it. In AutoCAD Mechanical it is also specified that the file should be saved as AutoCAD DWG 2010. Not as a mechanical file.

Do I have to use the command differently when saving so that the file is saved as AutoCAD DWG 2010?

Thank you in advance for further support

0 Likes
Message 11 of 11

ZEH1985
Contributor
Contributor

Hello

 

0 Likes