设置当前线型?
请问大侠,怎么设置当前线型啊?(Net) <p>系统变量CELTYPE</p><p>不过一般是设置当前图层吧CLAYER</p> <p>知道CLayer,但是一个层有多种线型,画图时设置当前线型可以预览,请高手指教!</p> <p>预览线型的对话框?Cad自带的么</p><p>看看这里</p><p><a href="http://www.mjtd.com/bbs/dispbbs.asp?boardid=33&replyid=10021&id=75921&page=1&skin=0&landlord=0&Star=2">http://www.mjtd.com/bbs/dispbbs.asp?boardid=33&replyid=10021&id=75921&page=1&skin=0&landlord=0&Star=2</a></p><p>13楼</p> <pre class="codeLine">using Autodesk.AutoCAD.Runtime;</pre><pre class="codeLine">using Autodesk.AutoCAD.ApplicationServices;</pre><pre class="codeLine">using Autodesk.AutoCAD.DatabaseServices;</pre><pre class="codeLine"></pre><pre class="codeLine"></pre><pre class="codeLine">public static void SetLinetypeCurrent()</pre><pre class="codeLine">{</pre><pre class="codeLine">// Get the current document and database</pre><pre class="codeLine">Document acDoc = Application.DocumentManager.MdiActiveDocument;</pre><pre class="codeLine">Database acCurDb = acDoc.Database;</pre><pre class="codeLine">
</pre><pre class="codeLine">// Start a transaction</pre><pre class="codeLine">using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())</pre><pre class="codeLine">{</pre><pre class="codeLine"> // Open the Linetype table for read</pre><pre class="codeLine"> LinetypeTable acLineTypTbl;</pre><pre class="codeLine"> acLineTypTbl = acTrans.GetObject(acCurDb.LinetypeTableId,</pre><pre class="codeLine"> OpenMode.ForRead) as LinetypeTable;</pre><pre class="codeLine">
</pre><pre class="codeLine"> string sLineTypName = "Center";</pre><pre class="codeLine">
</pre><pre class="codeLine"> if (acLineTypTbl.Has(sLineTypName) == true)</pre><pre class="codeLine"> {</pre><pre class="codeLine"> // Set the linetype Center current</pre><pre class="codeLine"> acCurDb.Celtype = acLineTypTbl;</pre><pre class="codeLine">
</pre><pre class="codeLine"> // Save the changes</pre><pre class="codeLine"> acTrans.Commit();</pre><pre class="codeLine"> }</pre><pre class="codeLine">
</pre><pre class="codeLine"> // Dispose of the transaction</pre><pre class="codeLine">}</pre><pre class="codeLine">}</pre> 2010版以前的Has函数是有Bug的
可以用下面的函数,我直接封装在DBTransaction类里了:)
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=76123
//在符号表中获取对应键值的记录Id
//弥补索引器的Bug
//即会获取已清除并存在符号表的记录
//但2010版该Bug已消除
public ObjectId GetIdFromSymbolTable(SymbolTable st, string key)
{
if (st.Has(key))
{
ObjectId idres = st;
if (!idres.IsErased)
return idres;
foreach (ObjectId id in st)
{
if (!id.IsErased)
{
SymbolTableRecord str = (SymbolTableRecord)m_Transaction.GetObject(id, OpenMode.ForRead);
if (str.Name == key)
return id;
}
}
}
return ObjectId.Null;
}
页:
[1]