<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Autodesk and that annoying grid!! in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/autodesk-and-that-annoying-grid/m-p/12460116#M6155</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Try this way (or using the &lt;A href="https://forums.autodesk.com/t5/net/want-to-have-c-program-to-modify-dwg-and-save-into-dwg-format/m-p/12439905/highlight/true#M79788" target="_blank" rel="noopener"&gt;WorkingDatabase class&lt;/A&gt; as shown by &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt; )&lt;/P&gt;
&lt;LI-CODE lang="visual-basic"&gt;    ' Save the current working database
	Dim currentDb = HostApplicationServices.WorkingDatabase

    ' Create a new database
    Using newDB As New Database
        db.Wblock(newDB, oidC, New Point3d(0, 0, 0), DuplicateRecordCloning.Ignore)
		
		' Set the newDb as working database
		HostApplicationServices.WorkingDatabase = newDB

        ' turn the ****** grid off
        Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("SNAPMODE", 0)

        ' Save the new database
        newDB.SaveAs(wFile, DwgVersion.Current)
		
		' Reset the working database
		HostApplicationServices.WorkingDatabase = currentDb

        ' Send out the new items
        Using tr As Transaction = newDB.TransactionManager.StartTransaction
            Dim bt As BlockTable = DirectCast(tr.GetObject(newDB.BlockTableId, OpenMode.ForRead, True), BlockTable)
            Dim btrMs As BlockTableRecord = bt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
            Dim ids As ObjectIdCollection = New ObjectIdCollection()
            For Each btrID In btrMs
                Dim oBr = TryCast(tr.GetObject(btrID, OpenMode.ForRead), BlockReference)
                If Not IsNothing(oBr) Then
                    Select Case UCase(oBr.Name)
                        Case "UG_LINK_NC", "UG_LINK_NO", "SCH_UNITID"
                            ids.Add(oBr.ObjectId)
                    End Select
                End If
            Next

            tr.Commit()
        End Using
    End Using&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 24 Dec 2023 07:28:37 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2023-12-24T07:28:37Z</dc:date>
    <item>
      <title>Autodesk and that annoying grid!!</title>
      <link>https://forums.autodesk.com/t5/net-forum/autodesk-and-that-annoying-grid/m-p/12459835#M6154</link>
      <description>&lt;P&gt;Does anyone know how to turn the grid off when you wblock to a new drawing created by code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code. I know somewhere in here I need to do it, but I cannot find any variable other than viewport table records, which unfortunately are all dealt with in the active drawing.:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;    ' Send out the new items
    Using newDB As New Database
        db.Wblock(newDB, oidC, New Point3d(0, 0, 0), DuplicateRecordCloning.Ignore)
        newDB.SaveAs(wFile, DwgVersion.Current)

        ' turn the ****** grid off
        Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("SNAPMODE", 0)


        Using tr As Transaction = newDB.TransactionManager.StartTransaction
            Dim bt As BlockTable = DirectCast(tr.GetObject(newDB.BlockTableId, OpenMode.ForRead, True), BlockTable)
            Dim btrMs As BlockTableRecord = bt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
            Dim ids As ObjectIdCollection = New ObjectIdCollection()
            For Each btrID In btrMs
                Dim oBr = TryCast(tr.GetObject(btrID, OpenMode.ForRead), BlockReference)
                If Not IsNothing(oBr) Then
                    Select Case UCase(oBr.Name)
                        Case "UG_LINK_NC", "UG_LINK_NO", "SCH_UNITID"
                            ids.Add(oBr.ObjectId)
                    End Select
                End If
            Next

            tr.Commit()
        End Using
    End Using&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Turns out I needed to iterate the viewport table records and set the snapEnabled variable to false, THEN save the database... Duh!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for wasting everyone's time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Dec 2023 01:13:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autodesk-and-that-annoying-grid/m-p/12459835#M6154</guid>
      <dc:creator>js75CAD</dc:creator>
      <dc:date>2023-12-24T01:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Autodesk and that annoying grid!!</title>
      <link>https://forums.autodesk.com/t5/net-forum/autodesk-and-that-annoying-grid/m-p/12460116#M6155</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Try this way (or using the &lt;A href="https://forums.autodesk.com/t5/net/want-to-have-c-program-to-modify-dwg-and-save-into-dwg-format/m-p/12439905/highlight/true#M79788" target="_blank" rel="noopener"&gt;WorkingDatabase class&lt;/A&gt; as shown by &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt; )&lt;/P&gt;
&lt;LI-CODE lang="visual-basic"&gt;    ' Save the current working database
	Dim currentDb = HostApplicationServices.WorkingDatabase

    ' Create a new database
    Using newDB As New Database
        db.Wblock(newDB, oidC, New Point3d(0, 0, 0), DuplicateRecordCloning.Ignore)
		
		' Set the newDb as working database
		HostApplicationServices.WorkingDatabase = newDB

        ' turn the ****** grid off
        Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("SNAPMODE", 0)

        ' Save the new database
        newDB.SaveAs(wFile, DwgVersion.Current)
		
		' Reset the working database
		HostApplicationServices.WorkingDatabase = currentDb

        ' Send out the new items
        Using tr As Transaction = newDB.TransactionManager.StartTransaction
            Dim bt As BlockTable = DirectCast(tr.GetObject(newDB.BlockTableId, OpenMode.ForRead, True), BlockTable)
            Dim btrMs As BlockTableRecord = bt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
            Dim ids As ObjectIdCollection = New ObjectIdCollection()
            For Each btrID In btrMs
                Dim oBr = TryCast(tr.GetObject(btrID, OpenMode.ForRead), BlockReference)
                If Not IsNothing(oBr) Then
                    Select Case UCase(oBr.Name)
                        Case "UG_LINK_NC", "UG_LINK_NO", "SCH_UNITID"
                            ids.Add(oBr.ObjectId)
                    End Select
                End If
            Next

            tr.Commit()
        End Using
    End Using&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Dec 2023 07:28:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autodesk-and-that-annoying-grid/m-p/12460116#M6155</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2023-12-24T07:28:37Z</dc:date>
    </item>
  </channel>
</rss>

