Author Topic: Can't set active drawing for it's modify.  (Read 4334 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Can't set active drawing for it's modify.
« on: June 03, 2010, 11:02:57 AM »
AutoCAD 2009 SP3 x86 Enu,
MS Visual Studio 2010,
Windows XP x86 SP3 Rus,
.Net Framework 3.5 SP1 x86
=======================

Why I get mistake (look code comments)?

Code: [Select]
   public class Class1
    {
        [CommandMethod("q5", [color=red]CommandFlags.Session[/color])]
        public void q5()
        {
            //Remember current drawing
            Document dwg = acad.DocumentManager.MdiActiveDocument;  
          
            //Drawing for edition
            string fileName = @"C:\Documents and Settings\andrey.bushman\My Documents\Drawing1++.dwg";
            
            //Open drawing
            Document dwg2 = acad.DocumentManager.Open(fileName); //[color=red]Instance not null![/color]
          
            //set current drawing
            acad.DocumentManager.MdiActiveDocument = dwg2;//[color=red]HERE I GET ERROR: eInvalidInput - WHY???...[/color]

            //Modify drawing
            dwg[color=red]2[/color].SendStringToExecute("_circle 0,0 50 _zoom _all ", true, [color=red]false[/color], true);

            //Restore active drawing
            acad.DocumentManager.MdiActiveDocument = dwg;

            //Save & Close drawing
            dwg2.CloseAndSave(fileName);
        }
    }
« Last Edit: June 04, 2010, 05:26:07 AM by Hwd »

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Can't set active drawing for it's modify.
« Reply #1 on: June 04, 2010, 04:52:36 AM »
Will work it:
Code: [Select]
           
if (acad. DocumentManager. MdiActiveDocument! = dwg2)
{
   acad. DocumentManager. MdiActiveDocument = dwg2;
}
And it:
Code: [Select]
((AcadDocument) dwg2.AcadDocument).Activate ();
It is strange that in the first variant mandatory check is required...

The subject is closed.
« Last Edit: June 04, 2010, 04:59:42 AM by Hwd »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Can't set active drawing for it's modify.
« Reply #2 on: June 04, 2010, 05:09:19 AM »

Just for interest, are you able to draw a circle in dwg2 and save it ??
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.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Can't set active drawing for it's modify.
« Reply #3 on: June 04, 2010, 05:19:55 AM »

Just for interest, are you able to draw a circle in dwg2 and save it ??

It does not turn out yet (((

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Can't set active drawing for it's modify.
« Reply #4 on: June 04, 2010, 05:36:50 AM »
It work:
Code: [Select]
        [CommandMethod("q5", CommandFlags.Session)]
        public void q5()
        {           
            Document dwg = acad.DocumentManager.MdiActiveDocument;
             
            string fileName = @"C:\Documents and Settings\andrey.bushman\My Documents\Drawing1++.dwg";             
            Document dwg2 = acad.DocumentManager.Open(fileName, false); //Полученный объект не равен null, т.о. его можно использовать далее.
           
            if (acad.DocumentManager.MdiActiveDocument != dwg2)
            {
                acad.DocumentManager.MdiActiveDocument = dwg2;
            }           
           
            ((AcadDocument)dwg2.AcadDocument).SendCommand("_circle 0,0 50 _zoom _all ");
           
            dwg2.CloseAndSave(fileName);

            if (acad.DocumentManager.MdiActiveDocument != dwg)
            {
                acad.DocumentManager.MdiActiveDocument = dwg;
            }         
        }
When I will open a file "Drawing1++.dwg" - I see a circle.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Can't set active drawing for it's modify.
« Reply #5 on: June 04, 2010, 06:07:16 AM »
Are you using mixed COM and wrapped ARX now ??


I see that you've changed the first post ... that is really confusing.

It helps for anyone following later if you nominate your references ie ..
where does AcadDocument come from.
((AcadDocument)dwg2.AcadDocument).SendCommand("_circle 0,0 50 _zoom _all ");

Anyone who copies this and tries to see how it works will have trouble .. better to explain now :)

and I see that SendStringToExecute is now SendCommand


I'm happy that you're happy with it working :)


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.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Can't set active drawing for it's modify.
« Reply #6 on: June 04, 2010, 06:23:39 AM »
I see that SendStringToExecute is now SendCommand
SendStringToExecute it's Document's method - not draw circle in my code
SendCommand it's AcadDocument's method - successfully draw circle in my code

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Can't set active drawing for it's modify.
« Reply #7 on: June 04, 2010, 06:33:15 AM »

Yes, I understand.
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.