Objects change to layer. Help me

rhino
python

(Xiix Xoox) #1

i want change layer for object is selected by code python but i can’t. EX: i have text and text dot in layer default. I select text and move them to new layer (add layer and move).
I dont know command of change layer for object. Please help me


#2

That would be:

rs.ObjectLayer(objects, layername)

You might want to check to see if the layer “layername” exists first and if not, create it:

if not rs.IsLayer(layername): rs.AddLayer(layername)

Check the rhinoscriptsyntax help for more info, there are a number of optional arguments for rs.AddLayer() for example.


(Xiix Xoox) #3

Thank you! I have a rectangle form, i want to get point in the 4 angle and drawing path in which it should be doing any


#4

Hi I’m sorry, but that’s not completely clear, can you explain in more detail?

–Mitch


(Xiix Xoox) #5

i want get location of rectangle be draw before.


#6

OK, let me try to walk through this with you.

You have an existing rectangle in Rhino? You want to find it’s “location”?

A rectangle is a polyline with 4 corner points, it has a start/end point and 3 points in between. Rhino objects do not have specific “center” or “pivot” point.

To get the start of a curve, use rs.CurveStartPoint(curve)
To get the end of a curve, use rs.CurveEndPoint(curve)
To get the midpoint of a curve, use rs.CurveMidPoint(curve)

To get the control points of a curve use rs.CurvePoints(curve) this will actually return five points, the start and the end of a closed curve are the same point.

If you are looking for a “center” of a rectangle, you can use rs.CurveAreaCentroid(curve)

Again, check the Help for more info on all of these methods.

Does any of the above answer what you need?

–Mitch


(Xiix Xoox) #7

Thank you.
how can i get all text dot inside closed curve?


#8

I guess something like this will work:

import rhinoscriptsyntax as rs

#get the containing curve
container=rs.GetObject("Select planar containing curve",4)
if container:
    #make sure it's closed and planar
    if rs.IsCurveClosed(container) and rs.IsCurvePlanar(container):
        #get the curve plane
        plane=rs.CurvePlane(container)
        #get all visible/selectable dots in the file
        dots=rs.ObjectsByType(8192, state=1)
        if dots:
            inside=[]
            for dot in dots:
                #get dot insertion point
                pt=rs.TextDotPoint(dot)
                if rs.PointInPlanarClosedCurve(pt,container,plane):
                    #if true, dot is inside container curve, add to list
                    inside.append(dot)
            #if any dots are inside, they will be in the list "inside"
            if inside:
                rs.SelectObjects(inside)
            #the list 'inside' contains the ID's of the dots for further use

Note that as text dots are considered as points in this case, the script will select dots whose insertion point is inside the container, even of part of the dot itself is outside the container.


(Xiix Xoox) #9

Great!
have you document of python rhinoceros? I want to study but could not find document. Please send me if you have it. Thank a lot


#10

Have a look at this page:

There is also the “Python 101 primer” here:
https://www.rhino3d.com/download/IronPython/5.0/RhinoPython101

–Mitch