VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Intermittent error when creating new drawing from template!

3 REPLIES 3
Reply
Message 1 of 4
CADCC
654 Views, 3 Replies

Intermittent error when creating new drawing from template!

Can somebody please help me with this problem?

 

I'm writing a program to create new drawings for users from different templates, based upon their choices made on a Userform.  The program works just fine all the way through apart from if, when the main form is loaded, the user takes a long time on the form before clicking the OK button.  If this happens I get a ' -2147417856 - Automation Error - System Call Failed'.

 

I've tracked the line of code down that triggers the error and highlighted it in the sub below.

 

Private Sub CreateNewDrawing()

 

Dim TemplatePath As String
Dim TemplateName As String
Dim acadDocs As AcadDocuments
Dim docObj As AcadDocument

 

On Error GoTo ErrTrap

 

Set acadDocs = ThisDrawing.Application.Documents

 

TemplatePath = "G:\AutoCAD Content\Central Library\Catalogs\LSU-UMC\Reference Files\"

 

If DrawingType = 0 Then
TemplateName = "Model.dwt"
Else
TemplateName = "End.dwt"
End If

 

If File_Exists(TemplatePath & TemplateName) = True Then
Set docObj = acadDocs.Add(TemplatePath & TemplateName)

Else
MsgBox "Template '" & TemplateName & "' not found at path" & vbCrLf & TemplatePath, vbCritical
End
End If

 

Exit Sub

 

ErrTrap:

 

Select Case Err.Number
Case Else
MsgBox Err.Number & " - " & Err.Description & vbCrLf & "CreateNewDrawing"
End Select

 

End Sub

 

This sub is called straight after the OK button has been clicked and the userform has been hidden.

 

I'm completely stumped as to why the code seems to lose its connection with AutoCAD after about a minue of inactivity.

 

Any help would be very much appreciated!

 

Regards

 

Graham

3 REPLIES 3
Message 2 of 4
norman.yuan
in reply to: CADCC

Is this VBA code running in 64-bit AutoCAD? Have you tried it with 32-bit AutoCAD? It sounds like because of 64-bit Acad's VBA issue. If it is so (that is, if you can verify the code works OK with 32-bit Acad), then I am afraid there isn't much you can do except for giving it up with 64-Acad VBA.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 4
CADCC
in reply to: norman.yuan

We've just upgraded all our PC's to Acad 2012 & Win 7 64bit so I've no way of testing Smiley Sad

 

Is there a know problem with this configuration?

Message 4 of 4
norman.yuan
in reply to: CADCC

If you have VBA programs that are very critical to the business operation, you should have test them in 64-bit AutoCAD thoroughly, before moving to 64-bit AutoCAd in production. because of the nature of VBA in 64-bit Acad, there will be some things that do not work and no fix will be avaialble.

 

So, if you can prove the code works well in 32-bit Acad, then you are likely hit by one of the "no-fix" issues with 64-bit Acad VBA. Also, if you are just start programming AutoCAD, VBA is not worth the effort of doing serious development.

Norman Yuan

Drive CAD With Code

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost