.NET

.NET

Reply
Active Contributor
harryliu3140
Posts: 46
Registered: ‎10-29-2009
Message 1 of 6 (415 Views)

VISRETAIN not work with ReadDwgFile

415 Views, 5 Replies
08-12-2011 08:49 AM

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.

Valued Mentor
fieldguy
Posts: 382
Registered: ‎03-31-2005
Message 2 of 6 (394 Views)

Re: VISRETAIN not work with ReadDwgFile

08-12-2011 01:00 PM 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

 

Active Contributor
harryliu3140
Posts: 46
Registered: ‎10-29-2009
Message 3 of 6 (361 Views)

Re: VISRETAIN not work with ReadDwgFile

08-15-2011 08:19 AM 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.

Valued Mentor
fieldguy
Posts: 382
Registered: ‎03-31-2005
Message 4 of 6 (355 Views)

Re: VISRETAIN not work with ReadDwgFile

08-15-2011 09:54 AM 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.

Active Contributor
harryliu3140
Posts: 46
Registered: ‎10-29-2009
Message 5 of 6 (331 Views)

Re: VISRETAIN not work with ReadDwgFile

08-19-2011 12:20 PM 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.

 

 

Distinguished Contributor
Dale.Bartlett
Posts: 175
Registered: ‎01-06-2003
Message 6 of 6 (165 Views)

Re: VISRETAIN not work with ReadDwgFile

03-17-2013 10:06 PM in reply to: harryliu3140
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.