I have a problem！ When I load a dwg file, i set all invisible layers to visible！The layer properties has been set to visible, but the entities on those invisible layers still can't see。 After that I change the layout，just change the 'model' to 'layout1' Then change back to 'model' . All entities is visible!
I mean what's the matter with that and how I can Solve the problem？
private void AddNewLayer(Document doc)
using (DocumentLock m_DocumentLock = doc.LockDocument())
string name = doc.Name;
using (Transaction tr = doc.Database.TransactionManager.StartTransaction()
LayerTable lt = (LayerTable)tr.GetObject(doc.Database.LayerTableId
SymbolTableEnumerator symbolTableEnumerator = lt.GetEnumerator();
LayerTableRecord activerecord = null;
while (symbolTableEnumerator.MoveNext() == true)
ObjectId objEntr = (ObjectId)symbolTableEnumerator.Current;
LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(objEntr, OpenMode.ForWrite);
ltr.IsOff = false;
Solved! Go to Solution.
After commit transaction, call doc.Editor.UpdateScreen() to update their visibility, doc.Editor.Regen() also updates visibility but slower as it will regenerate all entities.
"The UpdateScreen method redraws the application or document windows. The Regen method regenerates the graphical objects in the drawing window, and recomputes the screen coordinates and view resolution for all objects. It also re-indexes the drawing database for optimum display and object selection performance."
First, You should be using the TransactionManager of the Document, rather than it's Database (yes, there is a difference). For updating entities on the affected layers, you can call the RegenLayers() method of the Autodesk.AutoCAD.Internal.LayerUtilities class, and pass it the ObjectIds of the layers you want to regenerate which can be faster than a full regen.
UpdateScreen() will not help here, BTW.
Thanks for all! I try it ,but i am sorry it is not work.
When I change the mode now, it is also not work. However I click the 'Freezing new view' button on layer edit dialog then apply it, It is work now.It makes me very confusing!
Try this command:
then at the end of your directive add this line:
I use your method it is also not work。It get the error message of ‘can not find '?' entrypoint’
Mybe I find the reason，When I Execute the above AddNewLayer function， doc is not the activeDocument because it is starting。 So when I execute the doc.Editor.UpdateScreen() It is also get the error.
Thanks for all replies！ I have solved my problem。 All of this is that the doc is not the activedocument! When I Set DocuemntCollection.ActiveDocument=Doc
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register