zoukankan      html  css  js  c++  java
  • 块插入图中时,块随鼠标移动 EntityJig

    代码
    //继承EntityJig  两个函数重载   
     public class CADJig : EntityJig
        {
          //  houlinbo QQ420021327
           Entity moveEnt; 
    //移动的实体
            Point3d ptTo;   //插入点
            string promp;   //提示
            public CADJig(Entity ent, string strPromp)
                : 
    base(ent)
            {
                moveEnt 
    = ent; //打开的 ent
                promp = strPromp;
            }


            
    protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                JigPromptPointOptions optJigPoint 
    = new JigPromptPointOptions(promp);
                
    //optJigPoint.Cursor = CursorType.RubberBand;
                PromptPointResult resJigPoint = prompts.AcquirePoint(optJigPoint);
                Point3d curPt 
    = resJigPoint.Value;

                
    if (ptTo != curPt)
                {
                    ptTo 
    = curPt;
                    
    return SamplerStatus.OK;
                }
                
    else
                {
                    
    return SamplerStatus.NoChange;
                }
            }


            
    protected override bool Update()
            {
                
    try
                {
                    ((BlockReference)moveEnt).Position 
    = ptTo;
                }
                
    catch (System.Exception)
                {
                    
    return false;
                }
                
    return true;
            }
         }
    代码
            /// <summary>
            
    /// 将文件以块的形式添加到图中  随鼠标移动 JIG
            
    /// </summary>
            
    /// <returns></returns>
            public static ObjectId AddBlockDwgJig(Database db, Editor ed, String sourceFileName, String newBlockName, Point3d po, double dAngle, string jigPrompt)
            {
               //  houlinbo  QQ420021327
                BlockReference bref 
    = null;
                Transaction trans 
    = db.TransactionManager.StartTransaction();
                
    using (trans)
                {
                    
    try
                    {
                        BlockTable bt 
    = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForWrite);
                        BlockTableRecord btr 
    = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

                        ObjectId bobj 
    = new ObjectId();
                        
    if (bt.Has(newBlockName))
                        {
                            bobj 
    = bt[newBlockName];
                        }
                        
    else
                        {
                            Database databaseFromFile 
    = Getdb(sourceFileName, System.IO.FileShare.Read, true);
                            bobj 
    = db.Insert(newBlockName, databaseFromFile, true);
                        }
                        bref 
    = new BlockReference(po, bobj);
                        bref.Rotation 
    = dAngle;
                        ObjectId blockobj 
    = btr.AppendEntity(bref);
                        BlockTableRecord empBtr 
    = (BlockTableRecord)trans.GetObject(bt[newBlockName], OpenMode.ForWrite);

                        
    //用以下两句调用随鼠标移动的效果 在事务未知前调用,否则原点会出现一个块
                        CADJig cadJig = new CADJig(bref as Entity, jigPrompt);
                        PromptResult pr 
    = ed.Drag(cadJig);


                        
    foreach (ObjectId id in empBtr)
                        {
                            Entity ent 
    = (Entity)trans.GetObject(id, OpenMode.ForRead, true);
                            
    if (ent.GetType() == typeof(AttributeDefinition))
                            {
                                
    //块属性
                                AttributeReference attRef = new AttributeReference();
                                AttributeDefinition attDef 
    = (AttributeDefinition)ent;
                                attRef.SetPropertiesFrom(attDef);
                                attRef.SetAttributeFromBlock(attDef, bref.BlockTransform);
                                bref.AttributeCollection.AppendAttribute(attRef);
                                trans.AddNewlyCreatedDBObject(attRef, 
    true);
                            }
                        }
                        trans.AddNewlyCreatedDBObject(bref, 
    true);
                        trans.Commit();
                    }
                    
    catch (Exception ex)
                    {
                        CE.Elec.Common.ShowMgr.SException(
    "出错Insert ARX " + ex.Message);
                    }
                    
    finally
                    {
                        trans.Dispose();
                    }
                }
                
    return bref.ObjectId;
            }
  • 相关阅读:
    Testdisk 操作指南(硬盘分区表恢复)
    ThinkPHP下使用Uploadify插件提示HTTP Error (302)错误的解决办法
    C#获取计算机CPU的温度
    C# 获取显示器的物理尺寸或分辨率
    获取windows 操作系统下的硬件或操作系统信息等
    AD CS relay attack
    内网密码收集[Foxmail]解密
    如果你是业务线的程序员
    浅析php curl_multi_*系列函数进行批量http请求
    memcached讲解
  • 原文地址:https://www.cnblogs.com/houlinbo/p/1625962.html
Copyright © 2011-2022 走看看