• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Mentor
    Posts: 260
    Registered: ‎01-27-2010

    eWasOpenForRead on ReloadXrefs(CollId)

    101 Views, 2 Replies
    04-16-2012 06:48 AM

    Hi all i have a error when i use ReloadXrefs(CollId)

     

    here all the code :

     

     

      '*************************************************************************************
    '**** Function de MaJ d'un Xref dans la table général des définitions des blocs ******
    '*************************************************************************************
    '** Entrée :
    '** OkErreur : Init à false
    '** CollIdXref : initialisé mais vide
    '** strIndex : Un Texte récurant pour afficher le nombre de fois que la proc. a été lancée
    '** Sortie :
    '** OkErreur : Retourne Vrai si une erreur a été vu lors de la recherche du PathName de la Xref
    '** CollIdXref : Retour la collection Id des Xref restant dans la base
    '** --> Function : True si tous les Xref sont à jour et résolu
    '*************************************************************************************
    Public Shared Function MaJXRefDansTable(ByRef OkErreur As Boolean, _
    ByRef CollIdXref As ObjectIdCollection, _
    ByRef strIndex As String) As Boolean
    Dim OkRetour As Boolean = True
    If strIndex = "" Then
    strIndex = vbCrLf & "-->"
    Else
    strIndex = strIndex & "-->"
    End If
    'collection des ID pour vérifiation purge
    Dim CollId As New ObjectIdCollection
    'Recherche de tous les xref du desssin.
    Dim mydb As Database = Application.DocumentManager.MdiActiveDocument.Database '= HostApplicationServices.WorkingDatabase
    Dim myTrans As Transaction = mydb.TransactionManager.StartTransaction
    'verrouillage du doc car modification !
    Dim doc As Document = Application.DocumentManager.MdiActiveDocument
    Dim DocLock As DocumentLock = doc.LockDocument

    Try
    'acces à la base des blocs
    Dim BlocTable As BlockTable = CType(myTrans.GetObject(mydb.BlockTableId, OpenMode.ForRead), BlockTable)
    For Each btid As ObjectId In BlocTable
    Dim DefBloc As BlockTableRecord = CType(myTrans.GetObject(btid, OpenMode.ForWrite), BlockTableRecord)
    'Si c'est une Xref non résolu
    If DefBloc.IsFromExternalReference = True Then
    'If DefBloc.IsResolved = False Then
    'cherche un path
    Dim Txt As String = GestionFichier.MiseAJourIndice(DefBloc.PathName, True)
    If (Txt <> "") Then
    CollId.Add(btid)
    CollIdXref.Add(btid)
    If (Txt.ToUpper <> DefBloc.PathName.ToUpper) Then
    GestionAUTOCAD.EcrireSurLigneDeCommande(strIndex & DefBloc.Name & "-> " & "MaJ !")
    DefBloc.PathName = Txt
    'si MaJ alors sortie et relancer la procedure car si Xref Remise à jour
    'la base globale est remise à jour de plus si un Xref dans Xref est en Supperposer
    '(DefBloc.IsFromOverlayReference) il sera toujours dans la base
    'donc il faut purger la base !
    OkRetour = False
    Else
    'si path non changer mem de l'id pour vérifier si celui ci peut être purgé
    'dans le cas ou l'Xref de l'Xref a été mis en Supperposé
    End If
    Else
    OkErreur = True
    GestionAUTOCAD.EcrireSurLigneDeCommande(strIndex & DefBloc.Name & "-> Impossible à trouver !")
    End If
    'Else
    ' CollIdXref.Add(btid)
    'End If
    End If
    Next
    myTrans.Commit()
    Catch ex As Exception
    MsgBox(ex.Message, vbOKOnly & vbCritical, "ee")
    Finally
    myTrans.Dispose()
    End Try
    DocLock.Dispose()
    DocLock = Nothing

    DocLock = doc.LockDocument
    'regen du xref
    If CollId.Count > 0 Then
    Try
    mydb.ReloadXrefs(CollId) 'ne pas oublié le commit

    Catch ex As Exception
    MsgBox(ex.ToString, MsgBoxStyle.Information, "Erreur système GestionArchive.MaJXRefDansTable")

    End Try
    'la fonction purge permet de savoir si les ID restant dans la collection
    'peuvent être purgés
    mydb.Purge(CollId) 'ne pas oublié le commit
    If CollId.Count > 0 Then
    myTrans = mydb.TransactionManager.StartTransaction
    'purge des éléments restants
    For Each Id As ObjectId In CollId
    'sup des id xref car il va être éffacé
    CollIdXref.Remove(Id)
    'effacement
    Dim obj As Object = myTrans.GetObject(Id, OpenMode.ForWrite)
    obj.Erase(True)
    Next
    myTrans.Commit()
    myTrans.Dispose()
    End If
    End If


    DocLock.Dispose()
    DocLock = Nothing

    Return OkRetour
    End Function

     this function retreave all xref, check if the xref as loaded if not i find the good file --> i add the id in the CollId

     

    after this acad crash saying : !dbobji.ccp@7227:eNotopenForWrite.

     

    I am running this with commandflags.Session !

    Public Class Start
        <CommandMethod("ProgAR", CommandFlags.Session)> _
        Public Sub ProgAR()

     

     

    This work fine but sometime i have this error. I dunno why..

    Could you help me to improve this code ?

     

    Thx.

     

    Sr the comment was in French.

    Please use plain text.
    *Expert Elite*
    chiefbraincloud
    Posts: 736
    Registered: ‎02-13-2008

    Re: eWasOpenForRead on ReloadXrefs(CollId)

    04-16-2012 10:20 AM in reply to: AubelecBE

    Sorry, my high school french is terrible.  I could only understand about half of your comments.

     

    The Session Flag is not necessary for this function, and I think after removing the Session Flag, the document locks won't be necessary either.  I am not sure that will solve the problem (I doubt it, in fact), but I just know that you should only use the Session flag if you really need to, and in this case I don't believe you need to use it.

    Dave O.                                                                 Sig-Logos32.png
    Please use plain text.
    Mentor
    Posts: 260
    Registered: ‎01-27-2010

    Re: eWasOpenForRead on ReloadXrefs(CollId)

    04-17-2012 03:20 AM in reply to: chiefbraincloud

    hi. I need the session floag. I need to close the file

    Please use plain text.