Python right now

It is short for “Return Cash”. In the early days of python development, (around 1909), programmers were only paid if the function completed successfully. They started using rc as an indicator for the overlords to recognize that they needed to pay up if it worked. Note, all of this is totally true…really.

2 Likes

It is very detailed, thank you! And now I have worked a little with this code, “rc” is really an indicator and it returns Success :slight_smile: Cool! Well, “layername” is already just a variable that takes on a new value if the user nevertheless enters some other layer (not the current one). Right?

In some cases the Return Cash variable isn‘t a boolean but the actual amount of cash a function generated, expressed in rounded integers. Usually expressed in geometric sequence of a = 2^n.
Usually its just $0 but sometimes you get $512 (2^9) or even $1024 (2^10) ! If you get a return cash which is not 2^n its usually because somehow you got payed multiple times within one call.

1 Like

And the last … What is the meaning of these lines? I absolutely don’t understand ((

if __name__=="__main__":
    SelLayer()

its a Python thing. It means if the codefile is used as entrypoint for the interpreter = its the main file, then please run this method. As I said, really go through some Python tutorials because many questions you ask right now are basic ones!

1 Like

Hello,

3 Likes

Yes, I also got acquainted with various materials from Google, I got it, thank you! And this question was really basic, you are right. But I have a task and I can’t go to study everything, I try to generally understand how this is done, to complete the task, and there it is possible to study further so that there are fewer questions.

From my experience: it took me some weeks to get the basics, some years to get intermediate and a couple of months of everyday work to code „professionally“, but still it feels so overwhelming. I could have reduced the part in the middle, if I would have forced myself understanding the language from beginning on and not to stop at writing simplistic scripts over and over again. 99% of your future questions can be answered by searching the right thread on Stack Overflow or similar.

But even if you know the language, there are so many different things you can do and somethings you never touch. There is so much more than knowing how to code. Usually you will have more questions than answers, the problem of lacking time will stay forever. But thats why coding is fun. It challenges you everyday! If this doesn‘t motivate you, than this is something which may not be the right activity for you.

4 Likes

Thank you for these awesome words! Yes, to write serious scripts I still need to study and study, I understand, but now I need to solve this problem, then I will definitely continue to “plunge” into the world of Python, because I really like algorithms :slight_smile:

Modules modules, how do you determine what you need? And why are some marked, these are the main ones?
2020-07-14_103752

Best is to go the other way around. What do you need and then search if you need to import a module.
But to give a couple examples:

scriptcontext: when working directly with Rhino common, you often create geometry ‘in memory’ before adding anything to your Rhino document. Scriptcontext I mostly use for that: adding the created objects to the doc.
math: this module I often import for mathematical operations (for example cos, sin etc)
random: think this is clear what it stands for
System: for example if you want to work with colors, import System.Drawing.Color
os: to work with file paths.

the {} I think stands for namespace, an organization of classes.

1 Like

Tell us what you want to script and show what you got so far.
I understand your desire to know what you need, but that can be left for later.

For now only import rhinoscriptsyntax as rs
and start scripting.

Other modules are for more advanced functionality that Gijs had already outlined
-Willem

-Willem

2 Likes

Hello,

Also you could check out the current python Humble Bundle for some good value python learning resources.

Graham

@Gijs, yes, thank you, I will try :slight_smile:
@Willem, well, for now I will use the already known modules and try to write something, I will definitely share this, but first I want to lay some basic structure.

Start with rhinoscriptsyntax then move on to use the geometric part of Rhinocommon (Rhino.Geometry). That will solve 99 % of what you like to do in Rhino. Have a look at the ‘coerce’ functions of rhinoscriptsyntax which allow you to mix both.
Otherwise learn reading api documentation, it can be as difficult as learning the language itself. Sometimes understanding others ways of thinking can be hard. But Rhino offers a great api documentation.
Oh one downside of Python in Rhino is that its IronPython and sometimes you don’t understand the api, because its due to the underlying .net framework which is made to support strongly typed languages (C#, VB, C++) -> interfaces, generics, events …

2 Likes

Yes, thank you, time to start writing :slight_smile:

I recently found this script, it helped me a lot to solve the problem, so … @Helvetosaur, thank you!! And now I am adapting it
CreateColorPointCloud.py (696 Bytes)

1 Like
import rhinoscriptsyntax as rs
import scriptcontext as stex
import Rhino

def ObjectsToPoints():
    for id in objects:
        id_pieces = rs.ExplodePolysurfaces(id, True)
        for piece in id_pieces:
            meshParameters = [1, 3, 1, 0.0001, 0.005, 0.01, 0, True, False, False, False]
            mPiece = Rhino.DocObjects.MeshObject(piece, -1, meshParameters)
            rs.DeleteObject(piece)
            points = rs.MeshVertices(mPiece)
            rs.DeleteObject(mPiece)
            
            pc = Rhino.Geometry.PointCloud()
            color = rs.LayerColor(layer)
            for pt in points:
                pc.Add(pt, color)
            id = stex.doc.Objects.AddPointCloud(pc)

unsel = rs.UnselectAllObjects()
if unsel:
    print(unsel, "objects were selected")

choose_mode = rs.MessageBox("Yes/select and No/all", 4 + 32, "Mode, please")

if choose_mode == 6:
    layer = rs.GetLayer("Layer, please")
    if layer:
        rs.CurrentLayer(layer)
        objects = rs.ObjectsByLayer(layer, False)
        ObjectsToPoints()
        
    else:
        print("Layer was not selected")

elif choose_mode == 7:
    layers = rs.LayerNames()
    for layer in layers:
        lock = rs.IsLayerLocked(layer)
        if not lock:
            rs.CurrentLayer(layer)
            objects = rs.ObjectsByLayer(layer, False)
            ObjectsToPoints()
            
        else:
            print("%s layer was blocked" % layer)

else:
    print("Cancel")

I wrote this code, but something is wrong, it doesn’t work (( Help me please!

Instead of this: mPiece = Rhino.DocObjects.MeshObject(piece, -1, meshParameters)
I had it: mPiece = rs.MeshObjects(piece, -1, meshParameters) but it still doesn’t work :no_mouth:

Hi Modeler3D
Im on my phone so csnno test but maybe you need to make sure you objects have a rendermesh.
How about turning the view to shaded mode first. This will make sure all visible objects have a rendermesh generated for them.

Don’t change to mPiece but keep it as Rhino.DocOb…

Does that work?

1 Like