Author Topic: Anyone care to take a look?  (Read 2919 times)

0 Members and 1 Guest are viewing this topic.

BillZndl

  • Guest
Anyone care to take a look?
« on: February 10, 2010, 12:23:53 PM »
This appears to be the source of my crash problems.
It copies a selected "Group" in AutoCAD.
It works, then seemingly, boom, AutoCAD either locks up or has to close.
The only error message I get when there is one says "Error Reading" blah blah.
I call it with a button click from a modeless form.

Is there anything that looks to be taboo with this class?
Thanks in advance.

Code: [Select]
using System;
using System.Collections;
using System.Windows.Forms;
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;
using Autodesk.AutoCAD.Interop.Common;
using Autodesk.AutoCAD.Internal;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace PartGroupsMonitor
{
    class CopyGroupFromExisting
    {
        public void CreateGroup()
        {
            Document document = AcadApp.DocumentManager.MdiActiveDocument;
            Editor editor = document.Editor;
            Database database = HostApplicationServices.WorkingDatabase;          
            
            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)
                {
                    ObjectId GrpId = GroupId(selection.ObjectId);                

                    if (!GrpId.IsNull)  //has reactors.
                    {                        
                        using (Transaction trans = database.TransactionManager.StartTransaction())
                        {

                        Group grp = trans.GetObject(GrpId, OpenMode.ForWrite, false) as Group;  //is group.

                        if (grp != null)
                        {
                            DBDictionary GrpDic = (DBDictionary)trans.GetObject(database.GroupDictionaryId, OpenMode.ForWrite);

                            ObjectId[] EntIds = grp.GetAllEntityIds();

                            ObjectIdCollection IDCol = new ObjectIdCollection(EntIds);

                            HighlightSelection(IDCol);

                            PromptPointResult PntFrom = GroupBasePoint(); //basepoint for move.

                            if (PntFrom.Status == PromptStatus.OK)
                            {
                                UnHighlightSelection(IDCol);

                                Point3d basePt = (Point3d)PntFrom.Value;
                                EntityDragger dragger = new EntityDragger();

                                PromptResult dragResult = dragger.StartDrag(basePt, EntIds);

                                if (dragResult.Status == PromptStatus.OK)
                                {
                                    grp.Remove(IDCol);

                                    IdMapping IDMap = new IdMapping();
                                    IDMap = database.DeepCloneObjects(IDCol, database.CurrentSpaceId, false);

                                    grp.Append(IDCol);

                                    MoveDeepClonedCopies(dragger.DisplacementMatrix, IDMap);

                                    string str = grp.Name;
                                    string desc = grp.Description;
                                    string NewNam = AddGroupDate.GetNewName(str, "COPY");

                                    Group NewGroup = new Group(NewNam, true);

                                    GrpDic.SetAt(NewNam, NewGroup);
                                    trans.AddNewlyCreatedDBObject(NewGroup, true);
                                    NewGroup.Description = desc;

                                    foreach (IdPair pair in IDMap)
                                    {
                                        if (pair.IsPrimary)
                                        {
                                            Entity en = (Entity)trans.GetObject(pair.Value, OpenMode.ForRead);
                                            NewGroup.Append(en.ObjectId);
                                        }
                                    }

                                    AcadDocument ADoc = (AcadDocument)document.AcadDocument;
                                    AcadObject AO = ADoc.Dictionaries.Item("ACAD_GROUP");
                                    IAcadGroups iags = (IAcadGroups)AO;                                  

                                    iags.Add(NewNam);

                                    if (Module.GrpInfoTbl.Contains(NewGroup.ObjectId))
                                    {
                                        Module.GrpInfoTbl.Remove(NewGroup.ObjectId);
                                    }

                                    editor.WriteMessage("\nGroup < " + str + " > Copied.");
                                    Utils.PostCommandPrompt();
                                }

                                if (dragResult.Status == PromptStatus.Cancel)
                                {
                                    UnHighlightSelection(IDCol);

                                    editor.WriteMessage("\n*Cancel*\n");
                                    Utils.PostCommandPrompt();
                                }
                            }                            
                            
                            if (PntFrom.Status == PromptStatus.Cancel)
                            {                            
                                editor.WriteMessage("\n*Cancel*\n");
                                Utils.PostCommandPrompt();
                            }                          
                                            
                        }                        

                        if (grp == null)
                        {
                            editor.WriteMessage("\nNot a Group.\n");
                            Utils.PostCommandPrompt();
                        }
                        trans.Commit();
                    }

                    if (GrpId.IsNull)
                    {
                        editor.WriteMessage("\nInvalid entity.\n");
                        Utils.PostCommandPrompt();
                    }                      
                }
            } //using trans.
            else
            {
                editor.WriteMessage("\n*Cancel*\n");
                Utils.PostCommandPrompt();
            }                

        } //using document lock            
            
    }

        public ObjectId GroupId(ObjectId EntityId)
        {
            ResultBuffer rbf = SafeNativeMethods.EntGet(EntityId);
            TypedValue[] XdataOut = rbf.AsArray();
            ObjectId reactorId = ObjectId.Null;

            if (XdataOut[3].Value.ToString() == "{ACAD_REACTORS") //part of as group.
            {
                reactorId = (ObjectId)XdataOut[4].Value;                
            }
            return reactorId;                
        }

        private void UnHighlightSelection(ObjectIdCollection Oid)
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Database db = HostApplicationServices.WorkingDatabase;
            
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId entid in Oid)
                {
                    Entity ent = (Entity)trans.GetObject(entid, OpenMode.ForRead);
                    ObjectId[] ids = new ObjectId[1];
                    ids[0] = entid;
                    SubentityId index = new SubentityId(SubentityType.Edge, 0);
                    FullSubentityPath path = new FullSubentityPath(ids, index);
                    ent.Unhighlight(path, true);                        
                }
                
                trans.Commit();
            }                        
        }

        private void HighlightSelection(ObjectIdCollection Oid)
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Database db = HostApplicationServices.WorkingDatabase;
            
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    foreach (ObjectId entid in Oid)
                    {
                    Entity ent = (Entity)trans.GetObject(entid, OpenMode.ForRead);
                    ObjectId[] ids = new ObjectId[1];
                    ids[0] = entid;
                    SubentityId index = new SubentityId(SubentityType.Edge, 0);
                    FullSubentityPath path = new FullSubentityPath(ids, index);
                    ent.Highlight(path, true);                        
                    }
                    
                    trans.Commit();
                }                  
        }
        
        public PromptPointResult GroupBasePoint()
        {
            Document document = AcadApp.DocumentManager.MdiActiveDocument;
            Editor editor = document.Editor;
            PromptPointOptions options = new PromptPointOptions("\nPick base point: ");            
            options.AllowNone = false;            
            PromptPointResult pointRes = editor.GetPoint(options);            

            return pointRes;            

        }        

        private void MoveDeepClonedCopies(Matrix3d transformationMatrix, IdMapping idMap)
        
        {
            Document document = AcadApp.DocumentManager.MdiActiveDocument;
            Editor currentEditor = document.Editor;            

            using (Transaction trans = currentEditor.Document.TransactionManager.StartTransaction())
                {

                    foreach (IdPair pair in idMap)
                    {
                        if (pair.IsPrimary)
                        {
                            Entity clonedEntity = trans.GetObject(pair.Value, OpenMode.ForWrite) as Entity;

                            if (clonedEntity != null)
                            {
                                clonedEntity.TransformBy(transformationMatrix);
                            }
                        }
                    }

                    trans.Commit();
                }      
       }      
   }
}

« Last Edit: February 10, 2010, 12:28:07 PM by BillZndl »

jthrasher

  • Guest
Re: Anyone care to take a look?
« Reply #1 on: February 10, 2010, 02:05:16 PM »


I am using AutoCAD 2010, so I am not sure if it is different in the older versions, but the database.DeepCloneObjects method to the best of my knowlege requires 4 parameters.

You might try,

IdMapping IDMap = new IdMapping();
database.DeepCloneObjects(IDCol, database.CurrentSpaceId, IDMap, false);

instead of

Quote
IdMapping IDMap = new IdMapping();
IDMap = database.DeepCloneObjects(IDCol, database.CurrentSpaceId, false);

I Also couldnt get it to compile because I was missing the names
PaletteUtils
EntityDragger
AddGroupDate
Module
SafeNativeMethods

BillZndl

  • Guest
Re: Anyone care to take a look?
« Reply #2 on: February 10, 2010, 02:22:49 PM »
Thanks.

The Imap syntax is correct for VS2008 ACADver2006 net 3.5.
Don't worry about the Module and the AddGroupDate.
I'll post new code that won' need it.
Here's the palleteutils.cs, safenativemethods and entityDragger.


Code: [Select]
/// PaletteUtils.cs  Copyright(c) 2008   Tony Tanzillo  / www.caddzone.com

using System;
using System.Text;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace PartGroupsMonitor
{
    /// <summary>
    /// Utility functions for use from Palettes and Modeless dialogs.
    /// </summary>

    public class PaletteUtils
    {
        /// <summary>
        /// Activates the AutoCAD Editor Window when a palette has focus.
        /// This should be called immediately before calling a GetXxxxx()
        /// method of the Editor to acquire graphical/command line input.
        /// </summary>
        public static void ActivateEditor()
        {
            PostMessage(ActiveDocument.Window.Handle, WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero);
            System.Windows.Forms.Application.DoEvents();
        }

        /// <summary>
        /// The currently active document
        /// </summary>

        public static Document ActiveDocument
        {
            get
            {
                return AcadApp.DocumentManager.MdiActiveDocument;
            }
        }

        #region ///<summary>
        ///
        /// Executes code in the document context (the inverse of the
        /// DocumentCollection's ExecuteInApplicationContext() method).
        ///
        /// Call this method from the Application context when there is
        /// no command active, and pass a delegate that returns void and
        /// takes no parameters, and the code in the delegate will be
        /// executed in the document context, as if it were being called
        /// from the handler of a registered command (well, that's because
        /// it actually is called from the handler of a registered command :)
        ///
        /// If you execute AutoCAD commands from the handler, you must
        /// be extremely careful, and you must ensure that AutoCAD has
        /// returned to the Command: prompt when the delegate returns.
        ///
        /// If you call this API from the handler of a UI element, like
        /// a button on a palette or modeless dialog, you should always
        /// disable that UI element while the handler executes. You can
        /// disable the UI before calling this, and enable it from the
        /// handler passed as the argument, just before it returns.
        ///</summary>
        #endregion

        [System.Security.SuppressUnmanagedCodeSecurity]
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
        private const int WM_SETFOCUS = 7;
        private const string commandName = "DOCUMENT_COMMAND";

        private const CommandFlags CommandFlagsSilent = CommandFlags.NoHistory | CommandFlags.NoMultiple;
        private const CommandFlags CommandFlagsSilentNoUndo = CommandFlagsSilent | CommandFlags.NoUndoMarker;

        public delegate void ExecuteInDocumentContextDelegate();

        private static ExecuteInDocumentContextDelegate documentContextHandler = null;

        [CommandMethod(commandName, CommandFlagsSilent)]
        public static void OnCommandExecute()
        {
            if (documentContextHandler != null)
            {
                bool flag = AcadApp.DocumentManager.DocumentActivationEnabled;
                try
                {
                    AcadApp.DocumentManager.DocumentActivationEnabled = false;
                    documentContextHandler();
                }
                finally
                {
                    documentContextHandler = null;
                    AcadApp.DocumentManager.DocumentActivationEnabled = flag;
                }
            }
        }
    }
}

Code: [Select]
//Code not in the handout!
//Posted by Bobby C. Jones @theSwamp.org
//
using System;
using System.Collections;
using System.Collections.Generic;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;



namespace PartGroupsMonitor
{
   
    public class EntityDragger : DrawJig
    {
        private Point3d m_basePoint;
        private Point3d m_previousCursorPosition;
        private Point3d m_currentCursorPosition;       
        private Matrix3d m_displacementMatrix = Matrix3d.Identity;
        private List<Entity> m_entitiesToDrag;       


        /// <summary>
        /// Drag entities on screen with cursor.
        /// </summary>
        /// <param name="basePoint">The base point of the drag</param>
        /// <param name="entitiesToDrag">ObjectId's to drag.</param>
        /// <returns>The PromptResult of the Drag operation</returns>
        ///
        public virtual PromptResult StartDrag(Point3d basePoint, params ObjectId[] entitiesToDrag)
        {
            m_basePoint = TransformPointToCurrentUcs(basePoint);       
            m_previousCursorPosition = m_basePoint;         
            m_entitiesToDrag = CloneEntitiesToDrag(entitiesToDrag);

            //Start dragging loop
            return Application.DocumentManager.MdiActiveDocument.Editor.Drag(this);           
        }

        /// <summary>
        /// WCS displacement matrix from the basepoint to the final selected point.
        /// </summary>
        ///

        public virtual Matrix3d DisplacementMatrix
        {
            get
            {
                Vector3d displacementVector = m_currentCursorPosition.GetVectorTo(m_basePoint);
                return Matrix3d.Displacement(TransformVectorToWcs(displacementVector));
            }
        }       

       
        protected override SamplerStatus Sampler(JigPrompts prompts)
        {       
            //Track cursor position
            JigPromptOptions jpo = new JigPromptOptions();
            jpo.UserInputControls = UserInputControls.Accept3dCoordinates;           
            jpo.Message = "\nEnter destination point: ";           
           
            PromptPointResult userFeedback = prompts.AcquirePoint(jpo);           
            m_currentCursorPosition = userFeedback.Value;           
           
            if (CursorHasMoved())
            {               
                //Get the vector of the move
                Vector3d displacementVector = m_currentCursorPosition.GetVectorTo(m_previousCursorPosition);               

                //Save a displacement matrix for the move
                m_displacementMatrix = Matrix3d.Displacement(displacementVector);

                //Save the cursor position
                m_previousCursorPosition = m_currentCursorPosition;               
               
                return SamplerStatus.OK;
            }
            else
            {
                return SamplerStatus.NoChange;
            }
        }


        protected override bool WorldDraw(WorldDraw draw)
        {
            Matrix3d displacementMatrix = m_displacementMatrix;           

            foreach (Entity draggingEntity in m_entitiesToDrag)
            {
                draggingEntity.TransformBy(displacementMatrix);
                draw.Geometry.Draw(draggingEntity);
            }
            return true;
        }
       

        private List<Entity> CloneEntitiesToDrag(IList entities)
        {
            List<Entity> entitiesToDrag = new List<Entity>(entities.Count);
            using (Transaction dragTrans = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
            {               
                foreach (ObjectId entityId in entities)
                {
                    Entity drawableEntity = (Entity)dragTrans.GetObject(entityId, OpenMode.ForRead);
                    entitiesToDrag.Add((Entity)drawableEntity.Clone());
                }               
            }
            return entitiesToDrag;
        }


        private bool CursorHasMoved()
        {           
            return m_currentCursorPosition != m_previousCursorPosition;                           
        }
       

        private Vector3d TransformVectorToWcs(Vector3d vector)
        {
            return vector.TransformBy(Matrix3d.Identity);
        }       

        private Point3d TransformPointToCurrentUcs(Point3d basePoint)
        {           
            Matrix3d currentUcs = Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem;
            return basePoint.TransformBy(currentUcs);
        }       
    }
}

Code: [Select]
using System;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace PartGroupsMonitor
{
    public static class SafeNativeMethods
    {
        [DllImport("acdb16.dll", CallingConvention = CallingConvention.Cdecl,
            EntryPoint = "?acdbGetAdsName@@YA?AW4ErrorStatus@Acad@@AAY01JVAcDbObjectId@@@Z")]
        extern static public ErrorStatus acdbGetAdsName(out Int64 entres, ObjectId id);
        [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
        extern static IntPtr acdbEntGet(out Int64 e);
        public static ResultBuffer EntGet(ObjectId id)
        {
            Int64 e;
            if (acdbGetAdsName(out e, id) == ErrorStatus.OK)
            {
                IntPtr res = acdbEntGet(out e);
                if (res != IntPtr.Zero)
                    return ResultBuffer.Create(res, true);
            }
            return null;
        }
    }

}


BillZndl

  • Guest
Re: Anyone care to take a look?
« Reply #3 on: February 10, 2010, 02:23:47 PM »
Here's the new  CopyFroupFromExisting:
Code: [Select]
using System;
using System.Collections;
using System.Windows.Forms;
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;
using Autodesk.AutoCAD.Interop.Common;
using Autodesk.AutoCAD.Internal;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

namespace PartGroupsMonitor
{
    class CopyGroupFromExisting
    {
        public void CreateGroup()
        {
            Document document = AcadApp.DocumentManager.MdiActiveDocument;
            Editor editor = document.Editor;
            Database database = HostApplicationServices.WorkingDatabase;           
           
            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)
                {
                    ObjectId GrpId = GroupId(selection.ObjectId);                 

                    if (!GrpId.IsNull)  //has reactors.
                    {                       
                        using (Transaction trans = database.TransactionManager.StartTransaction())
                        {

                        Group grp = trans.GetObject(GrpId, OpenMode.ForWrite, false) as Group;  //is group.

                        if (grp != null)
                        {
                            DBDictionary GrpDic = (DBDictionary)trans.GetObject(database.GroupDictionaryId, OpenMode.ForWrite);

                            ObjectId[] EntIds = grp.GetAllEntityIds();

                            ObjectIdCollection IDCol = new ObjectIdCollection(EntIds);

                            HighlightSelection(IDCol);

                            PromptPointResult PntFrom = GroupBasePoint(); //basepoint for move.

                            if (PntFrom.Status == PromptStatus.OK)
                            {
                                UnHighlightSelection(IDCol);

                                Point3d basePt = (Point3d)PntFrom.Value;
                                EntityDragger dragger = new EntityDragger();

                                PromptResult dragResult = dragger.StartDrag(basePt, EntIds);

                                if (dragResult.Status == PromptStatus.OK)
                                {
                                    grp.Remove(IDCol);

                                    IdMapping IDMap = new IdMapping();
                                    IDMap = database.DeepCloneObjects(IDCol, database.CurrentSpaceId, false);

                                    grp.Append(IDCol);

                                    MoveDeepClonedCopies(dragger.DisplacementMatrix, IDMap);

                                    string str = grp.Name;
                                    string desc = grp.Description;
                                    string NewNam = GetNewName(str, "COPY");

                                    Group NewGroup = new Group(NewNam, true);

                                    GrpDic.SetAt(NewNam, NewGroup);
                                    trans.AddNewlyCreatedDBObject(NewGroup, true);
                                    NewGroup.Description = desc;

                                    foreach (IdPair pair in IDMap)
                                    {
                                        if (pair.IsPrimary)
                                        {
                                            Entity en = (Entity)trans.GetObject(pair.Value, OpenMode.ForRead);
                                            NewGroup.Append(en.ObjectId);
                                        }
                                    }

                                    //AcadDocument ADoc = (AcadDocument)document.AcadDocument;
                                    //AcadObject AO = ADoc.Dictionaries.Item("ACAD_GROUP");
                                    //IAcadGroups iags = (IAcadGroups)AO;                                   

                                    //iags.Add(NewNam);                                   

                                    editor.WriteMessage("\nGroup < " + str + " > Copied.");
                                    Utils.PostCommandPrompt();
                                }

                                if (dragResult.Status == PromptStatus.Cancel)
                                {
                                    UnHighlightSelection(IDCol);

                                    editor.WriteMessage("\n*Cancel*\n");
                                    Utils.PostCommandPrompt();
                                }
                            }
                           
                           
                            if (PntFrom.Status == PromptStatus.Cancel)
                            {                           
                                editor.WriteMessage("\n*Cancel*\n");
                                Utils.PostCommandPrompt();
                            }

                            IDCol.Dispose();
                                           
                        }                       

                        if (grp == null)
                        {
                            editor.WriteMessage("\nNot a Group.\n");
                            Utils.PostCommandPrompt();
                        }
                        trans.Commit();
                    }

                    if (GrpId.IsNull)
                    {
                        editor.WriteMessage("\nInvalid entity.\n");
                        Utils.PostCommandPrompt();
                    }                       
                }
            } //using trans.
            else
            {
                editor.WriteMessage("\n*Cancel*\n");
                Utils.PostCommandPrompt();
            }               

        } //using document lock           
           
    }

        public ObjectId GroupId(ObjectId EntityId)
        {
            ResultBuffer rbf = SafeNativeMethods.EntGet(EntityId);
            TypedValue[] XdataOut = rbf.AsArray();
            ObjectId reactorId = ObjectId.Null;

            if (XdataOut[3].Value.ToString() == "{ACAD_REACTORS") //part of as group.
            {
                reactorId = (ObjectId)XdataOut[4].Value;               
            }
            return reactorId;               
        }

        private void UnHighlightSelection(ObjectIdCollection Oid)
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Database db = HostApplicationServices.WorkingDatabase;
           
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId entid in Oid)
                {
                    Entity ent = (Entity)trans.GetObject(entid, OpenMode.ForRead);
                    ObjectId[] ids = new ObjectId[1];
                    ids[0] = entid;
                    SubentityId index = new SubentityId(SubentityType.Edge, 0);
                    FullSubentityPath path = new FullSubentityPath(ids, index);
                    ent.Unhighlight(path, true);                       
                }
               
                trans.Commit();
            }                       
        }

        private void HighlightSelection(ObjectIdCollection Oid)
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Database db = HostApplicationServices.WorkingDatabase;
           
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    foreach (ObjectId entid in Oid)
                    {
                    Entity ent = (Entity)trans.GetObject(entid, OpenMode.ForRead);
                    ObjectId[] ids = new ObjectId[1];
                    ids[0] = entid;
                    SubentityId index = new SubentityId(SubentityType.Edge, 0);
                    FullSubentityPath path = new FullSubentityPath(ids, index);
                    ent.Highlight(path, true);                       
                    }
                   
                    trans.Commit();
                }                 
        }
       
        public PromptPointResult GroupBasePoint()
        {
            Document document = AcadApp.DocumentManager.MdiActiveDocument;
            Editor editor = document.Editor;
            PromptPointOptions options = new PromptPointOptions("\nPick base point: ");           
            options.AllowNone = false;           
            PromptPointResult pointRes = editor.GetPoint(options);           

            return pointRes;           

        }       

        private void MoveDeepClonedCopies(Matrix3d transformationMatrix, IdMapping idMap)
       
        {
            Document document = AcadApp.DocumentManager.MdiActiveDocument;
            Editor currentEditor = document.Editor;           

            using (Transaction trans = currentEditor.Document.TransactionManager.StartTransaction())
                {

                    foreach (IdPair pair in idMap)
                    {
                        if (pair.IsPrimary)
                        {
                            Entity clonedEntity = trans.GetObject(pair.Value, OpenMode.ForWrite) as Entity;

                            if (clonedEntity != null)
                            {
                                clonedEntity.TransformBy(transformationMatrix);
                            }
                        }
                    }

                    trans.Commit();
                }     
       }

        public static string GetNewName(string str, string cmd)
        {

            string NewNam = str;


            if (str.Contains("-") && cmd.Equals("COPY"))
            {
                NewNam = str.Substring(0, str.IndexOf("-", 0, str.Length) + 3) + DateTime.Now.Millisecond.ToString();
            }

            if (str.Contains("_") && cmd.Equals("COPY"))
            {
                NewNam = str.Substring(0, str.IndexOf("_", 0, str.Length) + 1) + DateTime.Now.Millisecond.ToString();
            }

            if (!str.Contains("-") && !str.Contains("_") && !str.StartsWith("*") && cmd.Equals("COPY"))
            {
                NewNam = str + "_" + DateTime.Now.Millisecond.ToString();
            }

            if (str.StartsWith("*") && cmd.Equals("COPY"))
            {
                str = str.Substring(1);
                NewNam = "~Copy" + str + "_" + DateTime.Now.Millisecond.ToString();
            }

            if (str.StartsWith("*") && cmd.Equals("MIRROR"))
            {
                str = str.Substring(1);
                NewNam = "~Mirror" + str + "_" + DateTime.Now.Millisecond.ToString();
            }

            return NewNam;
        }
   }
}

BillZndl

  • Guest
Re: Anyone care to take a look?
« Reply #4 on: February 10, 2010, 02:29:04 PM »
Make that .net 2.0