Grasshopper

algorithmic modeling for Rhino

I have been scouring the internet for at least a month now looking for ways for grasshopper to bake objects as instances of a block.  I have found some solutions such as plug-ins, but all require the block to exist in Rhino, then modified and re-baked.  However I came across one person who was able to make a C# script to do exactly what I am trying to do... kind of...  

http://www.grasshopper3d.com/forum/topics/bake-as-block-c-script-help

I am not exactly proficient with C#, so I was hoping there was someone out there who can help me modify what was done in the linked thread.

Basically what I am trying to do it have an input of lets say 3 crvs (Rectangle, and two diagonal lines making an X through it), and there are 100 variations of them, 1000 total items.  I have them grouped (so the 3 associated crvs are together) and then sorted into branches (each group in an independent branch).  How do I bake all 1000 groups, with only 100 blocks as instances of themselves.

This isnt the end goal, and is a made-up situation, but it is the basics of what im trying to do and a lot easier than trying to explain the entire script I already have :-p

Any help is appreciated! 

Views: 4656

Replies to This Discussion

Hi Ryan,

I'll post in a few days a collection of scripts that do that both ways for a WIP tower project that I'm working (that includes complex and simple geometry, meaning nested blocks plus tests via STEP 214 in order to properly feed assembly/component driven CAD apps [like CATIA,NX,AECOSim etc]):

(a) get a Rhino block and place it around.

(b) bake as block GH generated geometry and then place it around.

In pretty much all the cases the PlaneToPlane transformation is used. 

In the mean time (for the "modify" part that you asked) post your def here.

best, Peter

As I mentioned previously, I am basing almost all of my c# script off the post I linked.  Here is what I have so far... The file has 2 parts to it.  The top part is what I have so far and it works great (although not want I want in the end)  The lower part has the data inputs that I want the end result to look like.  

Basically the difference is instead of the input geometries being sorted in grasshopper and then input into the C# component as Crvs and a Basepoint, I want to input all the geometries in the block as one, and the c# script sort the crvs and Basepoint.

Also, I would like to have (in this example) 2 blocks being created (each in their own tree branch) and then create a variable number of instances.  

Any help or further examples would be appreciated! 

Attachments:

Hey Peter, 

If you are able to I would really appreciate it if you can help me with my C# code to get closer to the end goal.  I have been able to progress it further by myself, but I think I have gotten as far as I can by myself.   

Thank you in advance!

Whilst the promised bakeAsBlocks <> useBlocks examples/scripts are delayed (a "bit", he he): blame Karma and some motorcycle repair that I must finish ... I'll look at your def ASAP. 

OK, that is simple: I'll do it in 2 C# scripts n order to allow more flexibility (separate the creation of things with the usage of things, as the Engineering classic mentality dictates):

1. The first (that's very simple, mind) gets stuff (geometry) and makes instance definitions. NOTE: for more than obvious reasons it is strongly advised to create the geometry always with regards some "global" origin point (Point3d(0,0,0) in plain English) - plane could be different mind [case: "flat" geometries]. This policy allows to build easily managed collections of "components" for other cases blah blah (not apparent for this case, mind, but wait for the quite complex examples promised dealing with nested ultra paranoid "assembly/component" things and the likes).

2. The second (that's NOT that simple, mind : since it can act as standalone using things stored as instance definitions [blocks] in any given Rhino file) gathers placement data and puts instances (via PlaneToPlane trans as usual) where required (does some other things as well, he he). Obviously all instances are sampled in DataTrees that match 1:1 with the placement data structure (your Points in this occasion).

more ASAP

OK, get the V1 (rather a tech preview than a complete solution on that matter) - attributes/nesting capability not added not to mention a myriad of other things that cross my mind.

Note: The Info panel (placement C# thingy) informs you about things. If you use the 2nd C# as a standalone ... it works IF blocks are found in the Active document... if not > Adios Amigos.

Note: After placing the cookies ... change the ptsTree > for this type of primitive (simple) geometry GH can keep-up live (because the 2nd script deletes all the blocks present in active document before doing anything else > thus if ptsTree is modified > play it again Sam ... etc etc).

Note: in complex 3d instance definitions (and depending on what kind of animal/computer you have) this MAY be not very "funny". See suggestions.

More in the trad (as usual) V2 update (i.e.: more options/checks, attributes, nesting, cats, dogs, less efficiency, more bugs, a couple of divisions by zero  == progress, what else?).

best, Lord of SardineLand

Attachments:

Well ... appears that before V2 I must do the V1A he he.

BTW: Since I never work with Rhino (nor any layer based CAD app has any meaning to me) I've omitted the usual attr stuff at instance definition phase (color/level/you name it). The 2nd C# uses the name in order to select and delete blocks if some change is happening (for instance in the ptsTree).

BTW: What has point(s) to do with a 3d block? to do what? Or you use it as ref Point at instance definition phase? (this IS bad practice, mind: you'll end-up some day in the future with blocks that have ref points heading N/S/E/W)

more soon.

Thank you for your help so far.  I have taken a look at your files, and am pretty sure I understand whats going on.  Im going to delve deeper into it in the coming days to make sure I truly understand everything.  But until then, One specific thing I have been trying to figure out is how to add attributes to the Block when it is first added as an Instance Definition.  I see you adding attributes when you add an instance, but not when you define it.

So for example, if I have 3 points and 2 Crvs, and want each to be on a separate layer, but contained within a single block, is this possible?  It seems like it should be.

Also, If the block already exists, you delete it and then remake it.  Lets assume the block already exists, but all the information isnt contained in grasshopper.  I want to reference the block, obtain it's Base Point, and then Delete it from the block list.  this way, when I go to redefine the block, I am able to place an instance of it in the same locations.

Such a simple case eh? ... and already a myriad of if-this-do-that, he he (especially with the layer name related checks: if it doesn't exists > make it [what about layer nesting?] etc etc).

In the mean time I'm thinking some far more handsome way to sample all the block related paraphernalia (geo + name/description/layer/color/cats/dogs) into a System.Object data tree (PS: Already the N1 C# works with GeometryBase trees regarding the block Geo).

This means: within a given complex GH definition > get this from here, that from there ... continue ... and make a block (or a nested one).

 I want to reference the block, obtain it's Base Point, and then Delete it from the block list.

Hmm ...

Here we are: we have a banana1 with some base pt somewhere "around" the banana space. We want to create a banana2 (or a modified banana1) and replace all the instances of bananas1 in some Rhino file(s).

The obvious way to do it is: first load  banana1 (say at basePt = Point3d(0,0,0)) and then manually (or intelligently) delete stuff from banana1 and then add manually (or intelligently) geo that combined with what's remaining (from banana1) they make the banana2 (or a modified banana1) obviously with respect the basePt

The other way ... well ... it's either reinventing the wheel or rather far more complex than it appears (by "matching" babana1 to 2 etc etc).

On the other hand a sequential naming policy (if banana is found make [optionally] banana_x or banana_x_y etc etc) is an absolute must.

I think more specifically I am looking to load all of the instances of the block, and get their location based on their Cartesian Coordinates.  So im NOT looking for the block definition's geometry based on the block's base point of 0,0,0.  Instead I want to have a block name, and have to script find all the location that that block is placed.  Then after that I would...

basePt.Add(newBasePt)

This would then give me all of my new locations, and the old locations in one list.  From here I would proceed to delete the block, redefine the block, and then place instances based on a plane2plane translation.

I have been attempting to figure out how to define objects in a Block to specific layers, and think I have come pretty close.  I have a list of attributes, but when i bake the block, everything seems to be only on the layer of the last attribute to define (you have to explode the block to see this.  Not sure why this is happening, but here is the file if you are able to help at all.  

Attachments:

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