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

VISRETAIN not work with ReadDwgFile

5 REPLIES 5
Reply
Message 1 of 6
harryliu3140
647 Views, 5 Replies

VISRETAIN not work with ReadDwgFile

Is there anyone want to try this on your computer?

 

Create a dwg with a xref, set VISRETAIN to 1. Freeze some layer and change color for some layer of the xref. Save the file.

 

Next time when you open the file those layers should stay at the same status as you saved.

 

Now try to open the dwg with DATABASE.ReadDwgFile(). Make some change if you want then save the dwg with DATABASE.SaveAs(). Open the dwg in ACAD and see if those layer stay at the same status as you saved.

 

On my computer I can see the DATABASE.VISRETAIN property is TRUE after ReadDwgFile(),  but xref status can't be retained after the dwg been saved by DATABASE.SaveAs().

 

Any response is appreciated.

5 REPLIES 5
Message 2 of 6
fieldguy
in reply to: harryliu3140

I can't replicate this issue.  It works as expected for me.  VISRETAIN remembers the settings I had before and after executing the following.

 

Autocad Map 3D 2010

VS 2008

 

Option Explicit On
Option Strict On

'reference acmgd
Imports Autodesk.AutoCAD.Runtime
'reference acdbmgd
Imports Autodesk.AutoCAD.DatabaseServices
'others
'reference system.drawing
Imports System.Drawing

Public Class VisTest

    <CommandMethod("vistest")> _
    Sub starthere()
        Dim dwgfile As String = "d:\acad\drawings\vistest.dwg"
        Dim myDB As New Autodesk.AutoCAD.DatabaseServices.Database
        myDB.ReadDwgFile(dwgfile, IO.FileShare.ReadWrite, True, "")
        Dim msg As String = "Visretain is "
        If myDB.Visretain = True Then
            msg = msg & "on"
        Else
            msg = msg & "off"
        End If
        MsgBox(msg)
        Using mytx As Transaction = myDB.TransactionManager.StartTransaction
            Dim vislayertable As LayerTable = CType(mytx.GetObject(myDB.LayerTableId, OpenMode.ForWrite), LayerTable)
            If Not vislayertable.Has("test") Then
                Dim newlayer As LayerTableRecord = New LayerTableRecord _
                    With {.Name = "test", .Color = Autodesk.AutoCAD.Colors.Color.FromColor(Drawing.Color.Red)}
                vislayertable.Add(newlayer)
                mytx.AddNewlyCreatedDBObject(newlayer, True)
            End If
            mytx.Commit()
        End Using
        myDB.SaveAs(dwgfile, DwgVersion.AC1800)
        myDB.Dispose()
        Dim xreffile As String = "d:\acad\drawings\xrefthis.dwg"
        Dim myXrefDB As New Autodesk.AutoCAD.DatabaseServices.Database
        myXrefDB.ReadDwgFile(xreffile, IO.FileShare.ReadWrite, True, "")
        Using mytx As Transaction = myXrefDB.TransactionManager.StartTransaction
            Dim xreflayertable As LayerTable = CType(mytx.GetObject(myXrefDB.LayerTableId, OpenMode.ForWrite), LayerTable)
            If Not xreflayertable.Has("test") Then
                Dim newlayer As LayerTableRecord = New LayerTableRecord _
                    With {.Name = "test", .Color = Autodesk.AutoCAD.Colors.Color.FromColor(Drawing.Color.Red)}
                xreflayertable.Add(newlayer)
                mytx.AddNewlyCreatedDBObject(newlayer, True)
            End If
            mytx.Commit()
        End Using
        myXrefDB.SaveAs(xreffile, DwgVersion.AC1800)
        myXrefDB.Dispose()
    End Sub

End Class

 

Message 3 of 6
harryliu3140
in reply to: fieldguy

Hi,

 

Thank you for quick reply.

 

I saw it last Friday. I notice one different in your code that is :

 

         myDB.ReadDwgFile(dwgfile, IO.FileShare.ReadWrite, True, "")

 

where in my code I use:

 

         dbdest.ReadDwgFile(sheetdwgfilename, IO.FileShare.ReadWrite,False, "")

 

After I changed the False to True, I got exception "Object reference not set to an instance of an object." at the statement of

 

         dbdest.SaveAs(sheetdwgfilename, DwgVersion.Current)

 

which in your code is :

 

         myDB.SaveAs(dwgfile, DwgVersion.AC1800)


But even I got the exception, the file was saved with my change, and the status of the xref was retained as what I want.

 

The problem half solved.

 

Do you have any idea of this exception?

 

Thank you.

Message 4 of 6
fieldguy
in reply to: harryliu3140

If you post your code I will try it - it's hard to tell without seeing it.

 

I would suspect a problem with your definition of sheetdwgfilename.

 

I should have added that we are still using Autocad 2004 as our standard DWG file format.  Autocad 2004 = DWGVERSION.AC1800.

Message 5 of 6
harryliu3140
in reply to: fieldguy

Hi,

 

I do have a warning on the  definition of sheetdwgfilename which is used before New(). Now I have no exception on SaveAs, but Visretain still not work.

 

Later I realize I have a statement before SaveAs:

       dbdest.ResolveXrefs(True, False)

 

This is the reason my xref status changed. After I comment it the problem gone.

 

Thank you for your time. I didn't post my code as I have OpengDWG and SaveAs in different sub and dbdest is a private member in Class. I made it too complex and don't want make you confused.

 

Have a nice weekend.

 

 

Message 6 of 6

Bit late, but you may want to refer to:

http://forums.autodesk.com/t5/NET/VISRETAIN-and-Purge/m-p/3807545/highlight/false

Dale




______________
Yes, I'm Satoshi.

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost