Adding an extrusion

Hi!

I try to add a simple extrusion but I have a crash. Where am I wrong?
Thank you so much
Paolo

ON_3dPoint point1(0., 0., 0.);
ON_3dPoint point2(100., 0., 0.);
ON_3dPoint point3(100., 100., 0.);
ON_3dPoint point4(50., 200., 0.);
ON_3dPoint point5(0., 200., 0.);
ON_3dPointArray pointarray(6);
pointarray.Append(point1);
pointarray.Append(point2);
pointarray.Append(point3);
pointarray.Append(point4);
pointarray.Append(point5);
pointarray.Append(point1);
ON_PolylineCurve poly(pointarray);
CRhinoCurveObject *pcurve = context.m_doc.AddCurveObject(poly); // OK!!

// CRASHES below, poly is a planar closed curve see above

ON_Extrusion extrusion;
if(extrusion.CreateFrom3dCurve(poly, NULL, 1000., TRUE) == NULL)
{
	RhinoMessageBox( _T("Error"), PlugIn()->PlugInName(), MB_OK );
}
context.m_doc.AddExtrusionObject(extrusion);

Hi Paolo,

CreateFrom3dCurve is a static function on ON_Extrusion.

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
  ON_3dPoint pt0(0.0, 0.0, 0.0);
  ON_3dPoint pt1(100.0, 0.0, 0.0);
  ON_3dPoint pt2(100.0, 100.0, 0.0);
  ON_3dPoint pt3(50.0, 200.0, 0.0);
  ON_3dPoint pt4(0.0, 200.0, 0.0);

  ON_3dPointArray points(6);
  points.Append(pt0);
  points.Append(pt1);
  points.Append(pt2);
  points.Append(pt3);
  points.Append(pt4);
  points.Append(pt0);

  ON_PolylineCurve curve(points);
  //CRhinoCurveObject* pCurveObject = context.m_doc.AddCurveObject(curve);
  //context.m_doc.Redraw();

  ON_Extrusion extrusion;
  if (0 == ON_Extrusion::CreateFrom3dCurve(curve, 0, 1000.0, true, &extrusion))
  {
    ON_wString msg = L"Unable to create sample extrusion.\n";
    if (context.IsInteractive())
      RhinoMessageBox(msg, EnglishCommandName(), MB_OK);
    else
      RhinoApp().Print((const wchar_t*)msg);
    return CRhinoCommand::failure;
  }

  context.m_doc.AddExtrusionObject(extrusion);
  context.m_doc.Redraw();

  return CRhinoCommand::success;
}

Hi Dale!
Thank you, it’s Crystal clear.
Two more questions (please excuse me, this can save much time). The matter is: extrusion of more closed polylines into one single 3D solid.

  1. An extrusion having two “outer” closed polylines, (e.g. a cross-section ][ or || double angles, or double channels, typical in structural engineering)

    extrusion.SetOuterProfile(&curve1, TRUE);
    extrusion.SetOuterProfile(&curve2, TRUE); // I guess only first will be kept

Is that possible? I fear not: “If the extrusion already has a profile, the set will fail.”

  1. An extrusion having one “outer” closed polyline and one or more holes (CHS, hollow sections)

    extrusion.SetOuterProfile(&curve1, TRUE);
    extrusion.AddInnerProfile(&curve2);
    extrusion.AddInnerProfile(&curve3);

I am “a glutton for punishment” :smile:
What is it still missing to end extrusion definition (i.e.if I am not using CreateFrom3dCurve)? Extrusion direction and extrusion amount.


More generally, if I see well, the place where to learn this kind of things is “opennurbs_beam.h”? 'Cause I don’t want to disturb placing stupid questions.

So many thanks…
Paolo

Hi Paolo,

See if this example is help for (or not):

https://github.com/mcneel/Rhino5Samples_CPP/blob/master/SampleCommands/cmdSampleExtrusionBox.cpp

– Dale

Hi Dale,

many thanks for your reply. I reply here, so may be this might be helpful for Others in the future.

Your example is useful as I understand that I have to call:

extrusion->SetPathAndUp
extrusion->SetOuterProfile
extrusion->SetDomain

If I call only the first two, as I did, I get a crash adding the object.
However I have still some questions, you can reply quickly to many of them just with YES/NO

  1. Extrusion accepts only 1 outer profile so one single 3d object will be generated if profile is closed
  2. Is profile is closed you may add more than one inner profile (holes).
  3. Path is the extrusion path, from start to end. It must not entirely lay over the curve plane.
  4. Its start point must lay over the bottom plane.
  5. Up is used to set a direction. Why? Isn’t it the path to give the direction of extrusion?
  6. The first parameter of SetDomain is not clear…

I am sorry. May be I missed some document with explanations.
Thank you
Paolo

Yes

Yes

Yes

Yes[quote=“rugarli, post:5, topic:30479”]
5) Up is used to set a direction. Why? Isn’t it the path to give the direction of extrusion?
[/quote]

Yes, and I don’t know.[quote=“rugarli, post:5, topic:30479”]

  1. The first parameter of SetDomain is not clear…
    [/quote]

The first parameter is the direction, either 0 or 1. See ON_Extrusion::PathParameter for details.

Also, there are some great comments in the member variable section of ON_Extrusion (opennurbs_beam.h).

Thank you very much Dale.
Bye
Paolo