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: 

Hermite,Nurbs Spline Do they need to be on a plane?

13 REPLIES 13
Reply
Message 1 of 14
Anonymous
1714 Views, 13 Replies

Hermite,Nurbs Spline Do they need to be on a plane?

Hi,


do both Hermite and Nurb Spline need to be created on a plane? Is there any way around this. I will like to avoid using CurveByPoints as I do no achieve the result I am after.

 

Thanks in advance

Tags (1)
13 REPLIES 13
Message 2 of 14
Anonymous
in reply to: Anonymous

I find it very weird because if I create a Surface out of Nurbs I can edit the profiles in any form or direction... 

Message 3 of 14
jeremytammik
in reply to: Anonymous

Dear Miruoz,

 

Can you please provide a minimal reproducible case that I can pass on to the development team to analyse?

 

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

 

Thank you!

 

Cheers,

 

Jeremy



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

Message 4 of 14
Anonymous
in reply to: jeremytammik

Hi Jeremy,

 

Let me know if this is sufficient to make my point.

 

  • An short exact description of what you are trying to achieve.

I want to create a loft from two nurb splines that are not planar. By non-planar I mean that not all the control points lie on the same plane.

 

What I have realised is that this should be possible as in Revit you can create a loft from two nurbs and later once the loft is created you can modify the nurbs' control points to any location that you want.

What I am after

 

  • The behaviour you observe versus what you expect, and why this is a problem.

I cannot create a loft surface as I expect through the API as the ModelCurve method requires a sketchplane, forcing the nurbs to have all of its control points on the same plane.

 

  • A complete yet minimal macro embedded in the sample model or Visual Studio solution with add-in manifest that can be compiled, loaded, run and debugged with a single click to analyse its behaviour live in the sample model.

I've attached a Visual Studio project with a simple example. I've coded it from the top of my head (sorry I havn't tested it) but it should be more than sufficient to make my point.

 

As a conclusion I can think of the following:

1.- The loft could be done in a different way with a different method and I am doing it wrong.

2.- The only way around this would be to modify the control points after the creation of the loft

 

Thank you for your help,

 

All the best,

Miguel

Tags (2)
Message 5 of 14
jeremytammik
in reply to: Anonymous

Dear Miguel,

 

Thank you for your query and clear sample material.

 

I passed it on to the development team to ask them waht to do about it.

 

I hope this helps.

 

Best regards,

 

Jeremy



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

Message 6 of 14
jeremytammik
in reply to: Anonymous

Dear Miguel,

 

Thank you for your patience.

 

The development team respond:

 

You can use the following code to create non-planar curves and loft:

 

 

  // Create an S shape with control points and weights
  List<CurveLoop> cls = new List<CurveLoop>();
  IList<XYZ> bottomControlPoints = new List<XYZ> { new XYZ(100, 100, 0), new XYZ(50, 100, 0), new XYZ(50, 50, 0),
      new XYZ(100, 50, 0), new XYZ(100, 0, 0), new XYZ(50, 0, 0) };
  IList<double> weights = new List<double> { 1, 1, 1, 1, 1, 1 };
  Curve bottomCurve = NurbSpline.CreateCurve(bottomControlPoints, weights);
  
  // Z coordinate is varied for the top curve
  IList<XYZ> topControlPoints = new List<XYZ> { new XYZ(100, 100, 10), new XYZ(50, 100, 20), new XYZ(50, 50, 30),
      new XYZ(100, 50, 40), new XYZ(100, 0, 50), new XYZ(50, 0, 60) };
  Curve topCurve = NurbSpline.CreateCurve(topControlPoints, weights);
  
  CurveLoop bottomLoop = new CurveLoop();
  CurveLoop topLoop = new CurveLoop();
  bottomLoop.Append(bottomCurve);
  topLoop.Append(topCurve);
  cls.Add(bottomLoop);
  cls.Add(topLoop);
  
  SolidOptions options = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId);
  Solid mySolid = GeometryCreationUtilities.CreateLoftGeometry(cls, options);
  Assert.IsNotNull(mySolid);

 

Here is a DirectShape generated from the resulting solid:

 

non_planar_curve_DirectShape.png

 

 

 

I hope this answers many of your questions.

 

Some further discussion ensued, which may or may not be relevant:

 

[Q] The user calls NewLoftForm, whereas the sample code calls CreateLoftGeometry.

 

NewLoftForm might use different criteria than CreateLoftGeometry, or maybe it decides to use a different form creation method than the one you used, and that fails.

 

User:

 

  var modelcurve = doc.FamilyCreate.NewLoftForm(true, profiles);

 

Sample code:

 

  Solid mySolid = GeometryCreationUtilities.CreateLoftGeometry(cls, options);

[A] I think the user is calling outdated (obsolete) methods for curve creation and loft. We should point out latest methods. One of his questions was how to create a non-planar Nurbs curve. Now we have better API methods to do that. My sample code has an example.

More feedback on the user's questions.

 

[Q] how can i programmatically create a non-planar hermite or nurb spline, please?

 

[A] Please see the functions in APIGeometryNurbSpline.h, e.g.,

 

 

  static Autodesk::Revit::DB::Curve ^CreateCurve(
    System::Collections::Generic::IList<Autodesk::Revit::DB::XYZ ^> ^controlPoints,
    System::Collections::Generic::IList<double> ^weights);

[Q] Do both Hermite and Nurb Spline need to be created on a plane? Is there any way around this?

 

[A] No, the Hermite and NurbSpline curves can be non-planar. Please see the answer to previous question.

 

Note that surface created by lofting may not be a Nurbs surface and we may not provide API functions for editing the surface.

 

[Q1] The loft could be done in a different way with a different method and I am doing it wrong.

 

[A1] Yes, the curves and the loft can be created using different API methods. Please see the example.

 

[Q2] The only way around this would be to modify the control points after the creation of the loft.

 

[A2] As noted above, the workaround is not needed and the proposed workaround will not be possible.

 

I hope this helps.

 

Please let us know whether this works for you and how you end up using it.

 

Thank you!

 

Best regards,

 

Jeremy



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

Message 7 of 14
Anonymous
in reply to: jeremytammik

Thank you very much for the reply.

 

As promised it works as expected except a tiny but important aspect. If I create the surface via a DirectShape I cannot edit it after the creating and this is something I would like to do.

 

Is there any other method to achieve this?

 

Best,

Miguel

Message 8 of 14
jeremytammik
in reply to: Anonymous

Checking with devteam... hang on...



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

Message 9 of 14
Anonymous
in reply to: jeremytammik

@jeremytammik any updates?

Message 10 of 14
jeremytammik
in reply to: Anonymous

Dear Miguel,

 

Thank you for your perseverance and prompting.

 

Yes, in fact, I do have an update.

 

This issue led to quite a discussion with the development team.

 

Here is a summary:

 

There is a FreeFormElement in the API that allows you to create an element with one Solid that is referenceable, and, I believe, editable.  I am not sure whether this element is being actively maintained, but it does exist.

 

Note also the original comment – a DirectShape is for creating non-UI-editable geometry (at least, non-editable by standard means – anyone can create their own mechanisms, of course). The person who implemented it has since by someone that has left the company. There is some overlap between FreeFormElement vs. DirectShape vs. ImportInstance.

 

To repeat what we showed in the initial answer:

 

  1. Create curves including non-planar spline curves using NurbSpline.CreateCurve and put them in a curve loop.
  2. Use the API function GeometryCreationUtilities.CreateLoftGeometry to create a “Solid” geometry.
  3. Create a DirectShape element using the “solid” geometry created above.
  4. As mentioned, the DirectShape element does not provide tools to edit the geometry it holds.

 

The user had tried the following approach:

 

  1. Create profile curves over sketch plane. It is not clear if non-planar curves are possible.
  2. Use doc.FamilyCreate.NewLoftForm(true, profiles) to create a family element containing the geometry.
  3. I don’t know if the family element will provide tools to edit the geometry the way the user wants.

 

The NewLoftForm approach will definitely give an editable family.

 

Q: Are the input curves passed to this function restricted only to a single plane NURBS?    I am not sure.

 

A: Any smooth, continuous curve should be acceptable as a path.  It is not limited to NURBS or 2D.

 

However, I am pretty sure that we enforce the rule that the profile curves do need to be in a plane.

 

Moreover, that plane should be perpendicular to the tangent of the path at the point where the plane intersects the path.

 

One point that’s been overlooked is the question of whether NewLoftForm chose the “wrong” geometry creation method. For example, instead of deciding to create a “loft” (as CreateLoftGeometry would do), maybe it decided to create a sweep, and the sweep failed for reasons such as those you mentioned.

 

Another question that wasn’t answered is why the user’s code even reached the call to NewLoftForm. His code tries to create spline curves for the call to NewLoftForm that have some zero weights and some non-zero weights, and that should result in an exception being thrown.

 

Hang on, I misunderstood the problem.  Forget what I said about ‘path’.  Path does not apply for loft.

 

The loft code should be able to handle pretty much any kind of curve loop for its profiles.  They don’t need to be planar, they don’t need to closed.  It should only fail if the resulting geometry becomes self-intersecting.

 

On the question about choosing the wrong geometry:  If you call ‘NewLoftForm’ there is no guessing about user intent; the result should always be a loft.

 

As to why we get no exceptions when the user creates splines with zero weight.  We had this conversation a couple of years ago.  As I recall it came up because we have several ways of creating these, and not all of them checked for zero weight, or something like that.

 

If we want final answers to these questions, we need to assigned it as a task to someone. Email threads are not good for getting to the bottom of such details.

 

As you can see, we have no final answer yet.

 

I hope this helps anyway.

 

Can you please digest the above, revise your sample add-in code accordingly, if there is anything to change or improve, and update this case again for me to file an issue with the development team to explore further?

 

As always, please ensure that you raise a really totally clear and unequivocal question or problem, so that it is absolutely clear what your need is and in what way it is currently not satisfied, and submit the reproducible case:

 

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

 

I know that you already did.

 

I just have to shorten the discussion thread that we have accumulated so far down to something really short and to the point.

 

It is best if you help me reformulate everything from scratch, so that the question is short and simple and to the point, so I don't have to sift through the entire previous discussion to pick out the important points.

 

Thank you!

 

Best regards,

 

Jeremy



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

Message 11 of 14
Anonymous
in reply to: jeremytammik

@jeremytammik,

thanks for the answer.

What I want to achieve:

I want to create a Nurbs Surface that is editable in Revit after the creation.

 

Issue:

NewLoftForm does the job except you cannot create ModelCurves that are non planar as they require a SketchPlane to be created.

 

 

From the documentation: public ModelCurve NewModelCurve(Curve geometryCurve, SketchPlane sketchPlane)

-----

To summarise there are two ways to create a nurbs surface:

1.- NewLoftForm:

Advantages: Editable after creating

Disadvantage: Cannot be created from non planar Nurbs. (Once created the curves can be modified to be non planar so the problem is not with the NewLoftForm method but with the NewModelCurve method. It requires a SketchPlane). 

 

From the ModelCurve: ModelArc,ModelEllipse,ModelLine make sense that they require a SketchPlane

for ModelHermiteSplilne and ModelNurbSpline this does not make sense as it limits the kind of ModelCurves than can be created.

 

2.- DirectShape:

Advantages: Can create any kind of NurbsSurface because the inputs do not require ModelCurves.

Distadvantages: I cannot edit them after they are created.

 

Ideal Solutions

I see three possible solutions:

1.- That NewModelCurve has an option for Nurbs and Hermite Splines to be non planar.

2.- Make the Directshape editable

3.- Make a Method within Directshape that could convert the DirectShape to a Form (probably not ideal)

 

Option 1 would be preferable as I know that LoftForm once created can have nonplanar Nurbs.

 

Hope this clarifies things,

Best,

Miguel

Message 12 of 14

Hello Jeremy,

 

I am trying to use GeometryCreationUtilities.CreateLoftGeometry in order to generate a doubly curved solid, and found your interesting sample.

You state in Point 3 that:

"3. Create a DirectShape element using the “solid” geometry created above."

WHere can I find code which shows how to do that?

Regards, Dirk

Message 13 of 14

Dear Dirk,

 

Everything I know about direct shapes is documented in the corresponding topic group:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.50

 

Cheers,

 

Jeremy



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

Message 14 of 14

Hallo Jeremy,

thanks I got the answer from the following link:

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2016/ENU/Revit-API/files/GUID-...

 

You just have to package the solid in a GeometryObject Array, then DirectShape.CreateElement works.

Regards, Dirk

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

Post to forums  

Forma Design Contest


Rail Community