Need Help to create a simple Script

Hi all,
i’m really new in RhinoScripting, and i’m trying to make a very simple script, but i need help.

I just want to create a flat line bothside from 0 on Y axis according length of another curve .

i tried something like that :

Call Main()
Sub Main()

Dim StrLenght
StrLenght = Rhino.Command("_length")
Rhino.Command("_line _Bothsides , 0,0,0 StrLenght/2,0,0")

End Sub

I’m able to get the curve length, i’m able to create a line bothside from zero, but i can’t input my variable data in Y axis

Any Help ?

Thanks.

Hi Falfa
The second line would be:
Rhino.Command("_Line _BothSides 0,0,0 0,&StrLength&,0")

Ciao Vittorio

You could also try something like the following…
–Mitch

Option Explicit
Call LineBSYO()
Sub LineBSYO()
    Dim strCrv,dblLen
    strCrv = Rhino.GetObject("Select curve to process", 4, True)
    If IsNull(strCrv) Then Exit Sub    
    dblLen = Rhino.CurveLength(strCrv)
    Call Rhino.AddLine(Array(0, -dblLen * 0.5, 0), Array(0, dblLen * 0.5, 0))
End Sub

Hey Vittorio Thanks for help .

Helvetosaur, thanks, your script is more elaborate , can you just explain met the call line please ?

Call Rhino.AddLine(Array(0, -dblLen * 0.5, 0), Array(0, dblLen * 0.5, 0))

just tested the Vittorio method, but rhino return Unknown command: 0,&StrLength&,0

A line exists from 2 points

PointA and PointB

PointA = Array(0, -dblLen * 0.5, 0)
PointB = Array(0, dblLen * 0.5, 0))

A point exists from X, Y and Z

X = 0
Y = -dblLen * 0.5 and dblLen * 0.5
Z = 0

dbiLen = the length of the curve you select. The - and *0.5 extends your PointA and the *0.5 extends PointB to the other side.

And the Addline adds the line to the current document.

he forgot 2 quotes :wink:

Rhino.Command("_Line _BothSides 0,0,0 0," &StrLength& “,0”)

Hello Jordy,
Thanks for explanation.

Even with 2 quotes the script doesn’t work,

Dim StrLength
StrLength = Rhino.Command("_length")
Rhino.Command("_Line _BothSides 0,0,0 0," & StrLength & ",0")

Also return Unkwow command

A very important resource is the Rhinoscript Help file, available once you’re in the script editor via the Help menu. If you look at the AddLine method you will see:

AddLine
Adds a line curve to the current model.

Syntax
Rhino.AddLine (arrStart, arrEnd)

Parameters
arrStart Required.  Array.  The starting point of the line.
arrEnd Required.  Array.  The ending point of the line.

Returns
String The identifier of the new object if successful.
Null  If not successful, or on error.

In Rhinoscript points are specified by arrays of 3 numbers, you can create them by using the syntax

point=Array(x,y,z)

The AddLine method requires a start and end point for the line.

Thanks , i’ll push the F1 button next time :slight_smile:

Hi Falfa
The below script tested is Ok:

Sub Main
curve=Rhino.GetObject(“select curve”,4)
ll=Rhino.Curvelength(curve)
Rhino.command("_Line _Bothsides 0,0,0 0,"&cstr(ll)&",0")
end sub
Main

Ciao Vittorio

Hi Vittorio ,

Thanks for this,

Yes work, i just need to declare my variables first : Dim Curve,ll

But, stil a problem with this method, the line is created on Y axis depending on what viewport i select the curve base, according cplane axis i think.

Hi Falfa
The script works without declaring variables .
If you want to draw in absolute coordinates then:
Rhino.command("_Line _Bothsides W0,0,0 W0,"&cstr(ll)&",0")
Ciao Vittorio

Vittorio,

Thanks for help and solution,

You right it works.

Hi. I have a sript
XY3 = Rhino.AddPoint(Array(700, 0.0, 200))

If Rhino.IsPoint(XY3) Then

Rhino.Print "XY3 is a point."

Else

Rhino.Print "XY3 is not a point."

End If

XY4 = Rhino.AddPoint(Array(-1100, 0.0, 200))

If Rhino.IsPoint(XY4) Then

Rhino.Print "XY4 is a point."

Else

Rhino.Print "XY4 is not a point."

End If

Rhino.AddLine XY3, XY4
I can’t creat a line from XY3 to XY4.
I don’t know this programe ?
Help me.

Hello,

There is a difference between a Rhino point object - what you see on the screen as a dot and what is represented by an object ID or GUID - and the actual coordinates of that point, which are represented as an array of 3 numbers (X,Y,Z).

Rhino.AddPoint(Array(x,y,z)) adds a point object to the document at coordinates x,y,z

Rhino.IsPoint() tells you if the object (represented by its GUID) in question is a point object
(returns True or False)

However, if you want to use the coordinates of a point object, you need to first extract them with coords=Rhino.PointCoordinates(point). This will give you the array of 3 numbers that are the point object’s coordinates.

However, you have already supplied those coordinates when using RhinoAddPoint()

So, you can make a line as follows:

Option Explicit
Call Test()
Sub Test()
	Dim XY3,XY4,line
	XY3 = Array(700, 0.0, 200)
	XY4 = Array(-1100, 0.0, 200)
	line = Rhino.AddLine(XY3, XY4)
End Sub

You might want to look at some of the available info on Rhinoscript here:

HTH, --Mitch

Thank you so much. your answer has helped very much.

Hello.

I have 2 curve , cur1 and cur2. I want to join them. I use syntax
Rhino.JoinCurves (cur1, cur2), but it not successful. Can you help me?

Thank you

JoinCurves() is looking for a collection of curves to join - can be more than two - so you need to put the curves into an array:

Rhino.JoinCurves (Array(cur1, cur2))

HTH, --Mitch

Hi.

Can you help me this scrip. It’s not successful to creat line .

Sub Main()

Dim a, b, c, d, f, g

a = Rhino.getobject("select curve a")

b = Rhino.getobject("select curve b")

c = Rhino.CurveEndPoint(a)

d = Rhino.CurveStartPoint(b)

f = Rhino.AddLine(Array(c, d))

g = Rhino.AddLine(Array(Array(c(0), 0.0, c(2)), Array(d(0), 0.0, d(2))))

End Sub

Main