Author Topic: How to placing toolbar programble  (Read 1331 times)

0 Members and 1 Guest are viewing this topic.

MarioR

  • Newt
  • Posts: 64
How to placing toolbar programble
« on: November 18, 2021, 07:39:27 AM »
Hello,

how can i set the location for docking toolbar.
I using autocad 2022, i have tried follow:

1. remowe the workspacetoolbar
2. set the toolbar (from partial CustomizationSection) visible,orient,X-,YCoordinate
3. create a new workspacetoolbar orient,dockRow, dockColumn, X-,YCoordinate
4. save the partial and main *cui

After the function are all changed toolbars in cui have correct datas, but the toolbar on autocad screen have not changed.
Even if i change the ToolbarOrient from top to bottom have no effect. But in the cui ist the change correct.

What i have forgotten?

The code are using own data classes, but i think it is readable ;-)

Code - C#: [Select]
  1. public static CustomizationSection placeToolbars(clToolbarPlaces tbPlaces)
  2. {
  3.   CustomizationSection csMain = null;
  4.   if ((tbPlaces != null) && (tbPlaces.CheckedToolbarIds.Count > 0))
  5.   {
  6.     string user = Environment.UserName;
  7.     clUserPlace userPlace = null;
  8.     // search user defined saved places
  9.     if ((tbPlaces.UserPlaces != null) && (tbPlaces.UserPlaces.Count > 0))
  10.     {
  11.       foreach (clUserPlace up in tbPlaces.UserPlaces)
  12.       {
  13.         if (up.Description.Equals(user))
  14.         {
  15.           userPlace = up;
  16.           break;
  17.         }
  18.       }
  19.     }
  20.     // otherwise use default
  21.     if (userPlace == null) userPlace = tbPlaces.DefaultPlace;
  22.     if ((userPlace.Places != null) && (userPlace.Places.Count > 0))
  23.     {
  24.       String mainCuixName = (Application.GetSystemVariable("MENUNAME") as String) + ".cuix";
  25.       csMain = new CustomizationSection(mainCuixName, false);
  26.       if (csMain != null)
  27.       {
  28.         string cuWorkspaceName = (string)Application.GetSystemVariable("WSCURRENT");
  29.         Workspace cuWorkspace = csMain.getWorkspace(cuWorkspaceName);
  30.         if (cuWorkspace != null)
  31.         {
  32.           // First remove the workspace toolbars
  33.           foreach (clToolbarPlace tbPlace in userPlace.Places)
  34.           {
  35.             if ((tbPlace != null) && (tbPlaces.CheckedToolbarIds.ContainsKey(tbPlace.ID)))
  36.             {
  37.               foreach (String partCuiFName in csMain.PartialCuiFiles)
  38.               {
  39.                 if (partCuiFName.ToLower().Contains(tbPlaces.CheckedToolbarIds[tbPlace.ID].CuiName.ToLower()))
  40.                 {
  41.                   CustomizationSection csPart = new CustomizationSection(partCuiFName);
  42.                   Toolbar tbFind = csPart.MenuGroup.Toolbars.FindToolbarWithName(tbPlaces.CheckedToolbarIds[tbPlace.ID].Name);
  43.                   if (tbFind != null)
  44.                   {
  45.                     WorkspaceToolbar wsToolbar = cuWorkspace.WorkspaceToolbars.FindWorkspaceToolbar(
  46.                       tbFind.ElementID, csPart.MenuGroup.Name);
  47.                     if (wsToolbar != null)
  48.                     {
  49.                       wsToolbar.Display = 0;
  50.                       cuWorkspace.WorkspaceToolbars.Remove(wsToolbar);
  51.                     }
  52.                   }
  53.                 }
  54.               }
  55.             }
  56.           }
  57.          
  58.           //if (csMain.IsModified)
  59.           csMain.Save();
  60.           // now set the position in partial cui and create new workspacetoolbars
  61.           Dictionary<string, CustomizationSection> changedCUIS = new Dictionary<string, CustomizationSection>();
  62.           foreach (clToolbarPlace tbPlace in userPlace.Places)
  63.           {
  64.             if ((tbPlace != null) && (tbPlaces.CheckedToolbarIds.ContainsKey(tbPlace.ID)))
  65.             {
  66.               clToolbarId tbId = tbPlaces.CheckedToolbarIds[tbPlace.ID];
  67.               if (tbId != null)
  68.               {
  69.                 foreach (String partCuiFName in csMain.PartialCuiFiles)
  70.                 {
  71.                   if (partCuiFName.ToLower().Contains(tbId.CuiName.ToLower()))
  72.                   {
  73.                     CustomizationSection csPart = new CustomizationSection(partCuiFName);
  74.                     Toolbar tbFind = csPart.MenuGroup.Toolbars.FindToolbarWithName(tbId.Name);
  75.                     if (tbFind != null)
  76.                     {
  77.                       switch (tbPlace.Side)
  78.                       {
  79.                         case "T":
  80.                           tbFind.ToolbarVisible = ToolbarVisible.show;
  81.                           tbFind.ToolbarOrient = ToolbarOrient.top;
  82.                           tbFind.XCoordinate = tbPlace.RowCol;
  83.                           tbFind.YCoordinate = tbPlace.Order;
  84.                           break;
  85.                         case "B":
  86.                           tbFind.ToolbarVisible = ToolbarVisible.show;
  87.                           tbFind.ToolbarOrient = ToolbarOrient.bottom;
  88.                           tbFind.XCoordinate = tbPlace.RowCol;
  89.                           tbFind.YCoordinate = tbPlace.Order;
  90.                           break;
  91.                         case "L":
  92.                           tbFind.ToolbarVisible = ToolbarVisible.show;
  93.                           tbFind.ToolbarOrient = ToolbarOrient.left;
  94.                           tbFind.YCoordinate = tbPlace.RowCol;
  95.                           tbFind.XCoordinate = tbPlace.Order;
  96.                           break;
  97.                         case "R":
  98.                           tbFind.ToolbarVisible = ToolbarVisible.show;
  99.                           tbFind.ToolbarOrient = ToolbarOrient.right;
  100.                           tbFind.YCoordinate = tbPlace.RowCol;
  101.                           tbFind.XCoordinate = tbPlace.Order;
  102.                           break;
  103.                         case "F":
  104.                           tbFind.ToolbarVisible = ToolbarVisible.show;
  105.                           tbFind.ToolbarOrient = ToolbarOrient.floating;
  106.                           tbFind.XCoordinate = tbPlace.Order;
  107.                           tbFind.YCoordinate = tbPlace.RowCol;
  108.                           break;
  109.                       }
  110.                      
  111.                       WorkspaceToolbar wsToolbar = cuWorkspace.WorkspaceToolbars.FindWorkspaceToolbar(
  112.                         tbFind.ElementID, csPart.MenuGroup.Name);
  113.                       if (wsToolbar == null)
  114.                       {
  115.                         wsToolbar = new WorkspaceToolbar(cuWorkspace, tbFind);
  116.                       }
  117.                       if (wsToolbar.MenuGroup.ToLower().Equals(tbId.CuiName.ToLower()))
  118.                       {
  119.                         switch (tbPlace.Side)
  120.                         {
  121.                           case "T":
  122.                             wsToolbar.Display = 1;
  123.                             wsToolbar.ToolbarOrient = ToolbarOrient.top;
  124.                             wsToolbar.DockRow = tbPlace.RowCol;
  125.                             wsToolbar.DockColumn = tbPlace.Order;
  126.                             wsToolbar.XCoordinate = tbPlace.Order;
  127.                             wsToolbar.YCoordinate = tbPlace.RowCol;
  128.                             break;
  129.                           case "B":
  130.                             wsToolbar.Display = 1;
  131.                             wsToolbar.ToolbarOrient = ToolbarOrient.bottom;
  132.                             wsToolbar.DockRow = tbPlace.RowCol;
  133.                             wsToolbar.DockColumn = tbPlace.Order;
  134.                             wsToolbar.XCoordinate = tbPlace.Order;
  135.                             wsToolbar.YCoordinate = tbPlace.RowCol;
  136.                             break;
  137.                           case "L":
  138.                             wsToolbar.Display = 1;
  139.                             wsToolbar.ToolbarOrient = ToolbarOrient.left;
  140.                             wsToolbar.DockRow = tbPlace.RowCol;
  141.                             wsToolbar.DockColumn = tbPlace.Order;
  142.                             wsToolbar.YCoordinate = tbPlace.Order;
  143.                             wsToolbar.XCoordinate = tbPlace.RowCol;
  144.                             break;
  145.                           case "R":
  146.                             wsToolbar.Display = 1;
  147.                             wsToolbar.ToolbarOrient = ToolbarOrient.right;
  148.                             wsToolbar.DockRow = tbPlace.RowCol;
  149.                             wsToolbar.DockColumn = tbPlace.Order;
  150.                             wsToolbar.YCoordinate = tbPlace.Order;
  151.                             wsToolbar.XCoordinate = tbPlace.RowCol;
  152.                             break;
  153.                           case "F":
  154.                             wsToolbar.Display = 2;
  155.                             wsToolbar.ToolbarOrient = ToolbarOrient.floating;
  156.                             wsToolbar.XCoordinate = tbPlace.Order;
  157.                             wsToolbar.YCoordinate = tbPlace.RowCol;
  158.                             break;
  159.                         }
  160.                       }                          
  161.                     }
  162.                     if (!changedCUIS.ContainsKey(partCuiFName.ToLower()))
  163.                     {
  164.                       changedCUIS.Add(partCuiFName.ToLower(), csPart);
  165.                     }
  166.                   }
  167.                 }
  168.               }
  169.             }
  170.           }
  171.           foreach (CustomizationSection csPart in changedCUIS.Values)
  172.             csPart.Save();
  173.           changedCUIS.Clear();
  174.           if (cuWorkspace.UserModified())
  175.           {
  176.             csMain.Workspaces.SetDefaultWorkspace(cuWorkspace.ElementID);
  177.             bool test = csMain.UpdateWorkspaceComplete();
  178.           }
  179.           csMain.Save();
  180.         }
  181.       }
  182.     }
  183.   }
  184.   return csMain;
  185. }
  186.  

regards Mario