DOTNETARX執行個體教學

來源:互聯網
上載者:User
 

本文將向你介紹一些DOTNETARX的例子。要運行文中的例子,你必須建立一個新的工程並加入DOTNETARX2.0組件,然後在代碼檔案中加入"using DOTNETARX;"。關於DOTNETARX的詳細說明,請大家參考DOTNETARX參考文檔。
  • 多重選取集
在ObjectARX託管封裝類中有一個bug,你不能使用多重選取集。例如,你不能使用選擇集來同時選擇圓和直線。但有了DOTNETARX2.0,你就可以使用多重選取集了。下面的例子在選擇集中加入半徑為1.0的圓和在層ABC上的直線。     void test()     {        TypedValue[] values=new TypedValue[]{                        new TypedValue(-4,"<or"),                            new TypedValue(-4,"<and"),                            new TypedValue(0,"CIRCLE"),                            new TypedValue((int)DxfCode.Real,1.0),                            new TypedValue(-4,"and>"),                            new TypedValue(-4,"<and"),                            new TypedValue(0,"Line"),                            new TypedValue((int)DxfCode.LayerName,"ABC"),                            new TypedValue(-4,"and>"),                            new TypedValue(-4,"or>")        };        int n=Tools.GetSelection(values).Count;//在選擇集中加入對象         Tools.Editor.WriteMessage(n.ToString());    }
  •  加入多個實體
在DOTNETARX1.0(也就是原來的zhfarx),如果你多次使用Tools.AddEntity來加入多個實體,那麼效率將非常的低。所以在2.0中,我加入了AddEntities()函數來解決這個問題。下面的例子使用AddEntities()在AutoCAD圖形中加入直線和圓。    void AddLineCircle()    {        Point3d pt1=new Point3d(0,0,0);        Point3d pt2=new Point3d(50,50,0);        Lines line=new Lines(pt1,pt2);        Point3d center=new Point3d(50,0,0);        Circles circle=new Circles(center,50);        Tools.AddEntities(new Entity[]{line,center});    }
  •  組
下面的例子在AutoCAD中加入一個組。     void MakeGroup()    {        PromptSelectionResult res=Tools.Editor.GetSelection();//選擇對象         SelectionSet ss=res.Value; //擷取選擇集         ObjectId[] ids=ss.GetObjectIds(); //擷取表示所選對象的objectId數組        Group gp=new Group("grouptest",true);//建立名為grouptest的組對象        gp.Append(new ObjectIdCollection(ids));// 加入上面的所選對象到組中        Tools.AddDictionaryObject("ASDK_GROUPTEST",gp,Tools.Database.GroupDictionaryId);        //使用AddDictionaryObject()函數把組加入到AutoCAD中。   }
  • 擴充記錄
下面的例子在AutoCAD中加入一個擴充記錄。                void MakeXRecord()    {        Xrecord rec=new Xrecord();//建立一個擴充記錄對象        rec.Data=new ResultBuffer(                new TypedValue((int)DxfCode.Text,"This is a test"),                new TypedValue((int)DxfCode.Int8,0),                new TypedValue((int)DxfCode.UcsOrg,new Point3d(0,0,0))        );//使用Xreord的Data屬性來設定Xreord的內容        Tools.AddDictionaryObject("test",rec,Tools.Database.NamedObjectsDictionaryId);        //使用AddDictionaryObject()函數把擴充記錄加入到AutoCAD中。        foreach (TypedValue rb in rec.Data) //輸出剛才加入的條目        {         Tools.Editor.WriteMessage(string.Format("TypedCode={0},Value={1}/n",rb.TypeCode,rb.Value));        }    }
  •  擴充資料
下面的例子在AutoCAD中加入擴充資料。    void MakeXData()    {        Lines line=new Lines(new Point3d(0,0,0),new Point3d(100,100,0));        //建立直線        RegAppTableRecord app=new RegAppTableRecord();        //加入擴充資料到直線,首先註冊程式        app.Name="MyApp";        Tools.AddSymbolTableRecord(app,Tools.Database.RegAppTableId);        //使用AddSymbolTableRecord 函數把app加入到RegAppTable。         line.XData=new ResultBuffer(new TypedValue((int)DxfCode.ExtendedDataRegAppName,"MyApp"),        new TypedValue((int)DxfCode.ExtendedDataAsciiString,"This is some xdata string"));        //設定直線的XData屬性        Tools.AddEntity(line);//加入直線到資料庫中        foreach (TypedValue rb in line.XData)// 輸出剛才加入的條目        {            Tools.Editor.WriteMessage(string.Format("TypedCode={0},Value={1}/n",rb.TypeCode,rb.Value));        }     }
  • 複製和移動
下面的例子先使用Copy()擷取所選實體的拷貝,然後使用Move()來移動這個拷貝。    void test()     {        PromptEntityResult res = Tools.Editor.GetEntity("please select an entity to copy:/n");        ObjectId id= Tools.Copy(res.ObjectId);        Tools.Move(id,res.PickedPoint,res.PickedPoint.Add(new Vector3d(20,20,0)));    }
  • 鏡像拷貝
下面的例子鏡像拷貝所選的實體。    void test()     {        Editor ed=Tools.Editor;        PromptEntityResult res =ed.GetEntity("please select an entity:/n");        Point3d pt1=ed.GetPoint("Select the first point of the mirror axis:/n").Value;        Point3d pt2=ed.GetPoint("Select the second point of the mirror axis:/n").Value;        Tools.Mirror(res.ObjectId,pt1,pt2,false);    }
  • 位移
下面的例子位移所選的實體。    void test()     {        Editor ed=Tools.Editor;        PromptEntityResult res =ed.GetEntity("please select an entity:/n");        Tools.Offset(res.ObjectId,20);    }
  • 旋轉
下面的例子旋轉所選的實體45度角。    void test()     {        Editor ed=Tools.Editor;        PromptEntityResult res =ed.GetEntity("please select an entity:/n");        Point3d pt1=ed.GetPoint("Select the base point of rotation:/n").Value;        Tools.Rotate(res.ObjectId,pt1,45);//注意:是角度而不是弧度    }
  • 縮放
下面的例子放大所選的實體2倍。    void test()     {        Editor ed=Tools.Editor;        PromptEntityResult res =ed.GetEntity("please select an entity:/n");        Point3d pt1=ed.GetPoint("Select the base point of scaling:/n").Value;        Tools.Scale(res.ObjectId,pt1,2);    }
  • 加入符號表記錄
下面的例子加入一個名為Test的層    void CreateLayer()     {        LayerTableRecord ltr=new LayerTableRecord();        ltr.Name="Test";        Tools.AddSymbolTableRecord(ltr,Tools.Database.LayerTableId);    }
  • 擷取符號表遍曆器
下面的例子使用GetIteratorForSymbolTable()來遍曆層表,並輸出層的名字。    void test()     {        DBObjectCollection objs= Tools.GetIteratorForSymbolTable(Tools.Database.LayerTableId);        foreach (DBObject obj in objs)        {            LayerTableRecord ltr=(LayerTableRecord)obj;            Tools.Editor.WriteMessage(ltr.Name+"/n");        }    }
  • 選擇過一個點的所有實體
    void test()    {        PromptPointResult res=Tools.Editor.GetPoint("Please select a point:/n");        Point3d pt=res.Value;        int n=Tools.SelectAtPoint(pt).Count;        Tools.Editor.WriteMessage(n.ToString());    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.