I would like a script that automates the creation of blocks.
I have a model with hundreds of 3D solids contained within. Each solid has its own unique name applied to it in the object properties.
Is it possible to have a script that makes a block of each individual solid and uses the solids object name as the block name?
I see the workflow going something like this…
1- select all objects to be converted into blocks. this would be all objects at once so i dont have to repeat the selection process for each individual solid
2- the script would then go through and identify each solid I have selected and make an individual block of each solid using the unique object name already applied. The block basepoint would be the model zero point (WCS) and the layer the block would be on can be the same layer the 3D solid is on.
Note the solids are not all modelled on the same layer if that matters. There is about 20 layers containing hundreds of 3D rhino solids.
Any help greatly appreciated.
Can you upload sample file, both before and after?
I dont understand the before and after request…are you requesting a sample rhino file of the 3D solids…?
To be clear I dont have any Scripts or knowledge of how to write them. What I am requesting is if one of you salty old scripting masters could write me such a script it would help me out. Almost like a charity without the benefits of tax write-offs… lol
Hi, the attached script should do what you described.
It has limited checking for problems built in (in case object has no name or a block with that name already exists, these objects will stay selected after the script completes).
CreateBlocksFromNamedObjects.rvb (891 Bytes)
Jarek you are a legend!
That worked flawlessly!!! and your error trapping trick of selecting any objects that had problems was a nice touch. It doubles its a good way for me to check whether I have any duplicate part numbers.
thank you so much
If you’re using Grasshopper you might be interested in the Elefront plugin which enables Grasshopper to read/write blocks.
Can i pick your brains regarding a system to handle part numbers within Rhino.
my current workflow is this…I manually enter each part number using the rhino object name in the properties panel. It takes ages as some of my assemblies have 500 parts and it gives me no options to manage the part numbers. For example the part numbers contain a project code and if that project code changes i have to manually go through and change 500 parts… Also if I remove parts or add additional parts the numbering sequence gets all messed up.
what would be good is if there was a plugin / script / something that intelligently handled part numbers and part numbering. Perhaps something that reads and writes back to a MS excel or a CSV spreadsheet.
It would be good if such a system could also apply names to selected parts that are currently un-named.
Perhaps something like select the rhino objects to be named, select a list of part numbers from a spreadsheet to pull the names from and the script applies the names in a orderly fashion using the distance a part is from zero along the X or Y planes. so the ones closest to zero have the numbers applied to first…
Is this something that can be scripted or is there already something out there existing that does this already?
Any ideas you or anyone else has on the matter would be appreciated
Hi Dax - would you have a sample file with just a few parts and before-after names?
Sounds like it could be automated in many ways. The excel part may be a bit more work though and I am not completely clear of all the steps. If you have a sample file and can write a step-by-step of what the automation could do, it may help to come up with a solution.
I have sent you a personal message with a link to download a sample file and the additional info you request. let me know if it dosnt show up.
Replacing part of the object name that changed is relatively easy, see attached script that should do it.
FYI - you can identify objects containing certain part of the name by using dashed version of command _-SelName ABCD* [where ABCD is the part of the name you are looking for, and * stands for anything else that goes after that). This may get handy in identifying objects with certain part of project name.
ReplacePartOfObjectName.rvb (654 Bytes)
As for the sequential naming and numbering and direct two-way excel link, that is a bit more involved and at this moment I can’t quicky provide a solution. I’ll have to take a look at the sample file and possible ideas later.
Here is the first attempt at the naming from Excel part:
Excel_Reading_Selection_Test_01.rvb (1.2 KB)
The way it works is you have to have Excel open and there have a cells selected with names to be used in a single column.
Then you run the Rhinoscript and select (or have preselected) the objects to be named from the Excel cells. The count of selected objects has to be less or equal to selected cells. The script will name the objects from Excel cells and will put Rhino object IDs on the right side of each name cell in Excel.
So far there is no sorting of objects in any logical way there (can add later) - it’s either the order the objects were picked or random, if window-selecting.
See if it works on your end.
im green with envy, some day I have got to get up to speed with Scripting and grasshopper. Its amazing what guys like you can achieve. Thanks for putting some time into this.
I ran the script here and it works exactly as described. While not quite the polished tool Im after for a first crack at it its more than exceeded my expectations. You have probable saved me 2 to 4 hours on every project just with this script alone.
thank you again.
glad it helps – obviously the script could be developed more; making it a full-fledged tool with options, settings etc. that would match exactly your workflow would be a larger project for sure.
At the very least we could try to add some sort of intelligent order of object naming. If you have any specific ideas for that or any other automation, let me know. Can’t promise when, but we could probably add more code at some point.
And yeah, even very basic scripting knowledge can save tons of time on repetitive tasks. Never too late to start ; )
There is a company called “Enthought” in Austin, Texas, that makes and offers a product called “Canopy” which is a Python distribution, IDE, etc. THEY HAVE a ‘new’ product that is - basically - a set of (Python) routines that interface with Excel,
that might help?
I did one more round to make the script a bit more useful : after selecting the objects to be renamed from Excel, you can either pick existing or draw a reference curve/polyline, that will be used to sort the objects order along, so the sequential naming can be defined better.
It will also now show name previews as dots before exiting the script.
I found the curve sorting way more flexible and useful than by X or Y direction.
Excel_Reading_Selection_Test_02.rvb (5.1 KB)
Legend, that works a treat. Great idea to use a polyline to control the numbering sequence, I now have unlimited possibilities to set a sequence. Nice touch with the dots also, good for error trapping.
Thanks for your expertise
I have been asked via PM to update the CreateBlocksFromNamedObjects script so it works on objects with no names or duplicated names.
Here is the updated version, in case anyone else finds it useful:
CreateBlocksFromNamedObjects.rvb (1.3 KB)
Thanks Jarek, I will be useful to have both versions. Much appreciated.