Python right now

Hello! I would like to get some Python now, I will be glad to any materials, if only they were not so huge and they could be understood :slight_smile:

1 Like
3 Likes

Hi,

if you are a real beginner to programming this is a great starting point. Once you know basic Python,
you could start using Python in Rhino. Just be aware that Python3.x and IronPython (Python 2.7) can differ in syntax.

3 Likes

Here is Rhino.python documentation that includes some fundamentals: http://developer.rhino3d.com/guides/rhinopython/

And the rhino.python 101 is a good primer also: http://developer.rhino3d.com/guides/rhinopython/primer-101/

And three is this series from Modelab on video: https://www.youtube.com/playlist?list=PLGV167zE8gnVhurBT46afZ1RlK9RzAsLx

4 Likes

Yes, great, there are a lot of good materials, but I would like a little practice. And I will be very happy if you give me some of your time and help me write one small script, my first script!

Hi,
Just make a beginning and ask about what issues you run into,
Post you code to be readable like so:

#This is code 
print 'Hello World'

-Willem

image

1 Like

@Willem, yes, thank you! But I’m just starting :slight_smile:

The docs have a your first getting started guide. And each of the fundamentals has sample code. Here are samples : http://developer.rhino3d.com/samples/

1 Like

Open editpythonscript command.

2 Likes

Well, it seems that I understand the basics, but I absolutely don’t understand how to approach the solution of the problem. I will be glad of any activity, as it will most likely be difficult and I’ll simply “bomb” my questions! Now I’m just getting ready …

The process of learning has to be to first just write out the sample code and play with it. There are many samples to play with there. Understand how to change the code and re-run the examples. After understanding some of the basic syntax only then can you determine your approach to solving a problem.

By the way, what is the problem you are trying to solve?

1 Like

Sure! I think it’s better to start with … Is it possible to somehow select a random object in an existing document?

Are you sure? :smiley: If I would need to relearn programming from scratch, I would learn the language first. Sure tinkering around with scripts is a nice starting point and its a great way of keeping motivation. However from an educational standpoint its much easier and lasting if you understand the language, with all its flaws and advantages. Just as you said, the biggest question mark is how to become able to solve problems by yourself.

Therefore you need to know the tools. Just as you need to know the most important commands within Rhino to be able to model a shape.

On top of that, the skill of reading library documentation and error messages is very helpful. Debugging in general. The earlier you learn all this, the faster you‘ll progress.

1 Like

Do you mean prompt the user to select any object. That would be a get object method: http://developer.rhino3d.com/guides/rhinopython/python-user-input/

Or do you mean truly random using a random function?

1 Like

Thank you, but that’s not quite what I need. Yes, there are many useful functions, but I’m specifically interested in how I can select an object without using a mouse, without doing anything at all. It is possible by ID, but here it will still take a few clicks, since you need to get it first. Can I somehow randomly select objects and carry out operations on them?

Sure - collect all the selectable objects’ ID’s with rs.NormalObjects(), then use one of Python’s native random methods to randomly decimate the list into the number of objects you want… then do want you want with those.

1 Like

Yes, thank you so much! I also thought about something like this and found


However, I don’t get this, I will be very glad if you explain some fragments :slight_smile: Good?

Are there lines that do make sense to you? and which fragments specifically do you not understand?

1 Like

Yes, I think there is something to be learned. And I would like to know … Why are function calculations assigned to 2 variables? Why is the “rc” variable here?

rc, layername = Rhino.Input.RhinoGet.GetString(“Name of layer to select objects”, True, layername)

Some methods in RhinoCommon return both a success/failure boolean value, plus some sort of data value(s) - but the second maybe only if successful. So normally you first look at the value of rc and if it is True, then you can look at the second (or other) element(s) in the return list; if rc is False, it means the function failed and you do not need to look further.

There does appear to be some debate about what the name rc actually stands for:

2 Likes