Author Topic: Issues with creating regions from CreateFromCurves  (Read 183 times)

0 Members and 1 Guest are viewing this topic.

pjm8765

  • Newt
  • Posts: 22
Issues with creating regions from CreateFromCurves
« on: July 13, 2017, 05:29:51 am »
Another novice question.  I'm getting an error at odd times when a call to Region.CreateFromCurves is made with an object collection of lines.  The error is eInvalidInput and given that this routine is intended to process closed loops I am guessing that the input it is receiving does not consititute a closed loop.

Does anyone have a routine that can validate the contents of the DBobjectCollection to make sure it is closed?

MexicanCustard

  • Swamp Rat
  • Posts: 675
Re: Issues with creating regions from CreateFromCurves
« Reply #1 on: July 13, 2017, 09:11:47 am »
If the collection is always lines. You could create a Polyline using all the end points of the lines and then check the Polyline's IsClosed property. That's just a guess without any testing.

You could wrap the Region.CreateFromCurves call in a try/catch and assume on exception that it is not closed and process accordingly.
Revit 2018, AMEP 2018 64bit Win 10

pjm8765

  • Newt
  • Posts: 22
Re: Issues with creating regions from CreateFromCurves
« Reply #2 on: July 13, 2017, 11:34:52 am »
Uhmm, food for thought, thanks.  I'll let you know how I work this one out.

There is a line of code, later on that pulls the region created out of the block (it's horribly inefficient, I know) and I've added an isnothing() check to make sure the region exists before continuing.  It'll do for now.  This error is only happening rarely, so I'm not going to go berserk trying to find the solution, but would rather be pro-active than reactive in handling a problem.

Atook

  • Swamp Rat
  • Posts: 841
Re: Issues with creating regions from CreateFromCurves
« Reply #3 on: July 13, 2017, 04:00:39 pm »
I ran into a similar problem converting polylines to regions, and some polylines wouldn't work even if they were closed. RonJonP brought up that I might have to run the 'overkill' command manually on those problem polylines to remove self intersections or something along those lines. That seemed to solve the problem.

I currently check for a closed polyline before creating a region, and check for null immediately after creating the region, but haven't figured out a good way to check for some of the more complex eInvalidInput errors programatically.

I'd also like to see what any of you have come up with to sanitize the input for Region.CreateFromCurves.