Update Viewport with database is not working.

Update Viewport with database is not working.

cstotal_Autodesk
Contributor Contributor
527 Views
4 Replies
Message 1 of 5

Update Viewport with database is not working.

cstotal_Autodesk
Contributor
Contributor

I have no idea why after I work with vb.net with database, zoom of current view is changing.

 

so I want zoom extent the document without open document in editor, only database.readdwgfile

 

I found some code on .net forum but I guess it doesn't work.

 

Dim originalDB As Database = HostApplicationServices.WorkingDatabase

        Using AcadDB As New Database(False, True)
            AcadDB.ReadDwgFile(OldDwgFilePath, FileOpenMode.OpenForReadAndAllShare, False, Nothing)

            HostApplicationServices.WorkingDatabase = AcadDB

            If AcadDB.TileMode = True Then 'Model
                Using Trans As Transaction = AcadDB.TransactionManager.StartTransaction
                    Dim vpt As ViewportTable = Trans.GetObject(AcadDB.ViewportTableId, OpenMode.ForRead)
                    Dim vptr As ViewportTableRecord = Trans.GetObject(AcadDB.CurrentViewportTableRecordId, OpenMode.ForWrite)
                    vptr.CenterPoint = New Point2d(1000, 1000)
                    vptr.Height = 2000
                    vptr.Width = 2000

                    AcadDB.UpdateExt(True)
                End Using
            End If

            ZoomExtents_DB_2(AcadDB)

            AcadDB.SaveAs(NewDwgFilePath, DwgVersion.Current)
            HostApplicationServices.WorkingDatabase = originalDB

        End Using

 

what actual code I used, include calculate for zoom extent but I changed it for fixed number for testing view is changed so I changed it as real numbers and it doesn't work(also not working with calculated numbers obviously)

 

How can I change current views zoom without open in editor?

 

0 Likes
Accepted solutions (1)
528 Views
4 Replies
Replies (4)
Message 2 of 5

cstotal_Autodesk
Contributor
Contributor
Accepted solution

I just found if I saveas database when

 

HostApplicationServices.WorkingDatabase = dwgfile Database

 

It changes Zoom as Auto. so before saveas

 

changed HostApplicationServices.WorkingDatabase to origin database

Message 3 of 5

kerry_w_brown
Advisor
Advisor

Did you try committing the transaction ?

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 4 of 5

cstotal_Autodesk
Contributor
Contributor

oh Yes. as I wrote on reply myself, it was solved. thank for replying.

0 Likes
Message 5 of 5

JamesMaeding
Advisor
Advisor

I just rediscovered this after 2 hours of troubleshooting.

In my experience, only set HostApplicationServices.WorkingDatabase to side database while touching system vars using AcAp.SetSystemVariable() method.

 

I am not dealing with viewports though, just modelspace.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes