乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 102|回复: 8

[原创]DBTransaction类

[复制链接]

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-6-4 12:45:00 | 显示全部楼层 |阅读模式
其实很早前就在论坛里贴过早期的版本,不算新内容
没有做详细的测试,还希望各位朋友指正:)
简单的注释了下:)
DBTransaction.cs
  1. #define AC2008
  2. using System;
  3. using System.IO;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Collections.Specialized;
  7. using Autodesk..ApplicationServices;
  8. using Autodesk.AutoCAD.DatabaseServices;
  9. using Autodesk.AutoCAD.EditorInput;
  10. using Autodesk.AutoCAD.Geometry;
  11. namespace TlsCad
  12. {
  13.     public class DBTransaction : IDisposable
  14.     {
  15.         private Database m_Database;
  16.         private Transaction m_Transaction;
  17.         private bool m_Commit = false;
  18.         private BlockTableRecord m_BlockTableRecord;
  19.         private BlockTable m_BlockTable;
  20.         private TextStyleTable m_TextStyleTable;
  21.         private LinetypeTable m_LinetypeTable;
  22.         private RegAppTable m_RegAppTable;
  23.         private LayerTable m_LayerTable;
  24.         private UcsTable m_UcsTable;
  25.         private ViewTable m_ViewTable;
  26.         private ViewportTable m_ViewportTable;
  27.         private DrawOrderTable m_DrawOrderTable;
  28.         private DBDictionary m_GroupDictionary;
  29.         //事务相关
  30.         #region Tran
  31.         //事务初始化,并只读方式打开块表
  32.         private void Initialize()
  33.         {
  34.             try
  35.             {
  36.                 m_Transaction = m_Database.TransactionManager.StartTransaction();
  37.                 m_BlockTable = (BlockTable)m_Transaction.GetObject(m_Database.BlockTableId, OpenMode.ForRead, false);
  38.             }
  39.             catch (Autodesk.AutoCAD.Runtime.Exception ex)
  40.             {
  41.                 CadHelper.InfoMessageBox(ex.Message);
  42.             }
  43.         }
  44.         //创建当前活动文档的事务(默认提交)
  45.         public DBTransaction()
  46.         {
  47.             m_Database = HostApplicationServices.WorkingDatabase;
  48.             Initialize();
  49.         }
  50.         //创建当前活动文档的事务
  51.         //commit = true 提交事务
  52.         //commit = false 不提交
  53.         public DBTransaction(bool commit)
  54.         {
  55.             m_Commit = !commit;
  56.             m_Database = HostApplicationServices.WorkingDatabase;
  57.             Initialize();
  58.         }
  59.         //创建指定数据库的事务,一般用于临时数据库(默认提交)
  60.         public DBTransaction(Database database)
  61.         {
  62.             m_Database = database;
  63.             Initialize();
  64.         }
  65.         //创建指定数据库的事务
  66.         //commit = true 提交事务
  67.         //commit = false 不提交
  68.         public DBTransaction(Database database, bool commit)
  69.         {
  70.             m_Commit = !commit;
  71.             m_Database = database;
  72.             Initialize();
  73.         }
  74.         //创建临时数据库的事务,并读入指定的文档(默认提交)
  75.         public DBTransaction(string fileName)
  76.         {
  77.             try
  78.             {
  79.                 m_Database = new Database(false, true);
  80.                 m_Database.ReadDwgFile(fileName, FileShare.Read, true, null);
  81.                 Initialize();
  82.             }
  83.             catch
  84.             { }
  85.         }
  86.         //创建临时数据库的事务,并读入指定的文档
  87.         //commit = true 提交事务
  88.         //commit = false 不提交
  89.         public DBTransaction(string DwgFileName, bool commit)
  90.         {
  91.             m_Commit = !commit;
  92.             try
  93.             {
  94.                 m_Database = new Database(false, true);
  95.                 m_Database.ReadDwgFile(DwgFileName, FileShare.Read, true, null);
  96.                 Initialize();
  97.             }
  98.             catch
  99.             { }
  100.         }
  101.         //
  102.         void IDisposable.Dispose()
  103.         {
  104.             Commit();
  105.             m_Transaction.Dispose();
  106.         }
  107.         //按事务初始化参数决定事物是否提交
  108.         public void Commit()
  109.         {
  110.             if (!m_Commit)
  111.             {
  112.                 m_Transaction.Commit();
  113.                 m_Commit = true;
  114.             }
  115.         }
  116.         //撤销事务
  117.         public void Abort()
  118.         {
  119.             m_Transaction.Abort();
  120.         }
  121.         #endregion
  122.         //在符号表中获取对应键值的记录Id
  123.         //弥补索引器的Bug
  124.         //即会获取已清除并存在符号表的记录
  125.         //但2010版该Bug已消除
  126.         public ObjectId GetIdFromSymbolTable(SymbolTable st, string key)
  127.         {
  128.             if (st.Has(key))
  129.             {
  130.                 ObjectId idres = st[key];
  131.                 if (!idres.IsErased)
  132.                     return idres;
  133. #if AC2008
  134.                 foreach (ObjectId id in st)
  135.                 {
  136.                     if (!id.IsErased)
  137.                     {
  138.                         SymbolTableRecord str = (SymbolTableRecord)m_Transaction.GetObject(id, OpenMode.ForRead);
  139.                         if (str.Name == key)
  140.                             return id;
  141.                     }
  142.                 }
  143. #endif
  144.             }
  145.             return ObjectId.Null;
  146.         }
  147.         //属性
  148.         #region Properties
  149.         public Database Database
  150.         {
  151.             get { return m_Database; }
  152.         }
  153.         public Transaction Transaction
  154.         {
  155.             get { return m_Transaction; }
  156.         }
  157.         public BlockTableRecord CurrentBlockTableRecord
  158.         {
  159.             get { return m_BlockTableRecord; }
  160.         }
  161.         public BlockTable BlockTable
  162.         {
  163.             get { return m_BlockTable; }
  164.         }        public LayerTable LayerTable
  165.         {
  166.             get { return m_LayerTable; }
  167.         }
  168.         public TextStyleTable TextStyleTable
  169.         {
  170.             get { return m_TextStyleTable; }
  171.         }
  172.         public RegAppTable RegAppTable
  173.         {
  174.             get { return m_RegAppTable; }
  175.         }
  176.         public LinetypeTable LinetypeTable
  177.         {
  178.             get { return m_LinetypeTable; }
  179.         }
  180.         public UcsTable UcsTable
  181.         {
  182.             get { return m_UcsTable; }
  183.         }
  184.         public ViewTable ViewTable
  185.         {
  186.             get { return m_ViewTable; }
  187.         }
  188.         public ViewportTable ViewportTable
  189.         {
  190.             get { return m_ViewportTable; }
  191.         }
  192.         public DrawOrderTable DrawOrderTable
  193.         {
  194.             get { return m_DrawOrderTable; }
  195.         }
  196.         public DBDictionary GroupDictionary
  197.         {
  198.             get { return m_GroupDictionary; }
  199.         }
  200.         #endregion
  201.         //块表记录
  202.         #region BlockTableRecord
  203.         
  204.         public BlockTableRecord OpenBlockTableRecord(ObjectId id, OpenMode openmode)
  205.         {
  206.             m_BlockTableRecord = (BlockTableRecord)m_Transaction.GetObject(
  207.                 id,
  208.                 openmode,
  209.                 false);
  210.             return m_BlockTableRecord;
  211.         }
  212.         public BlockTableRecord OpenBlockTableRecord(ObjectId id)
  213.         {
  214.             return OpenBlockTableRecord(id, OpenMode.ForWrite);
  215.         }
  216.         public BlockTableRecord OpenBlockTableRecord(string name, OpenMode openmode)
  217.         {
  218.             ObjectId id = GetIdFromSymbolTable(m_BlockTable, name);
  219.             if (id == ObjectId.Null)
  220.                 return null;
  221.             return OpenBlockTableRecord(id, openmode);
  222.         }
  223.         public BlockTableRecord OpenBlockTableRecord(string name)
  224.         {
  225.             return OpenBlockTableRecord(m_BlockTable[name], OpenMode.ForWrite);
  226.         }
  227.         public void OpenCurrentSpace(OpenMode openmode)
  228.         {
  229.             OpenBlockTableRecord(m_Database.CurrentSpaceId, openmode);
  230.         }
  231.         public void OpenCurrentSpace()
  232.         {
  233.             OpenCurrentSpace(OpenMode.ForWrite);
  234.         }
  235.         public void OpenPaperSpace(OpenMode openmode)
  236.         {
  237.             OpenBlockTableRecord(BlockTableRecord.PaperSpace, openmode);
  238.         }
  239.         public void OpenPaperSpace()
  240.         {
  241.             OpenPaperSpace(OpenMode.ForWrite);
  242.         }
  243.         public void OpenModelSpace(OpenMode openmode)
  244.         {
  245.             OpenBlockTableRecord(BlockTableRecord.ModelSpace, openmode);
  246.         }        public void OpenModelSpace()
  247.         {
  248.             OpenModelSpace(OpenMode.ForWrite);
  249.         }
  250.         public DBObject GetObject(ObjectId id, OpenMode openmode)
  251.         {
  252.             return m_Transaction.GetObject(id, openmode, false);
  253.         }
  254.         #endregion
  255.         //层表
  256.         #region LayerTable
  257.         public LayerTable OpenLayerTable(OpenMode openmode)
  258.         {
  259.             m_LayerTable = (LayerTable)m_Transaction.GetObject(
  260.                 m_Database.LayerTableId,
  261.                 openmode,
  262.                 false);
  263.             return m_LayerTable;
  264.         }
  265.         public LayerTable OpenLayerTable()
  266.         {
  267.             return OpenLayerTable(OpenMode.ForWrite);
  268.         }
  269.         public ObjectId AddLayer(string name, Autodesk.AutoCAD.Colors.Color color, ObjectId linetypeid, LineWeight lineweight)
  270.         {
  271.             ObjectId id = GetIdFromSymbolTable(m_LayerTable, name);
  272.             if (id == ObjectId.Null)
  273.             {
  274.                 LayerTableRecord layer = new LayerTableRecord();
  275.                 layer.Name = name;
  276.                 layer.Color = color;
  277.                 layer.LinetypeObjectId = linetypeid;
  278.                 layer.LineWeight = lineweight;
  279.                 m_LayerTable.UpgradeOpen();
  280.                 id = m_LayerTable.Add(layer);
  281.                 m_Transaction.AddNewlyCreatedDBObject(layer, true);
  282.             }
  283.             return id;
  284.         }
  285.         #endregion
  286.         //文字式样表
  287.         #region TextStyleTable
  288.         public TextStyleTable OpenTextStyleTable(OpenMode openmode)
  289.         {
  290.             m_TextStyleTable = (TextStyleTable)m_Transaction.GetObject(
  291.                 m_Database.TextStyleTableId,
  292.                 openmode,
  293.                 false);
  294.             return m_TextStyleTable;
  295.         }
  296.         public TextStyleTable OpenTextStyleTable()
  297.         {
  298.             return OpenTextStyleTable(OpenMode.ForWrite);
  299.         }
  300.         public ObjectId AddTextStyle(string name, string smallfont, string bigfont, double height, double xscale)
  301.         {
  302.             ObjectId id = GetIdFromSymbolTable(m_TextStyleTable, name);
  303.             if (id == ObjectId.Null)
  304.             {
  305.                 TextStyleTableRecord tstr = new TextStyleTableRecord();
  306.                 tstr.Name = name;
  307.                 tstr.FileName = smallfont;
  308.                 tstr.BigFontFileName = bigfont;
  309.                 tstr.TextSize = height;
  310.                 tstr.XScale = xscale;
  311.                 m_TextStyleTable.UpgradeOpen();
  312.                 id = m_TextStyleTable.Add(tstr);
  313.                 m_Transaction.AddNewlyCreatedDBObject(tstr, true);
  314.             }
  315.             return id;
  316.         }        #endregion
  317.         //注册应用程序
  318.         #region RegAppTable
  319.         public RegAppTable OpenRegAppTable(OpenMode openmode)
  320.         {
  321.             m_RegAppTable = (RegAppTable)m_Transaction.GetObject(
  322.                 m_Database.RegAppTableId,
  323.                 openmode,
  324.                 false);
  325.             return m_RegAppTable;
  326.         }
  327.         public RegAppTable OpenRegAppTable()
  328.         {
  329.             return OpenRegAppTable(OpenMode.ForWrite);
  330.         }
  331.         public ObjectId RegApp(string name)
  332.         {
  333.             ObjectId id = GetIdFromSymbolTable(m_RegAppTable, name);
  334.             if (id == ObjectId.Null)
  335.             {
  336.                 RegAppTableRecord regapp = new RegAppTableRecord();
  337.                 regapp.Name = name;
  338.                 id = m_RegAppTable.Add(regapp);
  339.                 m_Transaction.AddNewlyCreatedDBObject(regapp, true);
  340.             }
  341.             return id;
  342.         }
  343.         #endregion
  344.         //线型表
  345.         #region LinetypeTable
  346.         public LinetypeTable OpenLinetypeTable(OpenMode openmode)
  347.         {
  348.             m_LinetypeTable = (LinetypeTable)m_Transaction.GetObject(
  349.                 m_Database.LinetypeTableId,
  350.                 openmode,
  351.                 false);
  352.             return m_LinetypeTable;
  353.         }
  354.         public LinetypeTable OpenLinetypeTable()
  355.         {
  356.             return OpenLinetypeTable(OpenMode.ForWrite);
  357.         }
  358.         public SelectionSet SelectByLineWeight(LineWeight lineWeight)
  359.         {
  360.             List filter = new List();
  361.             filter.Add(new TypedValue(370, lineWeight));
  362.             OpenLayerTable(OpenMode.ForRead);
  363.             List lays = new List();
  364.             foreach (ObjectId id in LayerTable)
  365.             {
  366.                 LayerTableRecord ltr = (LayerTableRecord)GetObject(id, OpenMode.ForRead);
  367.                 if (ltr.LineWeight == lineWeight)
  368.                 {
  369.                     lays.Add(ltr.Name);
  370.                 }
  371.             }
  372.             if (lays.Count > 0)
  373.             {
  374.                 string s = string.Join(",", lays.ToArray());
  375.                 filter.Insert(0, new TypedValue(-4, ""));
  376.                 filter.Add(new TypedValue(-4, "or>"));
  377.             }
  378.             PromptSelectionResult res = CadHelper.Editor.SelectAll(new SelectionFilter(filter.ToArray()));
  379.             return res.Value;
  380.         }
  381.         #endregion
  382.         //用户坐标系
  383.         #region UcsTable
  384.         public UcsTable OpenUcsTable(OpenMode openmode)
  385.         {
  386.             m_UcsTable = (UcsTable)m_Transaction.GetObject(
  387.                 m_Database.UcsTableId,
  388.                 openmode,
  389.                 false);
  390.             return m_UcsTable;
  391.         }
  392.         public UcsTable OpenUcsTable()
  393.         {
  394.             return OpenUcsTable(OpenMode.ForWrite);
  395.         }
  396.         #endregion
  397.         //视图
  398.         #region ViewTable
  399.         public ViewTable OpenViewTable(OpenMode openmode)
  400.         {
  401.             m_ViewTable = (ViewTable)m_Transaction.GetObject(
  402.                 m_Database.ViewTableId,
  403.                 openmode,
  404.                 false);
  405.             return m_ViewTable;
  406.         }
  407.         public ViewTable OpenViewTable()
  408.         {
  409.             return OpenViewTable(OpenMode.ForWrite);
  410.         }
  411.         #endregion
  412.         //视口
  413.         #region ViewportTable
  414.         public ViewportTable OpenViewportTable(OpenMode openmode)
  415.         {
  416.             m_ViewportTable = (ViewportTable)m_Transaction.GetObject(
  417.                 m_Database.ViewportTableId,
  418.                 openmode,
  419.                 false);
  420.             return m_ViewportTable;
  421.         }
  422.         public ViewportTable OpenViewportTable()
  423.         {
  424.             return OpenViewportTable(OpenMode.ForWrite);
  425.         }
  426.         #endregion
  427.         //调整实体显示
  428.         #region DrawOrderTable
  429.         public DrawOrderTable OpenDrawOrderTable(OpenMode openmode)
  430.         {
  431.             m_DrawOrderTable = (DrawOrderTable)m_Transaction.GetObject(
  432.                 m_BlockTableRecord.DrawOrderTableId,
  433.                 openmode,
  434.                 false);
  435.             return m_DrawOrderTable;
  436.         }
  437.         public DrawOrderTable OpenDrawOrderTable()
  438.         {
  439.             return OpenDrawOrderTable(OpenMode.ForWrite);
  440.         }
  441.         #endregion
  442.         //编组字典
  443.         #region GroupDictionary
  444.         public DBDictionary OpenGroupDictionary(OpenMode openmode)
  445.         {
  446.             m_GroupDictionary = (DBDictionary)m_Transaction.GetObject(
  447.                 m_Database.GroupDictionaryId,
  448.                 openmode,
  449.                 false);
  450.             return m_GroupDictionary;
  451.         }
  452.         public DBDictionary OpenGroupDictionary()
  453.         {
  454.             return OpenGroupDictionary(OpenMode.ForWrite);
  455.         }
  456.         public ObjectId AddGroup(string name, ObjectIdCollection ids)
  457.         {
  458.             if (m_GroupDictionary.Contains(name))
  459.             {
  460.                 return ObjectId.Null;
  461.             }
  462.             else
  463.             {
  464.                 m_GroupDictionary.UpgradeOpen();
  465.                 Group g = new Group();
  466.                 g.Append(ids);
  467.                 m_GroupDictionary.SetAt(name, g);
  468.                 m_Transaction.AddNewlyCreatedDBObject(g, true);
  469.                 return g.ObjectId;
  470.             }
  471.         }
  472.         public List GetGroups(Entity ent)
  473.         {
  474.             List gs = new List();
  475.             foreach (DBDictionaryEntry obj in m_GroupDictionary)
  476.             {
  477.                 Group g =
  478.                     (Group)m_Transaction.GetObject(
  479.                     obj.Value,
  480.                     OpenMode.ForRead,
  481.                     false);
  482.                 if (g.Has(ent))
  483.                     gs.Add(g);
  484.             }
  485.             return gs;
  486.         }
  487.         #endregion
  488.         //在当前块表记录中加入实体
  489.         #region Add Entity
  490.         public ObjectId AddEntity(Entity entity)
  491.         {
  492.             ObjectId id = m_BlockTableRecord.AppendEntity(entity);
  493.             m_Transaction.AddNewlyCreatedDBObject(entity, true);
  494.             return id;
  495.         }
  496.         public ObjectId[] AddEntity(DBObjectCollection objs)
  497.         {
  498.             ObjectId[] ids = new ObjectId[objs.Count];
  499.             for (int i = 0; i  objs)
  500.         {
  501.             ObjectId[] ids = new ObjectId[objs.Count];
  502.             for (int i = 0; i  objs)
  503.         {
  504.             ObjectId[] ids = new ObjectId[objs.Count];
  505.             for (int i = 0; i  AppendAttribToBlock(ObjectId blkrefid, List atts)
  506.         {
  507.             BlockReference blkref = (BlockReference)m_Transaction.GetObject(blkrefid, OpenMode.ForWrite);
  508.             return AppendAttribToBlock(blkref, atts);
  509.         }
  510.         public Dictionary AppendAttribToBlock(BlockReference blkref, List atts)
  511.         {
  512.             BlockTableRecord blkdef = (BlockTableRecord)m_Transaction.GetObject(blkref.BlockTableRecord, OpenMode.ForRead);
  513.             int i = 0;
  514.             if (blkdef.HasAttributeDefinitions)
  515.             {
  516.                 Dictionary attribs = new Dictionary();
  517.                 foreach (ObjectId id in blkdef)
  518.                 {
  519.                     DBObject ent = GetObject(id, OpenMode.ForRead);
  520.                     if (ent is AttributeDefinition)
  521.                     {
  522.                         AttributeDefinition attdef = (AttributeDefinition)ent;
  523.                         AttributeReference attref = new AttributeReference();
  524.                         attref.SetAttributeFromBlock(attdef, blkref.BlockTransform);
  525.                         if (i  AppendAttribToBlock(ObjectId blkrefid, List atts)
  526.         {
  527.             BlockReference blkref = (BlockReference)m_Transaction.GetObject(blkrefid, OpenMode.ForWrite);
  528.             return AppendAttribToBlock(blkref, atts);
  529.         }
  530.         public Dictionary AppendAttribToBlock(BlockReference blkref, List atts)
  531.         {
  532.             Dictionary attribs = new Dictionary();
  533.             for (int i = 0; i  atts)
  534.         {
  535.             BlockReference blkref = new BlockReference(Point3d.Origin, blkdefid);
  536.             ObjectId id = AddEntity(blkref);
  537.             BlockRefJig jig = new BlockRefJig(blkref, AppendAttribToBlock(blkref, atts));
  538.             jig.SetPromptCounter(0);
  539.             PromptResult res = CadHelper.Editor.Drag(jig);
  540.             if (res.Status == PromptStatus.OK)
  541.             {
  542.                 jig.SetPromptCounter(1);
  543.                 res = CadHelper.Editor.Drag(jig);
  544.                 if (res.Status == PromptStatus.OK)
  545.                 {
  546.                     return id;
  547.                 }
  548.             }
  549.             blkref.Erase();
  550.             return ObjectId.Null;
  551.         }        public ObjectId InsertBlock(string name, List attribs)
  552.         {
  553.             return InsertBlock(m_BlockTable[name], attribs);
  554.         }
  555.         public bool GetBlockDefFromFile(string filename, string blkdefname, bool over)
  556.         {
  557.             try
  558.             {
  559.                 bool has = m_BlockTable.Has(blkdefname);
  560.                 if ((has && over) || !has)
  561.                 {
  562.                     using (DBTransaction t = new DBTransaction(filename))
  563.                     {
  564.                         ObjectId id = t.BlockTable[blkdefname];
  565.                         BlockTableRecord btr =
  566.                             (BlockTableRecord)t.GetObject(id, OpenMode.ForRead);
  567.                         if (!btr.IsAnonymous && !btr.IsLayout)
  568.                         {
  569.                             ObjectIdCollection ids = new ObjectIdCollection();
  570.                             ids.Add(t.BlockTable[blkdefname]);
  571.                             t.Database.Wblock(
  572.                                 m_Database,
  573.                                 ids,
  574.                                 new Point3d(),
  575.                                 DuplicateRecordCloning.Replace
  576.                                 );
  577.                         }
  578.                     }
  579.                 }
  580.                 return true;
  581.             }
  582.             catch
  583.             { }
  584.             return false;
  585.         }
  586.         public bool GetBlockDefFromFile(string filename, bool over)
  587.         {
  588.             try
  589.             {
  590.                 FileInfo fi = new FileInfo(filename);
  591.                 string blkdefname = fi.Name;
  592.                 if (blkdefname.Contains("."))
  593.                 {
  594.                     blkdefname = blkdefname.Substring(0, blkdefname.LastIndexOf('.'));
  595.                 }
  596.                 bool has = m_BlockTable.Has(blkdefname);
  597.                 if ((has && over) || !has)
  598.                 {
  599.                     Database db = new Database();
  600.                     db.ReadDwgFile(filename, FileShare.Read, true, null);
  601.                     m_Database.Insert(BlockTableRecord.ModelSpace, blkdefname, db, false);
  602.                 }
  603.                 return true;
  604.             }
  605.             catch
  606.             { }
  607.             return false;
  608.         }
  609.         #endregion
  610.         //字典
  611.         #region XRecord
  612.         public DBDictionary GetSubDict(DBDictionary dict, bool createsubdict, params string[] dictnames)
  613.         {
  614.             if (createsubdict)
  615.             {
  616.                 dict.UpgradeOpen();
  617.                 dict.TreatElementsAsHard = true;
  618.             }
  619.             for (int i = 0; i  m_Attribs;
  620.         public BlockRefJig(BlockReference blkref, Dictionary attribs)
  621.             : base(blkref)
  622.         {
  623.             m_Position = new Point3d();
  624.             m_Angle = 0;
  625.             m_Ucs = CadHelper.Editor.CurrentUserCoordinateSystem;
  626.             m_Attribs = attribs;
  627.             Update();
  628.         }
  629.         protected override SamplerStatus Sampler(JigPrompts prompts)
  630.         {
  631.             switch (m_PromptCounter)
  632.             {
  633.                 case 0:
  634.                     {
  635.                         JigPromptPointOptions jigOpts = new JigPromptPointOptions("\n请输入基点:");
  636.                         jigOpts.UserInputControls =
  637.                             UserInputControls.Accept3dCoordinates |
  638.                             UserInputControls.NoZeroResponseAccepted |
  639.                             UserInputControls.NoNegativeResponseAccepted;
  640.                         PromptPointResult res = prompts.AcquirePoint(jigOpts);
  641.                         Point3d pnt = res.Value;
  642.                         if (pnt != m_Position)
  643.                         {
  644.                             m_Position = pnt;
  645.                             m_BasePoint = m_Position;
  646.                         }
  647.                         else
  648.                             return SamplerStatus.NoChange;
  649.                         if (res.Status == PromptStatus.Cancel)
  650.                             return SamplerStatus.Cancel;
  651.                         else
  652.                             return SamplerStatus.OK;
  653.                     }
  654.                 case 1:
  655.                     {
  656.                         JigPromptAngleOptions jigOpts = new JigPromptAngleOptions("\n请输入旋转角度:");
  657.                         jigOpts.UserInputControls =
  658.                             UserInputControls.Accept3dCoordinates |
  659.                             UserInputControls.NoNegativeResponseAccepted |
  660.                             UserInputControls.GovernedByUCSDetect |
  661.                             UserInputControls.UseBasePointElevation;
  662.                         jigOpts.Cursor = CursorType.RubberBand;
  663.                         jigOpts.UseBasePoint = true;
  664.                         jigOpts.BasePoint = m_BasePoint;
  665.                         PromptDoubleResult res = prompts.AcquireAngle(jigOpts);
  666.                         double angleTemp = res.Value;
  667.                         if (angleTemp != m_Angle)
  668.                             m_Angle = angleTemp;
  669.                         else
  670.                             return SamplerStatus.NoChange;
  671.                         if (res.Status == PromptStatus.Cancel)
  672.                             return SamplerStatus.Cancel;
  673.                         else
  674.                             return SamplerStatus.OK;
  675.                     }
  676.                 default:
  677.                     return SamplerStatus.NoChange;
  678.             }
  679.         }
  680.         protected override bool Update()
  681.         {
  682.             try
  683.             {
  684.                 /*Ucs下Jig的流程:
  685.                  * 1.先将图元在Wcs下摆正,即//xy平面
  686.                  * 2.将获取点坐标转换到Ucs下
  687.                  * 3.将图元在Ucs下摆正
  688.                  * 4.矩阵变换到Wcs
  689.                  */
  690.                 BlockReference blkref = (BlockReference)Entity;
  691.                 blkref.Normal = Vector3d.ZAxis;
  692.                 blkref.Position = CadHelper.Wcs2Ucs(m_Position);
  693.                 blkref.Rotation = m_Angle;
  694.                 blkref.TransformBy(m_Ucs);
  695.                 //将属性引用按块引用的Ocs矩阵变换
  696.                 if (m_Attribs != null)
  697.                 {
  698.                     m_Mat = blkref.BlockTransform;
  699.                     foreach (KeyValuePair att in m_Attribs)
  700.                     {
  701.                         AttributeReference attref = att.Value;
  702.                         string s = attref.TextString;
  703.                         attref.SetAttributeFromBlock(att.Key, m_Mat);
  704.                         attref.TextString = s;
  705.                     }
  706.                 }
  707.                
  708.             }
  709.             catch
  710.             {
  711.                 return false;
  712.             }
  713.             return true;
  714.         }
  715.         public void SetPromptCounter(int i)
  716.         {
  717.             if (i == 0 || i == 1)
  718.             {
  719.                 m_PromptCounter = i;
  720.             }
  721.         }
  722.     }
  723. }
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-6-4 12:46:00 | 显示全部楼层
CadHelper 这个类是哪个?我怎么找不到?我用的是CAD2006
回复

使用道具 举报

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
1
发表于 2009-6-11 11:15:00 | 显示全部楼层
自定义类,可以直接下这里的类库
TlsBasal 会逐渐开源:)
不支持2006,2005/6的.NetApi是有很多Bug的,做.Net开发应使用2007以上版本
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-6-11 11:31:00 | 显示全部楼层
function XML() {
    [native code]
}
回复

使用道具 举报

0

主题

9

帖子

2

银币

初来乍到

Rank: 1

铜币
9
发表于 2009-11-2 09:14:00 | 显示全部楼层
好东东。
回复

使用道具 举报

7

主题

55

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
83
发表于 2009-12-28 23:35:00 | 显示全部楼层
飞狐兄太好了。这程序我又要研究几个月了
回复

使用道具 举报

7

主题

55

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
83
发表于 2009-12-28 23:50:00 | 显示全部楼层
飞狐兄。我学C#不久。脑子还是编程。还是以面向过程。我总是把所有功能写成方法。全做成静态的。看了你的代码。我就不知怎么办。做成非静态的有什么好处。方便在那里。BlockRefJig.cs 这个文件。应该怎么用这个JIG。能给出一个代码来不?先谢谢了。
回复

使用道具 举报

7

主题

55

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
83
发表于 2009-12-29 00:09:00 | 显示全部楼层
BlockRefJig是为DBTransaction的InsertBlock函数服务的:),一楼有调用的代码
DBTransaction本身是为简化托管代码而实现,
经常看到就算一个实体加入数据库也要用单个的事务,效率很低,哈哈
所以就有写该类的想法
至于静态,非静态,我的理解:类是数据及相关操作的集合
回复

使用道具 举报

72

主题

2726

帖子

9

银币

社区元老

Rank: 75Rank: 75Rank: 75

铜币
3014
发表于 2009-12-29 08:44:00 | 显示全部楼层
就是加一条直线。也要打开数据库。 另外我试 了。加1000条直线。用一次trans跟用1000次。差别感觉不出来。难道我的机子牛B。
飞狐兄的最后一句我上班要好好理解一下
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-14 21:16 , Processed in 0.380821 second(s), 70 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表