• 块插入图中时,块随鼠标移动 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;
            }
  • 相关阅读:
    大富翁8分析
    DCOM实现分布式应用(三)
    DCOM实现分布式应用(一)
    [转]职业生涯中的10个致命错误
    VC中展开宏
    zoj 2853 Evolution
    poj 1088 滑雪
    hdu 2437 Jerboas
    poj 3070 Fibonacci
    zoj 2976 Light Bulbs
  • 原文地址:https://www.cnblogs.com/houlinbo/p/1625962.html
Copyright © 2020-2023  润新知