Filled Region

Filled Region

Anonymous
Not applicable
3,252 Views
8 Replies
Message 1 of 9

Filled Region

Anonymous
Not applicable

I've deleted a line style which is in a filled region.  The filled region now apears to be missing the lines, however the lines are set to thin.  If I edit the boundary of the filled region and close it the appear.  

 

Is is possible to "Edit Boundary" of a filled region through the API? 

0 Likes
Accepted solutions (2)
3,253 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

Dear Danny, 

 

Same answer as here:

 

http://forums.autodesk.com/t5/revit-api/group-array-versus-array-of-group/m-p/5792465

 

I hope this helps.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 9

Anonymous
Not applicable
Accepted solution

I was able to get the lines back by moving the fill region and then moving it back.  The filled region needed to be regeneratated to show the lines again. 

 

Thank you for your help.  🙂 

 

        public void editFilledRegion(Document doc, UIDocument uidoc)
        {
            FilteredElementCollector fillRegionTypes = new FilteredElementCollector(doc).OfClass(typeof(FilledRegion));
            FilteredElementIterator itr = fillRegionTypes.GetElementIterator();
            while (itr.MoveNext())
            {
                Element element = (Element)itr.Current;
                FilledRegion filledRegion = doc.GetElement(element.Id) as FilledRegion;

                Transaction tx = new Transaction(doc);
                tx.Start("move");
                XYZ xyznew = new XYZ(1,0,0);
                XYZ xyzOld = new XYZ(-1,0,0);
                ElementTransformUtils.MoveElement(doc, filledRegion.Id, xyznew);
                ElementTransformUtils.MoveElement(doc, filledRegion.Id, xyzOld);
                tx.Commit();
            }
        }
0 Likes
Message 4 of 9

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Danny,

 

Congratulations on solving this and thank you for your appreciation and sharing your solution.

 

That looks viable to me. I discussed this technique in the past:

 

http://thebuildingcoder.typepad.com/blog/2011/07/refresh-element-graphics-display.html

 

As explained there, it might be safer if you move the region by a smaller amount than a full foot.

 

I have several other best practivce coding enhancements to suggest, if you don't mind:

 

  • Using foreach instead of an explicit iterator saves you a lot of typing.
  • The best way to handle transactions is to encapsulate them in a 'using' statement.
  • You can encapsulate all your calls to MoveElement in one single transaction, instead of opening a new one for each call.
  • You can use the static XYZ.BasisX member instead of explicitly instantiating your own X unit vector.

 

Regarding the using statement, please refer to 

 

http://thebuildingcoder.typepad.com/blog/2012/04/using-using-automagically-disposes-and-rolls-back.h...

 

That discussion was followed by many more posts on handling transactions and transaction groups.

 

The resultting code looks like this:

 

  public void EditFilledRegion( Document doc )
  {
    FilteredElementCollector fillRegions 
      = new FilteredElementCollector( doc )
        .OfClass( typeof( FilledRegion ) );

    using( Transaction tx = new Transaction( doc ) )
    {
      tx.Start( "Move all Filled Regions" );

      foreach( FilledRegion filledRegion in fillRegions )
      {
        XYZ v = XYZ.BasisX;
        ElementTransformUtils.MoveElement( doc, filledRegion.Id, v );
        ElementTransformUtils.MoveElement( doc, filledRegion.Id, -v );
      }
      tx.Commit();
    }
  }

Once you see it like that, it also becomes obvious that it would be more effective to move all the regions at once using the MoveElements method, instead of one by one, leading to this:

 

  public void EditFilledRegion( Document doc )
  {
    ICollection<ElementId> fillRegionIds
      = new FilteredElementCollector( doc )
        .OfClass( typeof( FilledRegion ) )
        .ToElementIds();

    using( Transaction tx = new Transaction( doc ) )
    {
      tx.Start( "Move all Filled Regions" );

      XYZ v = XYZ.BasisX;
      ElementTransformUtils.MoveElements( doc, fillRegionIds, v );
      ElementTransformUtils.MoveElements( doc, fillRegionIds, -v );

      tx.Commit();
    }
  }

Would you like to try that out?

 

And reduce the offset a bit, e.g by using something like

 

XYZ v = 0.01 * XYZ.BasisX;

Thank you!

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 9

jeremytammik
Autodesk
Autodesk

In order to compare these steps better, I added them to The Building Coder samples.

 

Here are the diffs:

 

https://github.com/jeremytammik/the_building_coder_samples/compare/2016.0.120.10...2016.0.120.11

 

https://github.com/jeremytammik/the_building_coder_samples/compare/2016.0.120.11...2016.0.120.12

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 6 of 9

Revitalizer
Advisor
Advisor

Hi Jeremy,

 

since a FilledRegion is view depending, it may be that it resides in a section or elevation view.

In this case, the moving vector must not be XYZ.BasisX since it may be that the FilledRegion would be moved out of the view's plane.

Which would result in an error.

 

What about view.RightDirection ?

 

 

Rudi




Rudolf Honke
Software Developer
Mensch und Maschine





Message 7 of 9

Anonymous
Not applicable

Jeremy,

I got it to work. I had to check the elements one at a time because in the project some elements had been pinned. I unpinned them and then repined them back. I also changed it to move along the Z axis. A comment made by a user had mentioned that it might move off the screen causing some problems. Moving it in the Z axis work enough to refresh the filled region even in a drafting view.

I’m CS student working in architecture and can use all the guidance, with that said I made the changes to my code and it runs nicely. I’ve also been reading and following “The Building Coder” and have found it very helpful. The many examples have helped me understand how Revit’s API works. It’s a very useful and great resource.

Thank you.

Danny.

0 Likes
Message 8 of 9

jeremytammik
Autodesk
Autodesk

Hi Revitalizer,

 

Yes, ensuring that it stays in the correct plane definitely makes sense.

 

Thank you for noticing and pointing that out!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 9

jeremytammik
Autodesk
Autodesk

Dear Danny,

 

Congratulations on getting it to work!

 

Thank you very much for your appreciation for The Building Coder.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes