The layer properties has been set to visible, but layers still can't see

The layer properties has been set to visible, but layers still can't see

Anonymous
Not applicable
1,395 Views
11 Replies
Message 1 of 12

The layer properties has been set to visible, but layers still can't see

Anonymous
Not applicable

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)
        {
            if (doc.IsReadOnly)
                return;
            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, OpenMode.ForWrite);
                    SymbolTableEnumerator symbolTableEnumerator = lt.GetEnumerator();
                    LayerTableRecord activerecord = null;
                    while (symbolTableEnumerator.MoveNext() == true)
                    {
                        ObjectId objEntr = (ObjectId)symbolTableEnumerator.Current;
                        LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(objEntr, OpenMode.ForWrite);
                        if (ltr.IsOff)
                        {
                            ltr.IsOff = false;
                        }
                    }
                    tr.Commit();
                }
              
            }
           
        }

0 Likes
Accepted solutions (1)
1,396 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable

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.

 

From AutoCAD .NET documentation:

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

 

-Khoa

0 Likes
Message 3 of 12

DiningPhilosopher
Collaborator
Collaborator

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.

0 Likes
Message 4 of 12

Anonymous
Not applicable

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!

0 Likes
Message 5 of 12

Anonymous
Not applicable

I just input 'regen' command in editor,but it is not work !

0 Likes
Message 6 of 12

Hallex
Advisor
Advisor

Try this command:

<DllImport("acad.exe", EntryPoint:="?applyCurDwgLayerTableChanges@@YA?AW4ErrorStatus@Acad@@XZ")> _ Private Shared Sub applyCurDwgLayerTableChanges() End Sub

then at the end of your directive add this line:

applyCurDwgLayerTableChanges()

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 7 of 12

Anonymous
Not applicable

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.

0 Likes
Message 8 of 12

Anonymous
Not applicable

I'm using AutoCAD 2008,and i have not find the Autodesk.AutoCAD.Internal.LayerUtilities class!

0 Likes
Message 9 of 12

Anonymous
Not applicable
Accepted solution

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

0 Likes
Message 10 of 12

DiningPhilosopher
Collaborator
Collaborator

The document you're modifying must be the active document or all bets are off

Message 11 of 12

Anonymous
Not applicable

I use custom command!

I find that when I excute the opendwg funtion of  documentcollection

it is different of these two function。

[CommandMethod("openDwg",CommandFlags.Session)]

public void OpenDwg(string fileName)        

{            

Document activeDocument = Application.DocumentManager.Open(fileName,false,string.Empty);  

///after this function  activeDocument is the activedocument 

}

//if i remove the commandflags

[CommandMethod("openDwg")]

public void OpenDwg(string fileName)       

{            

Document activeDocument = Application.DocumentManager.Open(fileName,false,string.Empty); 

///after this function  activeDocument is  ‘drawing1’

///

}

0 Likes
Message 12 of 12

Hallex
Advisor
Advisor

Then try again these both commands with adding this line,

but keep the CommandFlags still the same

 

Application.DocumentManager.DocumentActivationEnabled = true;

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes