Document does not appear to save

Document does not appear to save

dbrblg
Collaborator Collaborator
1,620 Views
7 Replies
Message 1 of 8

Document does not appear to save

dbrblg
Collaborator
Collaborator

Im using ObjectDBX to correct text in a document.  The idea is that I open the document and iterate through the text and block text updating it along the way before saving. 

When I open the document again nothing appears to have changed.

Private Function t()

    Dim aDBX As AxDbDocument
    Dim FileName As String
    
    FileName = "C:\doc\Desktop\ect\93.dwg"    
    Set aDBX = AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument." & Left$(ThisDrawing.GetVariable("AcadVer"), 2))
       
    Call aDBX.Open(FileName)
    Call UpdateAttributePosistionNamedDocument(aDBX)
    Call aDBX.SaveAs(FileName)
       
End Function

There are no errors opening or saving and the code just sails through.

But, because I cannot see what is occurring real-time, there is little point setting breakpoints and stepping through....

I cannot confirm at which step the problem is occurring.

Public Function UpdateAttributePosistionNamedDocument(oDocument As AxDbDocument)

    Dim objEntity As AcadEntity
    Dim objBlockRef As AcadBlockReference
    Dim objAttriRef As AcadAttributeReference
    Dim AttriList() As AcadAttributeReference
    Dim objAttributes As AcadAttributeReference
    Dim objTextEntity As AcadText
    Dim dBlocks As New Dictionary
    Dim i As Integer
    
    dBlocks.CompareMode = TextCompare
    
    For Each objEntity In oDocument.ModelSpace
        If (TypeOf objEntity Is AcadBlockReference) Then
            Set objBlockRef = objEntity
            
            If (Not dBlocks.Exists(objBlockRef.Name)) Then
                If objBlockRef.HasAttributes Then
                    AttriList = objBlockRef.GetAttributes
                    For i = LBound(AttriList) To UBound(AttriList)
                        Set objAttributes = AttriList(i)
                        objAttributes.Update
                        objBlockRef.Update
                    Next
                End If
            End If
            
        End If
        
        If (TypeOf objEntity Is AcadText) Then
            Set objTextEntity = objEntity
            objTextEntity.Update
        End If
    Next
    
End Function

I am fairly sure the UpdateAttributePosistionNamedDocument function works as I have a variant of this:

Public Function UpdateAttributePosistion()

in which the line

For Each objEntity In oDocument.ModelSpace

is renamed to

For Each objEntity In ThisDrawing.ModelSpace

I open a drawing and run this function and the text and blocks update as expected, so the logic seems sound and appears to be a problem introducing the ObjectDBX aspect of the code.

0 Likes
1,621 Views
7 Replies
Replies (7)
Message 2 of 8

Ed__Jobe
Mentor
Mentor

I don't know if you have shown all your code, but in the following snippet, it doesn't look like you've changed any properties before calling the Update method.

 

                    For i = LBound(AttriList) To UBound(AttriList)
                        Set objAttributes = AttriList(i)
                        objAttributes.Update  'What's changed?
                        objBlockRef.Update
                    Next

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 8

dbrblg
Collaborator
Collaborator

Hi @Ed__Jobe ,yes all the code is shown....

 

A little background information.  Recently I had a problem with some drawings where the text (and attributes too!!) justification grip would be incorrectly shown in the wrong place.  So for example, I had text with Middle Center justification but the grip was not in the middle center of the text.

After positing this to the forum, it was decided the cause was unknown but a solution was to invoke the Update method of the text which did correct the position of the text grip.

 

All the update method is doing is 'refreshing' or 'updating' the text.

0 Likes
Message 4 of 8

Ed__Jobe
Mentor
Mentor

OK, thanks.

Is the document open in acad when you run the function? btw, a function should return an object. If not, use Sub instead.

As a test, you could try

Call aDBX.SaveAs("x_" & FileName)

 

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 8

dbrblg
Collaborator
Collaborator

Good call@Ed__Jobe

Changed code to

Private Function t()

    Dim aDBX As AxDbDocument
    Dim FileName As String
Dim SaveAsFileName As String FileName = "C:\doc\Desktop\ect\93.dwg"
SaveAsFileName = "C:\doc\Desktop\ect\x_93.dwg" Set aDBX = AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument." & Left$(ThisDrawing.GetVariable("AcadVer"), 2)) Call aDBX.Open(FileName) Call UpdateAttributePosistionNamedDocument(aDBX) Call aDBX.SaveAs(SaveAsFileName ) End Function

The file is saved under a different filename, as expected, however none of the changes are present. 

 

So, I guess we can conculde it is not an issue with the saving of the file but whether the update has occurred...

0 Likes
Message 6 of 8

Ed__Jobe
Mentor
Mentor

As Norman mentioned in another thread, ObjectDBX cannot do some things because the editor is not present. It's possible that updating the grips is one of them. You could try some other edit like adding a line at 0,0. If that works, you know the SaveAS operation is working, but the grips are not being updated.

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 8

norman.yuan
Mentor
Mentor

It is a known issue with AutoCAD .NET API (or even ObjectARX C++ API) that if attribute of a block reference changed its text value (thus its width, obviously) in side database processing (i.e. the drawing is not opened in AutoCAD editor), the attribute's alignment does not get updated. The solution in AutoCAD .NET API is to set the side database as AutoCAD application's WorkingDatabase.

 

I suspect this is the same issue with opening drawing in memory as AxDbDocument with ObjectDBX COM API. However, in ObjectDBX COM API, there is no similar counterpart as WorkingDatabase in .NET API, thus, if you have attributes that are not aligned correctly (how that happened? were those drawings batched processed in someway that caused this issue?), then using ObjectDBX may not be the solution. Maybe, you find the root cause and correct it there, or you may have to actually open the drawing in AutoCAD as opened AcadDocument, instead of AxDbDocument to run your code.

 

However, one more thing to try: after the AxDbDocument processing, opening the drawing in AutoCAD, and not seeing changes, enter command "Regen" to see if the affected attributes correct them self.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 8 of 8

dbrblg
Collaborator
Collaborator

@norman.yuanI wasn't aware of the issues surrounding text in drawings when they are opened via the database....

I haven't caused these text issues, I am only trying to fix them via this code.  How the text misalignment occurred is a mystery.

Doing a regen after opening the file again has no effect.

 

@Ed__JobeAdding the line at 0,0 as suggested shows after the file is reopened, so it appears that it is to do with the text update and not saving...

0 Likes