Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CreateViaOffset(CurveLoop original,IList<double> offsetDists,XYZ normal

27 REPLIES 27
SOLVED
Reply
Message 1 of 28
stephen_harrison
3073 Views, 27 Replies

CreateViaOffset(CurveLoop original,IList<double> offsetDists,XYZ normal

I hope someone can help.

I have raised a previous post regarding Generating Views from rooms but feel that has probably run its course.

The problem I now face is how to follow the outer face of the wall were the wall changes thickness over its length and when room separators are utilised.

When the walls step back like image 1 there is an error “Curve loop couldn't be properly trimmed”.

Image1.png

Regarding room separators, the problems occur when the separator is as image 2, Error “Curve loop couldn't be properly trimmed”.

Image2.png

Situations like Images 3 there has been no errors so far!

Image3.png

I am working in c# with Revit 2020 and utilising the following to create the offset:

 

CreateViaOffset(CurveLoop original,IList<double> offsetDists,XYZ normal)

 

IList<double> is the thickness of the surrounding walls and a standard set offset for the room separator.

 

Is this a problem with the API or is there a solution to my problem that I am missing.

Any assistance is much appreciated.

27 REPLIES 27
Message 2 of 28

Please submit a minimal sample model with one single room and the code that exhibits the problematic behaviour so we can see what might be going wrong and possibly pass that on to the development team if more in-depth analysis is required: 

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Thank you!

 



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

Message 3 of 28

Thank you again for your assistance with this Jeremy.

Sample Revit room project and Code that is exhibiting the problems is attached.

You will recognise the code as it is the same code we were working on from an earlier post.

Regards

Stephen

Message 4 of 28

I integrated and cleaned up your code in CropViewToRoom release 2020.0.0.2 for further analysis.

 



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

Message 5 of 28

OK, well, I have not solved it yet, but at least uncovered one definite problem.

 

In the room separator model, the curve loop that you assemble has 11 elements, whereas the wall thickness list only has 10. That obviously causes a problem.

 

I implemented a new method CreateModelCurves that creates a set of model curves to display the curve loop. The result for the room separator model looks like this:

 

Room separator model curve loopRoom separator model curve loop

 

The new code is in the repository:

 

https://github.com/jeremytammik/CropViewToRoom

 

Please do not copy it out as a zip file.

 

Instead, clone the repo to your local file system, apply whatever changes you make, and submit a pull request for me to integrate them back into the repo. That will save unnecessary copying back and forth and manual integration on my side. It also adds useful information tracking of your commits to see what you change and why.

 

I leave it up to you to figure out where that extra segment is coming from, what it represents, and how to deal with the wall thickness for that one.

 

Maybe that will help sort out the other issue as well.

 

I reproduced the exception you mentioned creating the offset loop for the wall thickness model.

 

I'll ask the development team for a usage example of the method to see what we might be doing wrong.

 



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

Message 6 of 28

Here is the question I passed to the development team:

 

I am having trouble using the CreateViaOffset method taking a list of doubles for different offsets:

 

https://www.revitapidocs.com/2020/3097f423-9b0e-5496-bae2-3a82b6875414.htm

 

Can you provide a simple sample showing how to use this method?

 

I tested it passing in five curves representing the following five walls:

 

Rectangular room with five wallsRectangular room with five walls

  

Starting with the bottom horizontal wall and moving counterclockwise to the right, top two and left, I pass in five straight line segment curves and curves and the corresponding five offset distances:
 
5 curves with lengths 9.19,9.51,3.61,5.58,9.51 and 5 thicknesses 1.08,.43,.43,.76,1.08

 

This call throws an `Autodesk.Revit.Exceptions.InvalidOperationException` saying 'Curve loop couldn't be properly trimmed.'

 

 

 

 



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

Message 7 of 28

I received an answer and a solution from the development team.

 

Can you take a look at it in the draft blog post, please?

 

http://jeremytammik.github.io/tbc/a/1807_createviaoffset.html#3

 

Save me copying it here...  Thank you!

 



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

Message 8 of 28

Thank you again for your time and you patience in helping me resolve this issue. It is much appreciated.
I am currently away for a few weeks and not in a position to test out the suggestions outlined within your draft post however, I would make the following comments.
All my tests would suggest that the suspected short vertical were the walls meet is the problem. However, I make the following observations.
I have previously tried a fixed percentage based on the wall thickness instead of +0.1 but received the same error.
I have tried exaggerated the wall thickness difference substantially and still received the same error.

If I have understood the response from the development team correctly the solution they have proposed needs to be placed in a try catch as it may still fail and a therefore a more complex solution is required in this instance ? Is this alternative solution available through the API and if so how may it be implemented?

I have searched the Revit 2020 SDK sample code and unable to find an example utilising the sample code provided is the add-in code they reference available in some other sample code?

I am somewhat confused by the section of code below:

foreach( var curve in contour3D.curves )
  {
    polyCurves.Add( curve.asRevitCurve( 
      doc.Application ) );
  }

How is contour3D obtained and I assume asRevitCurve is an additional Method as I am unable to find any such reference within the SDK Help?

Once again thank you for your patience and assistance.

Regards

Stephen

Message 9 of 28

Dear Stephen,

 

Yes, they suggest using a moderate percentage of the wall thickness, I believe, e.g., 10-20%. I guess that for your needs, 110-120% is required. They also say that they tested it that way, and it worked well, offsetting both inwards and outwards. The sample code that they provided was extracted from some internal Revit module and is thus not present in the SDK nor restricted to using the public API. It just shows an example of using the method, regardless of where the input comes from.

 

I'll try out this percentage thingy on your sample models and see how I fare.

 

I wish you a pleasant time during your absence in the next few weeks.

 

Cheers,

 

Jeremy

  



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

Message 10 of 28

Jeremy I forgot to mention I had chance to examine your latest code up date with the intention of identifying why there are 11 wall elements but only 10 thicknesses but the results I have obtained are as follows: 

normal
11 curves with lengths 10.02,6.04,4.11,5.58,.33,8.69,3.28,.16,3.44,.82,2.46 and
11 thicknesses 1.08,1.08,1.08,.76,.1,.43,.43,.1,.1,.1,1.08
-normal
11 curves with lengths 10.02,6.04,4.11,5.58,.33,8.69,3.28,.16,3.44,.82,2.46 and
11 thicknesses 1.08,1.08,1.08,.76,.1,.43,.43,.1,.1,.1,1.08
 
Regards
Stephen
Message 11 of 28

Oh well how strange that I just saw ten instead of eleven. That prompted me to list those numbers in the debug output.

 

Anyway, I tried to followed the devteam suggestion of using a percentage instead of a fixed additional offset, and it did not work for me at all. I tried both 110%, which would suit your needs, and 10%. In both cases, it still trows the InvalidOperationException saying 'loop couldn't be properly trimmed.'

 

Maybe they tested on a more recent development version of Revit.

 

So, I think it might be time to step away from CreateViaOffset for the time being.

 

On the other hand, your goal is almost reached: you have the room boundary, the boundary element and the thickness, if it is a wall. From those, it is possible to create a curve loop tracing the outsides of the walls.



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

Message 12 of 28

Thank you for all your help Jeremy.

If you could bare with me this one last time?

I started to look at the possibility of tracing the outside of the walls several weeks ago when I was at a loss utilising CreateViaOffset.

I was finding it difficult to create the closed loop necessary, and particularly how I would achieve this were the wall thickness changes across its length.

Could you point me in the right direction, possibly some sample code that I could examine and see if I could get it to work to my requirements.

Hope you have a good festive season.

Message 13 of 28

Sure, no problem. I'll do both: bare with you and bear with you  🙂

 

I see several possible approaches, based on:

 

  • Room boundary curves and wall thicknesses
  • Room boundary curves and wall bottom face edges
  • Projection of 3D union of room and wall solids
  • 2D union of room and wall footprints 

 

The most immediate and pure Revit API approach would be to get the curves representing the room boundaries, determine the wall thicknesses, offset the wall boundary curves outwards by wall thickness plus minimum offset, and ensure that everything is well connected by adding small connecting segments in the gaps where the offset jumps.

 

Several slightly more complex pure Revit API approaches could be designed by using the wall solids instead of just offsetting the room boundary curves based on the wall thickness. For instance, we could query the wall bottom face for its edges, determine and patch together all the bits of edge segments required to go around the outside of the wall instead of the inside.

 

Slightly more complex still, and still pure Revit API: determine the room closed shell solid, unite it with all the wall solids, and make use of the extrusion analyser to project this union vertically onto the XY plane and grab its outside edge.

 

Finally, making use of a minimalistic yet powerful 2D Boolean operation library, perform the projection onto the XY plane first, and unite the room footprint with all its surrounding wall footprints in 2D instead.

 

The two latter approaches are both implemented in my ElementOutline add-in:

 

https://github.com/jeremytammik/ElementOutline

  

I mentioned it here in two previous threads:

  

   

Probably all the pure Revit API approaches will run into various problematic exceptions cases, whereas the 2D Booleans seem very fast, reliable and robust and may well be able to handle all the exceptional cases that can possibly occur, so I would recommend trying that out first.

 

I hope this makes for a nice gift to you in this festive season.

 

Happy advent!

 



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

Message 14 of 28

Published a summary of our results so far:

 

https://thebuildingcoder.typepad.com/blog/2019/12/dashboards-createviaoffset-and-room-outline-algori...

 

Thank you for the interesting explorations so far.

  

I wish I had the time to implement the outer room outline algorithm myself as previously sketched out.

 

I hope you beat me to it, though.

 

Good luck!

 



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

Message 15 of 28

Well, I seem to have beaten you to it after all:

 

https://github.com/jeremytammik/ElementOutline/releases/tag/2020.0.1.2

 

I make use of the 2D Boolean Clipper library.

 

It successfully handles the wall width sample model:

  

wall_width_loop_using_2d_booleans.png

  

It also gracefully handles the room separator situation:

  

room_separator_using_2d_booleans.png

    

Happy New Year!

 

Jeremy

 



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

Message 16 of 28

Jeremy

I hope you had a great seasonal break and a Happy New Year.

Apologies for not responding sooner but this is my first real opportunity to start looking at this again.

To be honest I was still working my way through the suggested ElementOutline add-in code in order to understand exactly how it was working before I attempted the solution.

Thank you so much for the solution?

At least that will all hopefully help my understand how your solution works! 

Your time and patience is much appreciated.

I look forward to implementing this in my final programme. 

Message 17 of 28

Dear Stephen,

 

Happy New Year and welcome back.

 

Thank you for your appreciation.

 

Yes, I believe that this is the most robust and foolproof approach and look forward to seeing how you can make use of it.

 

The ElementOutline add-in obviously only solves the outline part of the task, so it still needs combining with the CropViewToRoom to implement the complete job.

 

Cheers,

 

Jeremy

 



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

Message 18 of 28

Jeremy

Thank you again for your assistance with this.

I have finally had a few moments to try out the solution and all appears to work well, with one exception. The instant doors windows etc are introduced the outline is not as expected.Outline Door Error.pngOutline Window Error2.png

Havent had a chance to explore reasons why and possible solution.

I was expected the introduction of the door or window to included a projection in the same way as the handle on the desk example https://thebuildingcoder.typepad.com/blog/2020/01/extrusion-analyser-and-2d-boolean-element-outline....  however it does appear to do something altogether differant?

 

Regards

Stephen

 

 

Message 19 of 28

Jeremy

I have started to examine the code in relation to first integrating into CropViewToRoom to implement the complete job.

If I understand the code correctly the line

JtLoops loops = Cmd2dBoolean.GetRoomOuterBoundaryLoops(room, seb_opt, view );

loops is the outer loop however I regret I cannot see how this links into

CurveLoop cloop = CurveLoop.CreateViaOffset(loops, offset, normal );

As this returns an error.

I assume JtLoops loops needs converting somehow into a CurveLoop?

Regards

Stephen

Message 20 of 28

Yes, indeed, of course. It is pretty simple. Furthermore, the JtLoop data is in millimetres, and the Revit database stores all lengths in imperial feet, so you will have to multiply the data by 25.4 (to convert mm to inch) times 12 (to convert inch to foot). Or divide by those values, or something.

 



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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community