お知らせ

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Autodesk Community Tips- ADNオープン
Autodesk Community Tipsではちょっとしたコツ、やり方、ショートカット、アドバイスやヒントを共有しています。

AutoCADのAPIでレイヤーをロックした場合、レイヤー上のエンティティの表示がローライト表示されない

Question

AutoCADのAPIでレイヤーをロックした場合、レイヤー上のエンティティの表示がローライト表示されません。

GUIでレイヤーをロックする場合と同様にレイヤー上のエンティティをローライト表示する方法はありますか。

Answer

レイヤーのロックを設定する際に、レイヤーのプロパティを編集し、レイヤに変更がされたことをAutoCADエディタに認識させた後に、Regenを実行することでGUIからロック状態を変更した場合と同様に、ロックしたレイヤー上のエンティティをローライト表示させることが可能です。

 

以下は、上述の処理をLockという名前のレイヤーに対して実行するサンプルコードです。

 

C# 

[CommandMethod("Layerlack")]
static public void Layerlack()
{
	Document doc = Application.DocumentManager.MdiActiveDocument;
	Database db = doc.Database;
	Editor ed = doc.Editor;

	using (Transaction tr = db.TransactionManager.StartTransaction())
	{
		LayerTable table = tr.GetObject(db.LayerTableId,									OpenMode.ForRead) as LayerTable;
		if (table.Has("Lock"))
		{
			LayerTableRecord record = tr.GetObject(table["Lock"],OpenMode.ForWrite) as LayerTableRecord;
			record.IsLocked = true;
			
			record.LineWeight = record.LineWeight;
		}
		tr.Commit();
	}
	ed.Regen();
}

  

VBA

Sub Example_Lock()   
    Dim layerObj As AcadLayer
    Set layerObj = ThisDrawing.Layers.Add("Lock")
    
    layerObj.Lock = True
    layerObj.Lineweight = layerObj.Lineweight
    ThisDrawing.Regen acAllViewports
End Sub