Author Topic: xref  (Read 8156 times)

0 Members and 1 Guest are viewing this topic.

cadpro

  • Guest
xref
« on: November 08, 2007, 12:48:07 AM »
Hi all,

In C#, I have undefined the Xref command for some reason. After some coding, I need to bring back the Xref dialog when the user gives the XREF command. How do I bring back the xref dialog?

Thanks

Bob Wahr

  • Guest
Re: xref
« Reply #1 on: November 08, 2007, 12:55:47 AM »
There's probably a way to do it programmatically, but if all else fails, you can send a ".xref" comand.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: xref
« Reply #2 on: November 08, 2007, 04:56:16 AM »
Hi all,

In C#, I have undefined the Xref command for some reason................

If you don't know why, we won't be much help.

Have you also changed FILEDIA and CMDDIA and EXPERT
« Last Edit: November 08, 2007, 03:21:24 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: xref
« Reply #3 on: November 08, 2007, 07:45:50 AM »
< sigh >

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8659
  • AKA Daniel
Re: xref
« Reply #4 on: November 08, 2007, 07:47:39 AM »
(setq T nil)

Glenn R

  • Guest
Re: xref
« Reply #5 on: November 08, 2007, 07:49:18 AM »
 :evil:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: xref
« Reply #6 on: November 08, 2007, 03:04:10 PM »
I'm interested in seeing the code ..

in the mean-time, you could try something like any of these at the commandline :

.xref

externalreferences

.externalreferences


Command: redefine
Enter command name: xref
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: xref
« Reply #7 on: November 08, 2007, 04:48:14 PM »

I've just noticed this post replicated at several other locations ..

cadpro  ,  are you having some sort of competition ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Bob Wahr

  • Guest
Re: xref
« Reply #8 on: November 08, 2007, 04:57:12 PM »
Judging by his previous posts here, he is looking for the quickest solution and by solution I mean completed code all shiny and wrapped up with a big red bow on it.  Unfortunately, unless he was a bit more eloquent, and by a bit I mean incredibly huge amounts, on the other forums, it's pretty close to impossible to know exactly what he wants, and absolutely impossible to know what he has done.

Maybe I'm just being cynical but it looks like he would rather just order fish sticks.

Glenn R

  • Guest
Re: xref
« Reply #9 on: November 08, 2007, 07:18:03 PM »
Got it in one there me thinks Bob.

cadpro

  • Guest
Re: xref
« Reply #10 on: November 12, 2007, 01:18:15 AM »
My apologies to all. As I'm a novice, and due to my interest in learning C#, I did post a few questions. Anyways, I've done something of my own with a few references here and there. But unfortunately, it doesn't change the UCS back to the previous one after the command ends.  Can anybody tell me where I have gone wrong? Here is the code.

Code: [Select]
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.Geometry;

using System;
using System.Collections.Specialized;
using System.Windows.Forms;

namespace XU2
{
    public class XU:IExtensionApplication
    {
        public static Matrix3d ucs;

        public void Initialize()
        {
            DocumentCollection dm = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
            dm.DocumentLockModeChanged += new DocumentLockModeChangedEventHandler(Change);
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            doc.CommandEnded += new CommandEventHandler(doc_CommandEnded);
           
        }

        public void Terminate()
        {
        }

        private void Change(object sender,DocumentLockModeChangedEventArgs e)
        {
            if (e.GlobalCommandName == "XATTACH")
            {
                ModifyLayers();
                CreateLayer();
                ucs = UCS2WCS();
            }
        }

        private static ObjectId CreateLayer()
        {
            ObjectId layerId = ObjectId.Null;//the return value for this function
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                //Get the layer table first...
                LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead);

                //Check if 0-XREF exists;;;
                if (lt.Has("0-XREF"))
                {
                    layerId = lt["0-XREF"];
                    db.Clayer = layerId;
                }
                else
                {
                    //if not, create the layer here.
                    LayerTableRecord ltr = new LayerTableRecord();
                    ltr.Name = "0-XREF";
                    ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, 1);
                    ltr.IsFrozen = false;
                    ltr.IsLocked = false;
                    ltr.IsOff = false;
                    //upgrade the open from read to write
                    lt.UpgradeOpen();
                    layerId = lt.Add(ltr);
                    trans.AddNewlyCreatedDBObject(ltr, true);
                    db.Clayer = layerId;
                }
                trans.Commit();
            }
            return layerId;
        }

        public void ModifyLayers()
        {
            Database db = HostApplicationServices.WorkingDatabase;

            try
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
                    foreach (ObjectId objId in lt)
                    {
                        LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(objId, OpenMode.ForWrite);

                        if (ltr.Name == "0" || ltr.Name == "Defpoints")
                        {
                            if (ltr.IsLocked) { ltr.IsLocked = false; }
                            if (ltr.IsFrozen) { ltr.IsFrozen = false; }
                            if (ltr.IsOff) { ltr.IsOff = false; }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
           
        }

        public static Matrix3d UCS2WCS()
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            Matrix3d original = ed.CurrentUserCoordinateSystem;

            ed.CurrentUserCoordinateSystem = Matrix3d.Identity;

            return original;
       
        }

        void doc_CommandEnded(object sender, CommandEventArgs e)
        {
            try
            {
                if (e.GlobalCommandName == "XATTACH")
                {
                    Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
                    ed.WriteMessage("\n The command is XATTACH");
                    ed.CurrentUserCoordinateSystem = ucs;
                    ed.WriteMessage("\n" + ucs);
                }               
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
       
    }
}

Thanks

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: xref
« Reply #11 on: November 12, 2007, 04:03:43 AM »

works for me

Command: xattach

Attach Xref "Test": C:\Test.dwg
"Test" loaded.
 The command is XATTACH
((0.822724527413075,-0.568440280058454,0,840.784370459755),(0.568440280058454,0.
822724527413075,0,643.446602615863),(0,0,1,0),(0,0,0,1))

also,
you may want to restore the layer to the previous setting ..


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: xref
« Reply #12 on: November 12, 2007, 04:17:44 AM »


Cadpro
Just a note :
The original query does not mention event trapping, it mentions redefined commands.
You could help yourself a little better if the query was relevant.
... also posting a working (or failing) sample of code may also give a better indication of the direction you are trying to take.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

cadpro

  • Guest
Re: xref
« Reply #13 on: November 12, 2007, 07:17:27 AM »
Thanks for the reply kerry.

Yes, I started coding this work with undefining and redefining xref. But as I went on furthur coding, I changed the whole logic. Don't know if I'm right. As I mentioned in the earlier post, I'm just a novice. Thought I would go about checking the e.CommandName in code to see if xref or xattach, whichever is correct, is typed by the user.

And, btw, I don't know why it is not working for me. Can it be something wrong with the files I'm testing with. I will attach the files too.

Thanks

cadpro

  • Guest
Re: xref
« Reply #14 on: November 12, 2007, 07:36:39 AM »

also,
you may want to restore the layer to the previous setting ..


Yes, I think that is a good suggession. I would want to bring back the previous layer. Hence I globally declared a variable like this:

Code: [Select]
public static ObjectId curLayer;

void doc_CommandEnded(object sender, CommandEventArgs e)
        {
            try
            {
                if (e.GlobalCommandName == "XATTACH")
                {
                    Database db = HostApplicationServices.WorkingDatabase;
                    Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
                    ed.WriteMessage("\n The command is XATTACH");
                    ed.CurrentUserCoordinateSystem = ucs;
                    ed.WriteMessage("\n" + ucs);
                    db.Clayer = curLayer;
                }               
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
« Last Edit: November 12, 2007, 07:54:46 AM by cadpro »