- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 csharp 于 2014-5-1 23:01 编辑
- using System;
- using System.Globalization;
- using System.Runtime.InteropServices;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Interop.Common;
- using AcadApp = Autodesk.AutoCAD.Interop.AcadApplication;
- using Autodesk.AutoCAD.Interop;
- namespace PartGroupsMonitor
- {
- class CopyGroupFromExisting
- {
- public void CreateGroup()
- {
- Document document = Application.DocumentManager.MdiActiveDocument;
- Editor editor = document.Editor;
- Database database = Application.DocumentManager.MdiActiveDocument.Database;
- Matrix3d MoveMat = new Matrix3d();
- string NewNam = "";
-
- using (document.LockDocument())
- {
- PromptEntityOptions options = new PromptEntityOptions("\nSelect part of Group: < pick > ");
- options.SetRejectMessage("\nMust be Group related. ");
- options.AddAllowedClass(typeof(Arc), false);
- options.AddAllowedClass(typeof(Line), false);
- options.AddAllowedClass(typeof(Circle), false);
- options.AddAllowedClass(typeof(Polyline), false);
- PaletteUtils.ActivateEditor();
- PromptEntityResult selection = editor.GetEntity(options);
- if (selection.Status == PromptStatus.OK)
- {
- Object MvePnt = GroupDisplacementPoint();
- if (MvePnt is Point3d)
- {
- Point3d p1 = (Point3d)MvePnt;
- using (Transaction trans = database.TransactionManager.StartTransaction())
- {
- Entity obj = (Entity)trans.GetObject(selection.ObjectId, OpenMode.ForRead);
- if (obj != null)
- {
- Point3d basePt = obj.GeomExtents.MaxPoint;
- MoveMat = Matrix3d.Displacement(p1.GetVectorTo(basePt));
- ResultBuffer rbf = SafeNativeMethods.EntGet(obj.ObjectId);
- TypedValue[] XdataOut = rbf.AsArray();
- if (XdataOut[3].Value.ToString() == "{ACAD_REACTORS")
- {
-
- ObjectId reactorId = (ObjectId)XdataOut[4].Value;
- DBDictionary GrpDic = (DBDictionary)trans.GetObject(database.GroupDictionaryId, OpenMode.ForWrite);
- Group grp = (Group)trans.GetObject(reactorId, OpenMode.ForWrite);
-
- string str = grp.Name;
- NewNam = string.Concat(str.Substring(0, str.IndexOf("-", 0, str.Length) + 3), DateTime.Now.Millisecond.ToString());
- Group NewGroup = new Group(NewNam, true);
- NewGroup.Description = DateTime.Now.ToShortDateString();
-
- ObjectIdCollection IDCol = new ObjectIdCollection(grp.GetAllEntityIds());
- IdMapping IDMap = new IdMapping();
- IDMap = database.DeepCloneObjects(IDCol, database.CurrentSpaceId, false);
-
- foreach (IdPair pair in IDMap)
- {
- if (pair.IsPrimary)
- {
- Entity en = (Entity)trans.GetObject(pair.Value, OpenMode.ForRead);
-
- en.UpgradeOpen();
- en.TransformBy(MoveMat);
- NewGroup.Append(en.ObjectId);
- en.RecordGraphicsModified(true);
- trans.TransactionManager.QueueForGraphicsFlush();
- en.DowngradeOpen();
-
- }
- }
- GrpDic.SetAt(NewNam, NewGroup);
- trans.AddNewlyCreatedDBObject(NewGroup, false);
- NewGroup.DowngradeOpen();
- AcadDocument ADoc = (AcadDocument)document.AcadDocument;
- AcadObject AO = ADoc.Dictionaries.Item("ACAD_GROUP");
- IAcadGroups iags = (IAcadGroups)AO;
- iags.Add(NewNam);
- trans.Commit();
- editor.WriteMessage("\nGroup < " + str + " > selected. ");
- }
- }
- else
- {
- editor.WriteMessage("\nMust be Group related. ");
- }
- }
- }
- else
- {
- editor.WriteMessage("\n *Cancelled* ");
- }
- }
- else
- {
- editor.WriteMessage("\nNothing Picked: *" + selection.Status.ToString() + "*");
- }
- }
- editor.WriteMessage("\n\nCommand:\n");
- database.Dispose();
- }
-
- public Object GroupDisplacementPoint()
- {
- Document document = Application.DocumentManager.MdiActiveDocument;
- Editor editor = document.Editor;
- PromptPointOptions options2 = new PromptPointOptions("\nPick location point: ");
- options2.AllowNone = false;
- PromptPointResult point = editor.GetPoint(options2);
-
- return point.Value;
-
- }
- }
- }
|
|