Author Topic: The "cuiload" command problem!  (Read 8805 times)

0 Members and 1 Guest are viewing this topic.

csharpbird

  • Newt
  • Posts: 64
The "cuiload" command problem!
« on: April 15, 2007, 02:42:19 AM »
I want to load a partial cui file using the "cuiload" command.When I run the following codes,I cannot load "MyCUI.cui".
Code: [Select]
string cuiFileName = @"C:\MyCUI.cui";
Tools.Document.SendStringToExecute(" filedia 0 " + "cuiload " + filename + " filedia 1 ", false, false, false);
But the following is OK:
Code: [Select]
string cuiFileName = "\"C:\\MyCUI.cui\"";
Tools.Document.SendStringToExecute(" filedia 0 " + "cuiload " + filename + " filedia 1 ", false, false, false);
And using "acedCmd" is wrong again:
Code: [Select]
        [DllImport("acad.exe", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedCmd")]
        [CommandMethod("LoadCUI")]
        public void saveCui()
        {
            string cuiFileName = "\"C:\\MyCUI.cui\"";      
            ResultBuffer rb = new ResultBuffer();
            // RTSTR = 5005
            rb.Add(new TypedValue(5005, "FILEDIA"));
            rb.Add(new TypedValue(5005, "0"));
            // start the insert command
            acedCmd(rb.UnmanagedObject);

            //CUILOAD
            rb = new ResultBuffer();
            rb.Add(new TypedValue(5005, "_CUILOAD"));
            rb.Add(new TypedValue(5005, cuiFileName));
            acedCmd(rb.UnmanagedObject);

            //FILEDIA
            rb = new ResultBuffer();
            rb.Add(new TypedValue(5005, "FILEDIA"));
            rb.Add(new TypedValue(5005, "1"));
            acedCmd(rb.UnmanagedObject);
         }
Can someone solve this problem?
Thanks in advance!
« Last Edit: April 15, 2007, 06:51:15 AM by csharpbird »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: The "cuiload" command problem!
« Reply #1 on: April 15, 2007, 06:29:46 AM »
This works for me in AC2008 ..

Code: [Select]
       
        [CommandMethod("Menu_1")]
        public void Menu_1()
        {
           Document doc = AcadApp.DocumentManager.MdiActiveDocument;
           string MenuQualifiedName = "K:\\DbCon.cui";
            doc.SendStringToExecute("FILEDIA 0 cuiload "
                + MenuQualifiedName
                + " FILEDIA 1 ",
                false, false, true);           
        }

Command: CUIUNLOAD
Customization file unloaded successfully. Customization Group: DBCONNECT
Command: NETLOAD
Command: MENU_1
Command: FILEDIA
Enter new value for FILEDIA <1>: 0
Command: cuiload
Enter name of customization file to load: K:\DbCon.cui
Customization file loaded successfully. Customization Group: DBCONNECT
Command: FILEDIA
Enter new value for FILEDIA <0>: 1
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: The "cuiload" command problem!
« Reply #2 on: April 15, 2007, 06:33:55 AM »

string cuiFileName = @"C:\MyCUI.cui";
Tools.Document.SendStringToExecute(" filedia 0 " + "cuiload " + filename + " filedia 1 ", false, false, false

& why the space before the first filedia ??
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.

csharpbird

  • Newt
  • Posts: 64
Re: The "cuiload" command problem!
« Reply #3 on: April 15, 2007, 06:47:55 AM »
How to load partial CUI files using "acedcmd"?
« Last Edit: April 15, 2007, 06:50:41 AM by csharpbird »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: The "cuiload" command problem!
« Reply #4 on: April 15, 2007, 07:37:23 AM »
I have no idea.
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: The "cuiload" command problem!
« Reply #5 on: April 15, 2007, 07:46:56 AM »
.. but I seem to recall that Tony T' published a CommandLine class that would probably do the job.

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.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8804
  • AKA Daniel
Re: The "cuiload" command problem!
« Reply #6 on: April 15, 2007, 07:49:21 AM »
this is untested, but may give you some ideas
also you didn't say for what version of Autocad




Code: [Select]
#region Using this Stuff
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Runtime.InteropServices;
//
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using Trans = Autodesk.AutoCAD.DatabaseServices;
#endregion

namespace csharpbird
{
  public class birdy
  {
    #region Const
    // Type of resbuf element
    const int RTNONE = 5000; /* No result */
    const int RTREAL = 5001; /* Real number */
    const int RTPOINT = 5002; /* 2D point X and Y only */
    const int RTSHORT = 5003; /* Short integer */
    const int RTANG = 5004; /* Angle */
    const int RTSTR = 5005; /* String */
    const int RTENAME = 5006; /* Entity name */
    const int RTPICKS = 5007; /* Pick set */
    const int RTORINT = 5008; /* Orientation */
    const int RT3DPOINT = 5009; /* 3D point - X, Y, and Z */
    const int RTLONG = 5010; /* Long integer */
    const int RTVOID = 5014; /* Blank symbol */
    const int RTLB = 5016; /* list begin */
    const int RTLE = 5017; /* list end */
    const int RTDOTE = 5018; /* dotted pair */
    const int RTNIL = 5019; /* nil */
    const int RTDXF0 = 5020; /* DXF code 0 for ads_buildlist only */
    const int RTT = 5021; /* T atom */
    const int RTRESBUF = 5023; /* resbuf */
    const int RTMODELESS = 5027; /* interrupted by modeless dialog */
    // Error return code
    const int RTNORM = 5100; /* Request succeeded */
    const int RTERROR = -5001; // Some other error
    const int RTCAN = -5002; // User cancelled request -- Ctl-C
    const int RTREJ = -5003; // AutoCAD rejected request -- invalid
    const int RTFAIL = -5004; // Link failure -- Lisp probably died
    const int RTKWORD = -5005; // Keyword returned from getxxx() routine
    const int RTINPUTTRUNCATED = -5008; // Input didn't all fit in the buffer
    #endregion

    #region SendCmd

    [System.Security.SuppressUnmanagedCodeSecurity]
    [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    internal static extern int acedCmd(IntPtr rb);

    public static void SendCmd(ResultBuffer rb)
    {
      try
      {
        acedCmd(rb.UnmanagedObject);
      }
      catch
      {
        throw;
      }
      finally
      {
        rb.Dispose();
      }
    }
    #endregion

    #region
    [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    static internal extern int acedSetVar(string variableName, IntPtr value);
    //
    public static bool SetSystemVariable(string variableName, object value)
    {
      try
      {
        int valType = 0;
        if (value.GetType() == typeof(Double))
        {
          valType = RTREAL;
        }
        if (value.GetType() == typeof(Point2d))
        {
          valType = RTPOINT;
        }
        if (value.GetType() == typeof(Int16))
        {
          valType = RTSHORT;
        }
        if (value.GetType() == typeof(String))
        {
          valType = RTSTR;
        }
        if (value.GetType() == typeof(ObjectId))
        {
          valType = RTENAME;
        }
        if (value.GetType() == typeof(ObjectIdCollection))
        {
          valType = RTPICKS;
        }
        if (value.GetType() == typeof(ObjectIdCollection))
        {
          valType = RTPICKS;
        }
        if (value.GetType() == typeof(Point3d))
        {
          valType = RT3DPOINT;
        }
        if (value.GetType() == typeof(Int32))
        {
          valType = RTLONG;
        }
        using (ResultBuffer val = new ResultBuffer(new TypedValue(valType, value)))
        {
          if (acedSetVar(variableName, val.UnmanagedObject) == RTNORM)
          {
            return true;
          }
        }
      }
      catch
      {
        throw;
      }
      return false;
    }
    #endregion

    [CommandMethod("LoadCUI")]
    public void saveCui()
    {
      //FILEDIA
      SetSystemVariable("FILEDIA", 0);
      SetSystemVariable("CMDECHO", 0);
     
      //
      string cuiFileName = @"C:\MyCUI.cui";
      ResultBuffer rb = new ResultBuffer();
      rb.Add(new TypedValue(RTSTR, "_CUILOAD"));
      rb.Add(new TypedValue(RTSTR, cuiFileName));
      SendCmd(rb);

      //FILEDIA
      SetSystemVariable("FILEDIA", 1);
    }
  }
}
« Last Edit: April 15, 2007, 07:53:10 AM by Danielm103 »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: The "cuiload" command problem!
« Reply #7 on: April 15, 2007, 08:03:24 AM »
Just came back from playing with the problem

Yes Daniel, I think the
internal static extern int acedCmd(IntPtr rb);
solves it ..

This works for me ..
Code: [Select]
       
        [DllImport("acad.exe",
            CharSet = CharSet.Ansi,
            CallingConvention = CallingConvention.Cdecl,
            EntryPoint = "acedCmd")]
        private static extern int acedCmd(System.IntPtr vlist);

        [CommandMethod("Menu_2")]
        public void Menu_2()
        {
           string MenuQualifiedName = "K:\\DbCon.cui";     

           ResultBuffer rb = new ResultBuffer();
           rb.Add(new TypedValue(5005, "FILEDIA"));
           rb.Add(new TypedValue(5005, "0"));
           rb.Add(new TypedValue(5005, "cuiLoad"));
           rb.Add(new TypedValue(5005, MenuQualifiedName));
           rb.Add(new TypedValue(5005, "FILEDIA"));
           rb.Add(new TypedValue(5005, "1"));
           acedCmd(rb.UnmanagedObject);
        }           
       
« Last Edit: April 15, 2007, 08:08:16 AM 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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: The "cuiload" command problem!
« Reply #8 on: April 15, 2007, 08:15:50 AM »
.. and with the CUIUNLOAD added ..
it behaves properly even if the CUI isn't loaded initially, so no need to check.

Code: [Select]
        [DllImport("acad.exe",
            CharSet = CharSet.Ansi,
            CallingConvention = CallingConvention.Cdecl,
            EntryPoint = "acedCmd")]
        private static extern int acedCmd(System.IntPtr vlist);

        [CommandMethod("Menu_2")]
        public void Menu_2()
        {
           string MenuQualifiedName = "K:\\DbCon.cui";
           string MenuGroupName = "DBCONNECT";
           ResultBuffer rb = new ResultBuffer();
           rb.Add(new TypedValue(5005, "FILEDIA"));
           rb.Add(new TypedValue(5005, "0"));
           rb.Add(new TypedValue(5005, "cuiUnLoad"));
           rb.Add(new TypedValue(5005, MenuGroupName));
           rb.Add(new TypedValue(5005, "cuiLoad"));
           rb.Add(new TypedValue(5005, MenuQualifiedName));
           rb.Add(new TypedValue(5005, "FILEDIA"));
           rb.Add(new TypedValue(5005, "1"));
           acedCmd(rb.UnmanagedObject);
        }
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: The "cuiload" command problem!
« Reply #9 on: April 15, 2007, 08:47:42 AM »


Daniel,
will your ACAD version run this ? :
AcadApp.SetSystemVariable("FILEDIA", 0);
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.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8804
  • AKA Daniel
Re: The "cuiload" command problem!
« Reply #10 on: April 15, 2007, 09:39:01 AM »


Daniel,
will your ACAD version run this ? :
AcadApp.SetSystemVariable("FILEDIA", 0);

Yes, for some reason I had acad2005 on the brain which does not
 AcadApp.SetSystemVariable …. But 2005 didn’t have the cui yet... !Doh  :oops:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: The "cuiload" command problem!
« Reply #11 on: April 15, 2007, 09:43:04 AM »
... !Doh  :oops:

Thats OK, no problems .. after all it is Friday.
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: The "cuiload" command problem!
« Reply #12 on: April 15, 2007, 11:58:22 PM »
csharpbird,

Did that work for you ??
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.