马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Creating block from selection setBy Virupaksha Aithal
Below code shows the procedure to create a new block table record from entities selected on screen. The important function used is “DeepCloneObjects” which takes collections of object ids to be copy. The second parameter is the “owner” of the copied entities. In the below code, the block table record (“test”) is passed as owner, so that the selected entities clone objects are copied to block table record
- [CommandMethod("CreateBlock")]
- public void CreateBlock()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- TypedValue[] filterlist = new TypedValue[1];
- filterlist[0] = new TypedValue(0, "CIRCLE,LINE");
- SelectionFilter filter = new SelectionFilter(filterlist);
- PromptSelectionOptions opts = new PromptSelectionOptions();
- opts.MessageForAdding = "Select entities: ";
- PromptSelectionResult selRes = ed.GetSelection(opts, filter);
- if (selRes.Status != PromptStatus.OK)
- {
- return;
- }
- ObjectId[] ids = selRes.Value.GetObjectIds();
- ObjectId blockId = ObjectId.Null;
- //add a block table record with name test...
- using (Transaction Tx = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)Tx.GetObject(db.BlockTableId,
- OpenMode.ForRead);
- if (!bt.Has("Test"))
- {
- bt.UpgradeOpen();
- //create new
- BlockTableRecord record = new BlockTableRecord();
- record.Name = "Test";
- bt.Add(record);
- Tx.AddNewlyCreatedDBObject(record, true);
- }
- blockId = bt["Test"];
- Tx.Commit();
- }
- //copy the select entities to block by using deepclone.
- ObjectIdCollection collection = new ObjectIdCollection(ids);
- IdMapping mapping = new IdMapping();
- db.DeepCloneObjects(collection, blockId, mapping, false);
- }
|