Author Topic: Layout / selection objects  (Read 2826 times)

0 Members and 1 Guest are viewing this topic.

bikelink

  • Guest
Layout / selection objects
« on: December 11, 2010, 06:17:30 AM »
I have a Dwg with layouts..and viewports.
the drawing is saved with  named layout active (example a "Bom" layout)
When I open the drawing (onDocumentCreated) I  need to select  the objects in the model space with a selectionset..

the problem is :

I try then to change the active layout (set Model) before to execute the  "selection set" (selectAll())  but the selection fails.
When autocad shows the drawing the active layout is right ..and Model is active.


onDocumentCreated(......)
{
                B2UtilCad.b2Layout.SetCurrentLayout(m_DocumentoAttivo, "Model");

                TypedValue[] values = { new TypedValue((int)DxfCode.Start, "3DSOLID") };
                SelectionFilter selFil = new SelectionFilter(values);

               PromptSelectionResult eeee =m_DocumentoAttivo.Editor.SelectAll(selFil);

}

I would like to avoid  to run a search through the modelspace the objects..

thanks in advance for every idea suggested.
« Last Edit: December 11, 2010, 06:20:33 AM by bikelink »

Jeff H

  • Needs a day job
  • Posts: 6151
Re: Layout / selection objects
« Reply #1 on: December 17, 2010, 12:54:44 AM »
Have you tried using Editor.SwitchToModelSpace or confirming "TILEMODE" = 1

kaefer

  • Guest
Re: Layout / selection objects
« Reply #2 on: December 17, 2010, 02:21:42 AM »
Have you tried using Editor.SwitchToModelSpace or confirming "TILEMODE" = 1

Hi Jeff,

he's trying to do some pretty heavy lifting inside an event handler for DocumentManager.DocumentCreated, if I get that right. I don't think that you can access the Editor class for anything other than WriteMessage at that point. Even the startup lisp and restore commands for palettes aren't executed yet.

Jeff H

  • Needs a day job
  • Posts: 6151
Re: Layout / selection objects
« Reply #3 on: December 17, 2010, 02:45:36 AM »

Hi Jeff,

he's trying to do some pretty heavy lifting inside an event handler for DocumentManager.DocumentCreated, if I get that right. I don't think that you can access the Editor class for anything other than WriteMessage at that point. Even the startup lisp and restore commands for palettes aren't executed yet.

Hey Thorsten,

First off thanks, as always for the good info.


Then this could be the problem then?
Code: [Select]
PromptSelectionResult eeee =m_DocumentoAttivo.[color=red]Editor[/color].SelectAll(selFil);

bikelink

  • Guest
Re: Layout / selection objects
« Reply #4 on: December 17, 2010, 03:21:59 AM »
Have you tried using Editor.SwitchToModelSpace or confirming "TILEMODE" = 1

Hi Jeff,

he's trying to do some pretty heavy lifting inside an event handler for DocumentManager.DocumentCreated, if I get that right. I don't think that you can access the Editor class for anything other than WriteMessage at that point. Even the startup lisp and restore commands for palettes aren't executed yet.

that's true. isn't possible...'cause the document looks like "read only" mode.
I know that's a little difficult..
Any idea to change the current layout when we open a drawing ?

Jeff H

  • Needs a day job
  • Posts: 6151
Re: Layout / selection objects
« Reply #5 on: December 17, 2010, 07:17:45 AM »
This seems to work if it helps


Code: [Select]
[CommandMethod("OpenAndChangeLayout", CommandFlags.Session)]
        public void OpenAndChangeLayout()
        {
            DocumentCollection docMgr = Application.DocumentManager;
            docMgr.DocumentCreated += new DocumentCollectionEventHandler(DocCreated);
            docMgr.Open(@"C:\Test\Test.dwg", false);
         
        }

        public static void DocCreated(Object sender, DocumentCollectionEventArgs e)
        {
            Application.DocumentManager.DocumentCreated -= new DocumentCollectionEventHandler(DocCreated);
            Document doc = e.Document;
            Application.DocumentManager.MdiActiveDocument = doc;
            Editor ed = doc.Editor;

            LayoutManager.Current.CurrentLayout = "Model";           

            TypedValue[] tv = { new TypedValue((int)DxfCode.Start, "3DSOLID") };
            SelectionFilter sf = new SelectionFilter(tv);
           
            PromptSelectionResult psr = ed.SelectAll(sf);
            SelectionSet ss = psr.Value;

            foreach (SelectedObject so in ss)
            {
                ed.WriteMessage("\n " + so.ObjectId.ToString());
            }
        }

kaefer

  • Guest
Re: Layout / selection objects
« Reply #6 on: December 17, 2010, 10:10:53 AM »
This seems to work if it helps

That's funny, it seems I haven't tested this yet with an existing drawing. Just try it with a new one. (KABOOM)

Quote
Code: [Select]
            LayoutManager.Current.CurrentLayout = "Model";           

            TypedValue[] tv = { new TypedValue((int)DxfCode.Start, "3DSOLID") };
            SelectionFilter sf = new SelectionFilter(tv);
           
            PromptSelectionResult psr = ed.SelectAll(sf);

Here's the question: Why change the layout when SelectAll will return all objects from all layouts? Maybe adding TypedValue((int)DxfCode.LayoutName, "Model") to the SelectionFilter will do...


Jeff H

  • Needs a day job
  • Posts: 6151
Re: Layout / selection objects
« Reply #7 on: December 17, 2010, 11:01:48 AM »
This seems to work if it helps

That's funny, it seems I haven't tested this yet with an existing drawing. Just try it with a new one. (KABOOM)

Quote
Code: [Select]
            LayoutManager.Current.CurrentLayout = "Model";           

            TypedValue[] tv = { new TypedValue((int)DxfCode.Start, "3DSOLID") };
            SelectionFilter sf = new SelectionFilter(tv);
           
            PromptSelectionResult psr = ed.SelectAll(sf);

Here's the question: Why change the layout when SelectAll will return all objects from all layouts? Maybe adding TypedValue((int)DxfCode.LayoutName, "Model") to the SelectionFilter will do...



Of course it needs error handling, and needs to check if the drawing exists. That was to see if the the Editor.SelectAll would work under the DocumentCreated  event.

I thought for some reason SelectAll just selected active layout, and I was wrong.

I was just giving the OP a idea