Author Topic: Changing the order of Values for Registry Keys  (Read 9759 times)

0 Members and 1 Guest are viewing this topic.

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Changing the order of Values for Registry Keys
« Reply #15 on: October 21, 2013, 09:47:31 AM »
That does answer my question but I must ask another. Can you not search the catalog using one of your custom fields that you're using to create the box?

We do something similar here but I use PartType, PartSubType, Material, and Custom fields to query the catalog and come back with specific parts for use in my program.  Seems to me, that is a lot easier than moving catalogs around every time you need to query some parts. 

Also, I don't suspect that the catalogs will need to be moved around that much.  I just needed to verify that my catalog was on top.  I could then just ask the user to move it to the top but I figured if I could find a way to do it automatically why not?  And as I mentioned before, it leads to adding a new catalog automatically without user interaction.
 
I must confess that some of this is leading to possibly using the autodesk exchange site to sell AutoCAD MEP Content which is sorely lacking.  You almost always have to create your own stuff which is fine for some of the larger companies but for the smaller ones the resources and knowledge is not always there.  Adding tools like this will make such an endeavor much easier.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Changing the order of Values for Registry Keys
« Reply #16 on: October 21, 2013, 01:52:18 PM »
What about putting all the content you want to use for the application in a separate catalog and then query with CatalogId?  Saving CatalogId as a const string in your application.  Using PartManager can keep you from having to find a DataLookup first and then querying for parts.  Although I do it both ways depending on where I'm going with the data.

Personally I wouldn't develop parts with identical PartIds and then filter them by changing their order in the Catalog listing.  I think you're setting yourself up for failure in the future if Autodesk makes changes to their catalog structure. 

You mentioned "doing it this way is to make the selection of the part as fast and as easy as possible" but parsing the catalog or parsing the registry is going to be the same to the end user as far as perceived time goes.  We list our catalogs in a particular order, this effects the order in which parts are listed in the part selection dialog.  Any application that rearranges this order without putting it back the way it found it would irritate my users.  If you're putting the catalog back the way you found it then you're parsing the registry again and that would make your way slower than just parsing the catalog once.

These are just my opinions from developing MEP applications for last 3 years but there is always more than one way to skin the proverbial cat.
Revit 2019, AMEP 2019 64bit Win 10

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Changing the order of Values for Registry Keys
« Reply #17 on: October 21, 2013, 01:56:21 PM »
Oh, also if you're thinking about publishing this then you have to consider that some users may not have rights to edit the registry and then your application would fail to reorder the list.
Revit 2019, AMEP 2019 64bit Win 10

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Changing the order of Values for Registry Keys
« Reply #18 on: October 21, 2013, 02:12:35 PM »
Here ia an example of what I mentioned above.  I created an application to insert pipe sleeves into the drawing.  This application uses a dialog to let the user select the type of sleeve they would like to use.  The sleeves are in their own Catalog. I used a PartType we would never use FireProtectionInlet and I made the PartSubType=Sleeve.  I then use this query to fill the dialog box combobox with sleeves.

Code - C#: [Select]
  1. private const string SleeveCatalog = "4F72A7FC-4CBE-4C2A-A823-800F9F117EBC";
  2. var catalog = new CatalogManager();
  3. var query = new DataQuery
  4.      {
  5.          Domain = Domain.MultiViewPartComponent,
  6.          CatalogId = SleeveCatalog,
  7.          SubType = "Sleeve"
  8.       };
  9. var sleeves = catalog.GetPartsList(query).DataParts.Cast<DataPartLookup>().ToDictionary(d => d.Guid, d => d.Name);

After the user selects a sleeve from the dialog box I use the PartId guid to query the exact part and insert into the drawing.
Revit 2019, AMEP 2019 64bit Win 10

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Changing the order of Values for Registry Keys
« Reply #19 on: October 21, 2013, 02:51:24 PM »
I am only using a single catalog which is where I could be going wrong.  The catalog has a strong folder naming convention that is something like this  PartType->Manufacturer->Model-> Part.  By having a folder for the part type I am able to logically group the parts and use the folder name as a filtering mechanism.  For instance if I wanted to grab a list of manufacturers from the catalog I have the following method.
 
Code - C#: [Select]
  1.         public static StringCollection GetManufacturersFromCatalogByPath()
  2.         {
  3.             StringCollection manufacturers = new StringCollection();
  4.             IEnumerator partEnumerator = null;
  5.             CatalogManager manager = new CatalogManager();
  6.             DataQuery queryForPartsList = new DataQuery { Domain = Domain.MultiViewPartComponent, CatalogId = manager.CatalogID(Domain.MultiViewPartComponent) };
  7.             DataPartLookupCollection dataParts = manager.GetPartsList(queryForPartsList).DataParts;
  8.             try
  9.             {
  10.                 partEnumerator = dataParts.GetEnumerator();
  11.                 while (partEnumerator.MoveNext())
  12.                 {
  13.                     DataPartLookup current = (DataPartLookup)partEnumerator.Current;
  14.                     try
  15.                     {
  16.                         if (manager.GetRawPartTable(current).BasicTable.Count != 0)
  17.                         {
  18.                             string[] partPath = current.Path.Split(new char[] { '\\' });
  19.                             int length = partPath.Length;
  20.                             string manufacturer = partPath[length - 2];
  21.                             string partName = partPath[length - 1];
  22.                             if ((length > 1) && partName.ToUpper().Contains(manufacturer.ToUpper()) && (!manufacturers.Contains(manufacturer)))
  23.                             {
  24.                                 manufacturers.Add(manufacturer);
  25.                             }
  26.                         }
  27.                     }
  28.                     catch (Autodesk.AutoCAD.Runtime.Exception exception1)
  29.                     {
  30.                     }
  31.                 }
  32.             }
  33.             finally
  34.             {
  35.                 if (partEnumerator is IDisposable)
  36.                 {
  37.                     (partEnumerator as IDisposable).Dispose();
  38.                 }
  39.             }
  40.             return manufacturers;
  41.         }

I guess I need to think about it because I am doing the same thing to get the model and part size information.  I have created a dialog where you first select the manufacturer and then select a model number that is filtered by the manufacturer and then you would select a part size which is filtered based on the model number selected.  So I needed to get a list of manufacturers and then a list of models for each manufacturer and then a list of part sizes for each model and have that be able to be displayed in three dropdown combo boxes.  I didn't want to use a tree structure and chose the previous method instead.  What you have works great where you don't need a lot of information to find the part.
 
Now I am just confused.  Not on the how to do it but on the why to do it a certain way.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Changing the order of Values for Registry Keys
« Reply #20 on: October 21, 2013, 02:56:36 PM »
Can you explain the last line of your code?  Are you taking the DataPartLookup and placing it in a dictionary for easy retrieval?
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Changing the order of Values for Registry Keys
« Reply #21 on: October 21, 2013, 03:28:29 PM »
Can you explain the last line of your code?  Are you taking the DataPartLookup and placing it in a dictionary for easy retrieval?

I'm converting the DataPartLookup to a Dictionary<string, string>. The dictionary has the PartId guid as the key and the Part Name as the value.  I'm using this Dictionary<string, string> to Databind to a ComboBox in my WPF dialog box that only shows the value(Name).  Its a little more compicated than that since Sleeves is a property in a MVVM ViewModel.  My ViewModel returns the selected KeyValuePair<string, string> which gives me the PartId guid as the key which I can use to do further part lookups.  Hope that doesn't confuse you more.
Revit 2019, AMEP 2019 64bit Win 10

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Changing the order of Values for Registry Keys
« Reply #22 on: October 21, 2013, 03:37:41 PM »
Have you looked at the CatalogExplorer example in MEP//Sample//CS.NET?  That may help you too.  Without knowing more details of what you're trying to do. It seems like you might be trying to re-invent the wheel when the default parts dialog does the same thing.
Revit 2019, AMEP 2019 64bit Win 10