Set document variable (in memory)

Set document variable (in memory)

ym.56789
Contributor Contributor
705 Views
4 Replies
Message 1 of 5

Set document variable (in memory)

ym.56789
Contributor
Contributor

Hi, I have a number of files where the variable VISRETAIN as to be updated.

I would like to do so by loading the document in memory.

 

I have the following code:

 

Dim myDB As New Database(False, True)
myDB.ReadDwgFile(file, FileOpenMode.OpenForReadAndAllShare, False, "")

 

Is there a way to set drawing variables from the database? And if I must get a document object, is there a way to load a document in memory?

(I found that I can set variables within a document as follows: acadDocument.Setvariable("DIMASZ",1.5).

 

Thanks

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

_gile
Consultant
Consultant
Accepted solution

Hi,

 

The Database class exposes a Visretain property. you can simply do:

myDB.VisRetain = 0

or:

myDB.VisRetain = 1



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 5

ym.56789
Contributor
Contributor

Thank you very much for your answer - I see I can access all other document variables in this manner as well.

 

Can you perhaps help me further though? I don't seem to know how to save the variable: (here's my code)

 

Dim myDB As New Database(False, True)
myDB.ReadDwgFile(file, FileOpenMode.OpenForReadAndWriteNoShare, False, "")
Using myTrans As Transaction = myDB.TransactionManager.StartTransaction
myDB.Visretain = 0
myTrans.Commit()
End Using

 

The code runs with no errors, but when I open up the file VISRETAIN is still at 1. (Additionally in the file properties the date modified property shows the file was not modified recently.)

 

Thanks

0 Likes
Message 4 of 5

_gile
Consultant
Consultant

You have to save your database before disposing it.

Using myDB As New Database(False, True)
    myDB.ReadDwgFile(file, FileOpenMode.OpenForReadAndWriteNoShare, False, "")
    Using myTrans As Transaction = myDB.TransactionManager.StartTransaction
        myDB.Visretain = 0
        myTrans.Commit()
    End Using
    myDB.SaveAs(file, DwgVersion.Current)
End Using


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 5

ym.56789
Contributor
Contributor

Thanks a lot!

0 Likes