Grasshopper

algorithmic modeling for Rhino

Dear Discussion,

Has anyone successfully created a sweep 1 with a vb.net node in GH?  I have tried but get some error " ... Attempted to read or write to protected memory....".  I have taken a look at the vb.net examples on the rhino website but cant seem to understand why it takes a 100 lines of code to extrude a profile along a path, so its hard for me to follow.  I know am not the best coder, but I'm trying.  This is the code I have put together based on others attempts: 

    revised:

   Private Sub RunScript(ByVal rail As OnCurve, ByVal section As OnCurve, ByRef A As Object)

    'create sweep arguments
    Dim args As New MArgsRhinoSweep1

    'create arravy of sections, this is the required format to feed the sweep arguments
    Dim sArray() As OnCurve = {section}

    'create polyedge, this is the required format to feed the sweep arguments
    Dim edge As New MRhinoPolyEdge()
    edge.create(rail.DuplicateCurve())

    'Add rails to sweep arguments
    args.m_rail_curve = edge.Duplicate()
    args.m_bClosed = True

    'Add sections to sweep arguments
    args.m_shape_curves = sArray

    args.m_simplify = 0

    args.m_rebuild_count = -1 'Sample point count for rebuilding shapes
    args.m_refit_tolerance = RMA.Rhino.RhUtil.RhinoApp.ActiveDoc.AbsoluteTolerance()
    args.m_sweep_tolerance = RMA.Rhino.RhUtil.RhinoApp.ActiveDoc.AbsoluteTolerance()
    args.m_angle_tolerance = RMA.Rhino.RhUtil.RhinoApp.ActiveDoc.AngleToleranceRadians()

    Dim sBreps()As OnBrep = Nothing
    Dim Sweep1 As New List(Of OnBrep)
    If (RhUtil.RhinoSweep1(args, sBreps)) Then
      For Each b As OnBrep In sBreps
        Sweep1.Add(b)
      Next
    End If

    A = Sweep1

Views: 1368

Replies to This Discussion

Hi, as a subtle hint, the first thing you could try is calling RhUtil.RhinoSweep1 as it seems to be what you are intending to do.

I haven't tried the rest of it, but if it's still not working, I'm happy to. I have Sweeping working as I need it in dotNET scripting, refer http://geometrygym.blogspot.com

Cheers,

Jon
Doh! How embarrassing. I made the corrections and a few other related to that. As per corrections I have no errors but I have no surface either.

Thank you for your advice. I will take a look at your site.

Will
Well if you still haven't had success, feel free to post your updated code. Might help others in the future that search this thread.
I actually revised the code in the original post when nobody was looking, rather than repost the slightly augmented code.
Is your error message still the same though?

My code is C#, but yours looks pretty similar. Here's a couple of lines I have that might be necessary.

args.set_m_bUsePoints(0, 0);
args.set_m_bUsePoints(1, 0);

but I guess the most obvious explanation for a reference error is probably not setting
args.m_planar_up = new On3dVector(OnUtil.On_zaxis);

(adjust as necessary)

Is your rail curve always closed? as you are forcing that when it could be ested.

Hope this might help.
Jon
Thanks Jon for the help. Still no luck with an actual surface even though GH is not giving me any errors. I uploaded the last .ghx with the node in it if any one would like to give it a shot.

Will
Attachments:
The attached works here, I overlooked you were missing shape curves for the sweep.
Note in this example I've added the curve back to the Rhino document and deleted it after sweeping (which is still in my code from the very first time I tried to program sweep), but I'm about to see if instead you can just add curves to the Shape_curves list in Args.

You'll have to reassign your rail and profile curve as you didn't attach a rhino model.

Cheers,

Jon
Attachments:
I went through your code compared to my code line by line and did notice a big difference was that I assume you added crv's to the document to use them as shape_objrefs as part of the arguments, but as I went down the line and changed my old code to see excactly what was wrong, I noticed this...

I used this: edge.create(rail.DuplicateCurve()) as recommended in this example: http://wiki.mcneel.com/developer/sdksamples/sweep1

but you used this: edge.Append(rail.DuplicateCurve())
... so this was the first line I changed to my old code and BEHOLD it made a sweep surface.

So, please, how did you know to use append instead of create and go against the wisdom of the almighty gods of the developer examples? I assume that sweep2 might use append since there are two rails. I would have never come to this conclusion or variation on my own.

Thank you for your solution.
It was some time ago when I programmed my Sweep1 (when I was first translating my plug-in from RhinoScript to C#), and helping you actually found this inefficiency in my routine for the shape curves.

I'm assuming the edge.Append was in the the RMA Wiki help for Sweep1 as I would have copy/pasted from that, maybe the example changed (or maybe I've changed it some time).

I guess I could have just given you my sweep1 code from the start (albeit in c#) but I think it's better we've both learnt from the question. And don't worry, learning in the SDK is a never ending experience (although it does taper), if you look through the history of the Rhino.Plug-ins newsgroup, you'll find me asking the equivalent question, and those that helped me similar before etc etc. It's the great thing about the Rhino Community is the peer support and the support from McNeel.

Hi Will ,

Are you ready with closed curve ???

Thanks for your reply

Plese read this post :

http://www.grasshopper3d.com/forum/topics/sweep-1-rail?commentId=29...

have you succeded for you code sweep1rail ???

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service