Autodesk and that annoying grid!!

Autodesk and that annoying grid!!

js75CAD
Enthusiast Enthusiast
310 Views
1 Reply
Message 1 of 2

Autodesk and that annoying grid!!

js75CAD
Enthusiast
Enthusiast

Does anyone know how to turn the grid off when you wblock to a new drawing created by code?

 

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.:

 

    ' 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

 

 

Turns out I needed to iterate the viewport table records and set the snapEnabled variable to false, THEN save the database... Duh!

 

Sorry for wasting everyone's time.

 

0 Likes
Accepted solutions (1)
311 Views
1 Reply
Reply (1)
Message 2 of 2

_gile
Consultant
Consultant
Accepted solution

Hi,

Try this way (or using the WorkingDatabase class as shown by @ActivistInvestor )

    ' 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

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes