Results 1 to 8 of 8

Thread: Turn FILEDIA back on...

  1. #1
    Member
    Join Date
    2015-12
    Location
    Las Vegas, NV
    Posts
    20
    Login to Give a bone
    0

    Default Turn FILEDIA back on...

    How do I turn off and on “FILEDIA” in C#?

    If I run the code the way it is. I get a dialog box. If I don’t turn “FILEDIA” back on at the end it work the way it should, but “FILEDIA” is turn off in the drawing.

    Here is my C# code:

    Code:
    [CommandMethod("woSetupSubEng")]
            public void woSetupSubEng()
            {
                //  Get the current Document and Database.
                Document acDoc = Application.DocumentManager.MdiActiveDocument;
                Database acCurDb = acDoc.Database;
                var ed = acDoc.Editor;
                string strDWGName = acDoc.Name;
                ed.WriteMessage("\nRunning Command:. ");
                if (File.Exists(@"c:\\UserScript.scr"))
                {
                    // Set system variable to new value
                    Application.SetSystemVariable("FILEDIA", 0);
                    acDoc.SendStringToExecute("._script c:\\UserScript.scr \n", true, false, false);
                    Application.SetSystemVariable("FILEDIA", 1);
    
                }
            }
    Here the Script:
    Code:
    open
    C:\AUD\Drawings\181911-01.dwg
    zoomext
    qsave
    close
    open
    C:\AUD\Drawings\181911-02.dwg
    zoomext
    qsave
    close
    open
    C:\AUD\Drawings\181911-03.dwg
    zoomext
    qsave
    close
    Here the Lisp:
    Code:
    (defun c:zoomext ( / )
      (command "zoom" "e")
      (princ)
      )
    Please don’t worry about the Script or the Lisp. They are short and simply for testing.

    Thanks for any help!!!
    Last edited by RenderMan; 2012-12-06 at 06:22 PM. Reason: Please use [CODE] tags

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Turn FILEDIA back on...

    Quote Originally Posted by CornDawgPower View Post
    How do I turn off and on “FILEDIA” in C#?
    From Autodesk Exchange Online:

    Quote Originally Posted by Help, AutoCAD .NET Developer's Guide, Control the AutoCAD Environment, Set and Return System Variables

    Set and Return System Variables

    Code:
    // Get the current value from a system variable
    int nMaxSort = System.Convert.ToInt32(Application.GetSystemVariable("MAXSORT"));
     
    // Set system variable to new value
    Application.SetSystemVariable("MAXSORT", 100);
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Member
    Join Date
    2015-12
    Location
    Las Vegas, NV
    Posts
    20
    Login to Give a bone
    0

    Default Re: Turn FILEDIA back on...

    Thanks RenderMan,

    I do use that SetSystemVariable to set the variable but i can turn it back on with out getting the dialog box went I run the command.

    Thanks Corn

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Turn FILEDIA back on...

    When you debug your code, does the code stay in SendStringToExecute() until the Script is complete (i.e., processed all drawings), or does it (your code) move onto the FileDia restore before it (the script) is done?
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #5
    Member
    Join Date
    2015-12
    Location
    Las Vegas, NV
    Posts
    20
    Login to Give a bone
    0

    Default Re: Turn FILEDIA back on...

    It move on before its done. It don't wait.

  6. #6
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    202
    Login to Give a bone
    0

    Default Re: Turn FILEDIA back on...

    Hi,

    This is due to SendStringToExecute() asynchronous execution.

    If you realy want to do this with NET (should be easier with LISP), you have to P/Invoke acedCmd which works synchronously.

    Code:
            // Replace acad.exe with accore.dll for AutoCAD 2013
            [System.Security.SuppressUnmanagedCodeSecurity]
            [DllImport("acad.exe", EntryPoint = "acedCmd",
                CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
            extern static private int acedCmd(IntPtr resbuf);
    
           /// Calls an AutoCAD command (works synchronously).
           /// </summary>
           /// <param name="args">The command name followed by command inputs.</param>
           public static void Command(params object[] args)
           {
               ResultBuffer resbuf = new ResultBuffer();
               foreach (object obj in args)
               {
                   switch (obj.GetType().Name)
                   {
                       case "String":
                           resbuf.Add(new TypedValue((int)LispDataType.Text, obj)); break;
                       case "Int16":
                           resbuf.Add(new TypedValue((int)LispDataType.Int16, obj)); break;
                       case "Int32":
                           resbuf.Add(new TypedValue((int)LispDataType.Int32, obj)); break;
                       case "Double":
                           resbuf.Add(new TypedValue((int)LispDataType.Double, obj)); break;
                       case "Point2d":
                           resbuf.Add(new TypedValue((int)LispDataType.Point2d, obj)); break;
                       case "Point3d":
                           resbuf.Add(new TypedValue((int)LispDataType.Point3d, obj)); break;
                       case "ObjectId":
                           resbuf.Add(new TypedValue((int)LispDataType.ObjectId, obj)); break;
                       case "ObjectId[]":
                           foreach (ObjectId id in (ObjectId[])obj)
                               resbuf.Add(new TypedValue((int)LispDataType.ObjectId, id));
                           break;
                       case "ObjectIdCollection":
                           foreach (ObjectId id in (ObjectIdCollection)obj)
                               resbuf.Add(new TypedValue((int)LispDataType.ObjectId, id));
                           break;
                       case "SelectionSetDelayMarshalled":
                       case "SelectionSetFullyMarshalled":
                           resbuf.Add(new TypedValue((int)LispDataType.SelectionSet, obj)); break;
                       default:
                           throw new InvalidOperationException("Unsupported type in Command() method");
                   }
               }
               acedCmd(resbuf.UnmanagedObject);
    Then call:
    Code:
    Application.SetSystemVariable("FILEDIA", 0);
    Command("._script", "c:\\UserScript.scr");
    Application.SetSystemVariable("FILEDIA", 1);

  7. #7
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    202
    Login to Give a bone
    0

    Default Re: Turn FILEDIA back on...

    For AutoCAD 2009 or later, you can use the non-public Editor.RunCommand() method instead of P/Invoking acedCmd().
    see this here:
    http://www.theswamp.org/index.php?to...3306#msg483306

  8. #8
    Member
    Join Date
    2015-12
    Location
    Las Vegas, NV
    Posts
    20
    Login to Give a bone
    0

    Default Re: Turn FILEDIA back on...

    Thanks Gile,
    I will take a look at your posting.

    I was out last week for SQL training.

    In the completed command, the I will get a dialog box so that I can select the files to run the script on (is the reason why i didn't go with LISP).

    Thanks a gain.

Similar Threads

  1. Replies: 1
    Last Post: 2013-05-15, 10:48 PM
  2. How do I turn 'Cycle' back on?
    By ukdodger in forum AutoCAD 3D (2006 or below)
    Replies: 4
    Last Post: 2011-11-16, 04:31 PM
  3. How do I turn back on the Project Browser? (was.....something dumb)
    By ntnik in forum Revit Architecture - General
    Replies: 2
    Last Post: 2008-10-03, 06:29 AM
  4. How do I turn levels back on in sections?
    By jeff.95551 in forum Revit - Platform
    Replies: 3
    Last Post: 2007-11-14, 11:12 PM
  5. Replies: 3
    Last Post: 2006-09-22, 08:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •