.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
kevinsir
875 Views, 11 Replies

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

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();
                }
              
            }
           
        }

11 REPLIES 11
Message 2 of 12
khoa.ho
in reply to: kevinsir

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

Message 3 of 12

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.

Message 4 of 12

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!

Message 5 of 12
kevinsir
in reply to: kevinsir

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

Message 6 of 12
Hallex
in reply to: kevinsir

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
Message 7 of 12
kevinsir
in reply to: Hallex

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.

Message 8 of 12

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

Message 9 of 12
kevinsir
in reply to: Hallex

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

Message 10 of 12

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

Message 11 of 12
kevinsir
in reply to: kevinsir

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’

///

}

Message 12 of 12
Hallex
in reply to: kevinsir

Then try again these both commands with adding this line,

but keep the CommandFlags still the same

 

Application.DocumentManager.DocumentActivationEnabled = true;

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost