-1

It closed my original question. Fairly new to c# & I'm wondering if there is a way to do the following:

string joint = "Press Joint" || "ProPress"; 

Would I achieve this using a switch statement? I.e. set the string to be empty & programmatically pull a value & switch the case depending on the value? I've created an updater utility to check the models in Revit to enforce minimum pipe length standards. The code is pretty lengthy but hopefully what I pulled out makes sense.

    internal class UtilsFabricationPipeLengths
{
    public static FailureDefinitionId illegalPipeLengthFailureId;
    public static FailureDefinitionId illegalPipeLengthFailureId2;
    public static FailureDefinitionId illegalPipeLengthFailureId3;
   // public static FailureDefinitionId illegalPipeLengthFailureId4;
    public static FailureDefinitionId illegalPipeLengthFailureId5;
    public static FailureDefinitionId illegalPipeLengthFailureId6;
    public static FailureDefinitionId illegalPipeLengthFailureId7;
    public class FabricationPipeLengthsUpdater : IUpdater
    {
        private readonly UpdaterId fabricationPipeLengthsUpdaterId;
        private FabricationDimensionDefinition fabricationDimensionDefinition;
        public FabricationPipeLengthsUpdater(AddInId id)
        {
            fabricationPipeLengthsUpdaterId = new UpdaterId(id, new Guid("B0C85739-93DB-44A6-BC74-92280998063E"));
        }
        public void Execute(UpdaterData data)
        {
            try
            {
                {
                    string brazed = "Brazed";
                    string pressJoint = "Press Joint";
                    string soldered = "Soldered";
                    string threaded = "Threaded";
                    string buttWeld = "ButtWeld";
                    string pexJoint = "Pex Joint"; 

                    Document doc = data.GetDocument();
                    List<ElementId> ids = new List<ElementId>();
                    ids.AddRange(data.GetAddedElementIds());
                    ids.AddRange(data.GetModifiedElementIds());
                    foreach (ElementId id in ids)
                    {
                        if (doc.GetElement(id) is FabricationPart fabricationPart)
                        {
                            Autodesk.Revit.DB.Parameter lLength = fabricationPart.LookupParameter("Length");
                            lLength.AsDouble().ToString();
                            Autodesk.Revit.DB.Parameter fpdsd = fabricationPart.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH);
                            fpdsd.AsDouble().ToString();

                            //Don't execute if the change was not trigerred by the wanted parameter
                            if (!data.IsChangeTriggered(id, Element.GetChangeTypeParameter(new ElementId(BuiltInParameter.FABRICATION_PART_LENGTH))))
                            {
                                break;
                            }
                            if (!fabricationPart.IsValidObject)
                                continue; 
#region Press To Existing Soldered
if ( fabricationPart.ProductInstallType == pressJoint &&
                                                            (decimal)lLength.AsDouble() < 0.2239583333m &&
                            fabricationPart.ProductSizeDescription == "1-1/4" ||
                                                            fabricationPart.ProductInstallType == pressJoint &&
                                                            (decimal)lLength.AsDouble() < 0.2812500000m &&
                            fabricationPart.ProductSizeDescription == "1-1/2" ||
                                                            fabricationPart.ProductInstallType == pressJoint &&
                                                            (decimal)lLength.AsDouble() < 0.3229166667m &&
                            fabricationPart.ProductSizeDescription == "2")
#endregion
else
                            {
                                continue;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
    public UpdaterId GetUpdaterId()
        {
            UpdaterId id = fabricationPipeLengthsUpdaterId;
            return (id);
        }
        public ChangePriority GetChangePriority()
        {
            return ChangePriority.MEPSystems;

        }
        public  string GetUpdaterName()
        {
            return "Fabrication Pipe Updater";
        }
        public string GetAdditionalInformation()
        {
            return "Fabrication Pipe updater example: checks the lenghts of pipe to make sure " +
                "all pipes meet minimum pipe length requirements.";
        }
    }
}

The string value pressJoint can vary with what is being checked between "Press Joint", "ProPress", & "PressFit".

nhilson
  • 25
  • 8
  • 2
    _"Would I achieve this"_ - what is "this"? It's absolutely unclear to me, what you are trying to do. – Fildor Jun 15 '23 at 15:54
  • 1
    The original question was closed for a reason (I didn't see what that was before you deleted it, but I imagine it was that it needs details or clarity). Your new question doesn't address the issues with the orignal, so expect this one to be closed, too, unless you address those issues. Start by reviewing the guidelines for providing a [mre] because you have a lot of code likely has nothing to do with what you're trying to do. – madreflection Jun 15 '23 at 15:58
  • I'm not sure what you are trying to do, but it _seems_ you might want to look up what you can do with `enum`. – oerkelens Jun 15 '23 at 16:01
  • This is code I've already written & found that the value of the parameter "ProductInstallType" has changed with the updated ITM's from our building data content supplier to be one of the three types of press joints (technically all the same from a piping standpoint). I was checking to see if there was a quick way to index the values without changing too much. @John Lord is headed in the direction I'm thinking will need to be done. I was first thinking of setting the value to be empty, pull and set the value foreach, & iterate through each instance. Just brainstorming ideas. – nhilson Jun 15 '23 at 17:37

2 Answers2

3

No. A string is one value. If you want to test whether a string is something or something else - or one of some set of options, then:

  1. for constant strings, you can use if (value is "abc" or "def") {...}
  2. otherwise, create some kind of collection (perhaps a HashSet<string>) and use if (options.Contains(value)) {...}
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
2

You appear to want to be able to store two values in the same variable. You don't want a string for that. I would suggest you use a List()

List<string> joints = new List<string>();

Then to add to the list,

joints.Add("Press Joint");
joints.Add("ProPress");

To check for a match,

if (joints.Contains(brazed)
{ 
   //do something 
}

I hope this helps.

John Lord
  • 1,941
  • 12
  • 27
  • It does actually. Would I be able to iterate through the list instead of checking for one specific value? Something like if ( fabricationPart.ProductInstallType.Contains(joints)) {//do something} – nhilson Jun 15 '23 at 17:52
  • you just need to reverse that. if (joints.Contains fabricationPart.ProductInstallType) – John Lord Jun 15 '23 at 18:04