Reading the Size Value of Pipe Component using .NET C# in AutoCAD Plant 3D - Stack Overflow

admin2025-04-17  2

I am trying to create a custom command in AutoCAD Plant 3D. The purpose of this command is to fetch all the available sizes of any selected component and use them to populate the Size Property so that when I choose any of the Size from the dropdown, the component redraws itself matching the new size instead of me deleting the old component and placing a new in its place. Please take a look at the following pictures;

  1. Image-1: Component in the Catalog showing all the available Sizes
  2. Image-2: Component is Specs Sheet with all sizes
  3. Image-3: Component in Modelspace showing only active size in the Dropdown

I understand that I need to query the Specs Sheet and get all the Size values of the selected component in a String Array or List and then iterate through it and assign values to the Size property as shown in Image-3 above. But I am unable to create the required code snippet for that. I am able to fetch all the size values of the Specs Sheet itself but that is of no help to me because Sizes of Specs Sheet means ALL AVAILABLE size. For example Component A has 50, 100, 200, 300 and Component B has 50, 150, 250 then the Size of Specs Sheet would return 50, 100, 150, 200, 250, 300 which is not what I require. I need to fetch only the sizes of Component A. The code that I have used to fetch specs sizes is like this;

[CommandMethod("GetPipeSizes")]
public void GetPipeSizes()
{
  // get the AutoCAD Editor object so we can print to the command line
  Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
  PromptResult res = ed.GetString("\nEnter Pipe Spec");
  if (res.Status == PromptStatus.OK)
  {
    // get the UISettings object (found in Pnp3dMain.dll)
    Autodesk.ProcessPower.P3dUI.UISettings settings = new Autodesk.ProcessPower.P3dUI.UISettings();
    // now get all the sizes that are available for that spec
    StringCollection sizes = settings.GetAllSizesFromSpecName(res.StringResult);
    foreach (string size in sizes)
    {
      ed.WriteMessage("\nSize " + size);
    }
  }
}

Any help would be highly appreciated.

转载请注明原文地址:http://anycun.com/QandA/1744824139a88122.html