Announcement

Collapse
No announcement yet.

Revit C# Change Phase Property

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Revit C# Change Phase Property

    Hello, I'm not sure this is the right area to post this or not, but hopefully it is.

    I have spent a good deal searching the web for information on how to change the Phasing property labeled "Phase Created" without success, and have come here in hopes to find an answer.

    The property is available on all elements to my knowledge, and I need to be able to change that property from "New Construction" to "Existing" via C# code. My goal is to feed the program an item from user selection and be able to see what phase that item is currently set to and then change it if needed. Now I already can feed the program an item and view what phase that item is in with the following code:

    Reference RefDemo = uidoc.Selection.PickObject(ObjectType.Element);
    Element eDemo = doc.GetElement(RefDemo.ElementId);
    Autodesk.Revit.DB.Phase phaseCreated = doc.GetElement(eDemo.CreatedPhaseId) as Phase;
    if (phaseCreated.Name != "Existing")
    {
    // Change phase code here...
    }

    I have tested this code and it does work for testing the phase of the item, however I cannot find any support API to change the phase. The only API I can find that makes changes to it is the CreatePhaseId property or its mirror version that destroys the PhaseId. With these I have no way to make changes to what the property is set to other then true or false. The closest I got to get it working was with the following code:

    phaseCreated.Name = "Existing";

    which provided with an error stating that It would not allow user entered variables to change it, which led me to think that there must be a way to access the dropdown options and change the property to an option in that dropdown.

    And this is where I am now stuck.

    If anyone would be able to provide some guidance on how I can programmatically change the Phase Property please comment, If I am posting this in the wrong area or if you know a better place for me to post this question please also let me know.

    In my attempts to get this working I also managed to use this same method to change the Workset property to any given Workset by the text name of that Workset. EX: I want to change a Workset from M_HVAC to M_DEMO, I can do that by entering M_DEMO into the program then select an element to change.

    #2
    You could try using Dynamo.
    Check here:
    Topic: Change Phase Created Value | Dynamo BIM
    Cliff B. Collins
    Registered Architect
    The Lamar Johnson Collaborative Architects, St. Louis, MO
    Autodesk Expert Elite

    Comment


      #3
      Switching to Dynamo would cause a lot of re-work with my code as it is in a different language. The overall program will be doing more then just changing the phase, it is also changing the Workset. I would prefer a C# solution as it would cause a lot less re-work, but a worst case scenario its good to know dynamo may hold the key.

      Comment


        #4
        CreatedPhaseId Property

        var doc = DocumentManager.Instance.CurrentDBDocument;
        Autodesk.Revit.DB.Element elemId = doc.GetElement(element) as Autodesk.Revit.DB.Element;
        ElementOnPhaseStatus elemStat = elemId.GetPhaseStatus'''This is custom to me''''(phaseID);
        string phaseStatus = elemStat.ToString();

        Then IDK if there is a solution after with something like
        elemID = elemID.CreatedPhaseId(phaseId)

        Where phaseId is the Document ID of the Phase you are trying to set it too.

        CreatedPhaseId should be a get; set; You should be able to pass in the PhaseId to the element. Try catch that.
        Last edited by kraftwerk; June 15, 2018, 04:51 PM.

        Comment


          #5
          @Kraftwerk I managed to test the code and ran into a couple problems.
          for
          elemID = elemID.CreatedPhaseId(PhaseId)
          it wont allow me to cast the "CreatedPhaseId" with "()" attached.

          So I ended up testing
          elemID = elemID1.CreatedPhaseId
          to see if that would make a difference, as elemID1 would be another variable that holds the correct phase already.

          That returned an error displaying it could not convert the object from an element to a CreatedPhaseId. So then I attempted this:

          elemID.CreatedPhaseId = elemID1.CreatedPhaseID

          which returned no errors, but also didn't change anything... When I use a string to output the numbers of the phase Id, it simply provides a -1, unless you cast it as an integer, then it outputs 1. So I'm feeling like the CreatedPhaseId may be a dead end..

          Comment

          Related Topics

          Collapse

          Working...
          X