明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1601|回复: 5

设置当前线型?

[复制链接]
发表于 2009-9-10 10:42 | 显示全部楼层 |阅读模式
请问大侠,怎么设置当前线型啊?(Net)
发表于 2009-9-10 10:54 | 显示全部楼层

系统变量CELTYPE

不过一般是设置当前图层吧CLAYER

 楼主| 发表于 2009-9-11 18:43 | 显示全部楼层

知道CLayer,但是一个层有多种线型,画图时设置当前线型可以预览,请高手指教!

发表于 2009-9-11 18:47 | 显示全部楼层
 楼主| 发表于 2009-9-13 10:05 | 显示全部楼层
<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">[CommandMethod("SetLinetypeCurrent")]</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[sLineTypName];</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>
发表于 2009-9-13 12:20 | 显示全部楼层
2010版以前的Has函数是有Bug的
可以用下面的函数,我直接封装在DBTransaction类里了:)
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=76123
  1.          //在符号表中获取对应键值的记录Id
  2.          //弥补索引器的Bug
  3.          //即会获取已清除并存在符号表的记录
  4.          //但2010版该Bug已消除
  5.          public ObjectId GetIdFromSymbolTable(SymbolTable st, string key)
  6.          {
  7.              if (st.Has(key))
  8.              {
  9.                  ObjectId idres = st[key];
  10.                  if (!idres.IsErased)
  11.                      return idres;
  12.                  foreach (ObjectId id in st)
  13.                  {
  14.                      if (!id.IsErased)
  15.                      {
  16.                          SymbolTableRecord str = (SymbolTableRecord)m_Transaction.GetObject(id, OpenMode.ForRead);
  17.                          if (str.Name == key)
  18.                              return id;
  19.                      }
  20.                  }
  21.              }
  22.              return ObjectId.Null;
  23.          }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-10 15:18 , Processed in 0.135404 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表