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();
}
}
}
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.
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
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:
<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'~
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.
I'm using AutoCAD 2008,and i have not find the Autodesk.AutoCAD.Internal.LayerUtilities class!
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
The document you're modifying must be the active document or all bets are off
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’
///
}
Then try again these both commands with adding this line,
but keep the CommandFlags still the same
Application.DocumentManager.DocumentActivationEnabled = true;
~'J'~
Can't find what you're looking for? Ask the community or share your knowledge.