.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DocumentCollectionExtension.Open Problem

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
1151 Views, 2 Replies

DocumentCollectionExtension.Open Problem

This is from an existing application which has been working fine for months and the problem is in a very simple minor function used to open files in the editor. Using: DocumentCollectionExtension.Open however no matter what I do the files open in AutoCAD Read-Only...

Very weird and frustrating.

 

Code Follows.

 

Public Function OpenDrawing(ByVal fullname As String, ByVal ForReadOnly As Boolean) As Document ' OpenDrawingUNSULLIED
    Try
        Dim docs As DocumentCollection = _

                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager ' 2014 ARX Change
            Try
                  Dim doc As Document = SelectDocument(fullname, Not ForReadOnly)                        

                  '  SelectDocument --> Makes file current if open in editor
                  If Not doc Is Nothing Then
                      Return doc
                  Else
                      Batch_Audit_WPF.OpenDrawingEventBypass = True
                     doc = DocumentCollectionExtension.Open(docs, fullname, ForReadOnly)
                     Batch_Audit_WPF.OpenDrawingEventBypass = False
                     If ForReadOnly = False And doc.IsReadOnly = True Then
                            doc.DowngradeDocOpen(True) 
                            Return Nothing
                     Else
                            Return doc
                     End If
                 End If
           Catch ex As SystemException
                 Dim pname = (New StackTrace().GetFrame(1)).GetMethod.Name, mname = (New StackFrame().GetMethod().Name)
                 LogError(ex, mname, pname)
                 Return Nothing
           End Try
           Return Nothing
    Catch ex As Exception
           Dim pname = (New StackTrace().GetFrame(1)).GetMethod.Name, mname = (New StackFrame().GetMethod().Name)
           LogError(ex, mname, pname)
           Return Nothing
      End Try
End Function

One of our main applications is crippled until I can get this figured out, any help is apreciated...
Thanks in advance.

2 REPLIES 2
Message 2 of 3
Balaji_Ram
in reply to: Anonymous

Hi JB,

 

Sorry, I do not reproduce the problem using the code snippet that you shared.

 

Some of the things that you can try :

 

Does the drawing open without "Read-only" when  opened directly in AutoCAD without your code ?

 

Does the folder containing the drawing have the required privileges and not set as "read-only"

 

Have you tried resetting AutoCAD using the "Reset settings to default" option as in the attached screenshot

 

Also, please try the other version of opening drawing files as in this code snippet :

 

    Public Class Test
        Implements IExtensionApplication

        Public Sub Initialize() Implements IExtensionApplication.Initialize
        End Sub

        Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
        End Sub

        <CommandMethod("Test1")> _
        Public Sub Test1Method()
            Dim fileName As String
            fileName = "D:\Temp\Test.dwg"
            OpenDrawing(fileName, False)
        End Sub

        <CommandMethod("Test2", CommandFlags.Session)> _
        Public Sub Test2Method()
            Dim fileName As String
            fileName = "D:\Temp\Test.dwg"
            Dim docs As DocumentCollection = _
                       Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
            docs.AppContextOpenDocument(fileName)
        End Sub

        Public Function OpenDrawing(ByVal fullname As String, ByVal ForReadOnly As Boolean) As Document
            Dim docs As DocumentCollection = _
                        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
            Try
                Dim doc As Document
                doc = DocumentCollectionExtension.Open(docs, fullname, ForReadOnly)
                If ForReadOnly = False And doc.IsReadOnly = True Then
                    doc.DowngradeDocOpen(True)
                    Return Nothing
                Else
                    Return doc
                End If
            Catch ex As SystemException
                Return Nothing
            End Try
            Return Nothing
        End Function
    End Class

Regards,

Balaji



Balaji
Developer Technical Services
Autodesk Developer Network

Message 3 of 3
Anonymous
in reply to: Balaji_Ram

Hi Balaji

 

Thanks for responding to my post and for your code, I did solve my problem and I believe it was caused by not disposing of a database in another procedure. I am not entirely sure however as I finally just went back to a version of my program in which these functions worked as they should and modified a half dozen procedures in several modules when doing so.

 

What I'm trying to do is delete, purge and replace an older out of date drawing border with our current standard drawing border in a side-database and update the associated attributes and the form display from a SQL conversion table.

 

I had tried the AppContextOpenDocument method but had not as yest tried to the IExtensionApplication methods which appear to be superior and which I will be experimenting with shortly, the ObjectARX docs. indicated that you should use the database.readdwgfile method.

 

At any rate my (current) problem has been solved and thank you again for your responce

 

--jim

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

Post to forums  

Autodesk Customer Advisory Groups


Autodesk Design & Make Report