.NET

.NET

Reply
Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 1 of 12 (411 Views)
Accepted Solution

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

411 Views, 11 Replies
10-10-2012 02:07 AM

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

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

Mentor
khoa.ho
Posts: 224
Registered: ‎09-15-2011
Message 2 of 12 (393 Views)

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

10-10-2012 07:37 AM 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

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 3 of 12 (373 Views)

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

10-10-2012 01:00 PM in reply to: kevinsir

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.

Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 4 of 12 (361 Views)

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

10-10-2012 04:44 PM in reply to: DiningPhilosopher

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!

Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 5 of 12 (352 Views)

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

10-10-2012 07:23 PM in reply to: kevinsir

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

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 6 of 12 (342 Views)

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

10-10-2012 10:43 PM 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
Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 7 of 12 (333 Views)

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

10-11-2012 12:24 AM 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.

Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 8 of 12 (330 Views)

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

10-11-2012 12:50 AM in reply to: DiningPhilosopher

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

Valued Contributor
kevinsir
Posts: 78
Registered: ‎08-20-2012
Message 9 of 12 (324 Views)

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

10-11-2012 01:51 AM 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

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 10 of 12 (269 Views)

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

10-13-2012 07:52 PM in reply to: kevinsir

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.