Distribute block on point and along spline


#1

Hi I’am rookie on the forum, and it’s the first time I’am trying to create script on rhino.
Here is the purpose :
I want to distribute a bloc on a point and along a spline, then I want to merge everything.
this is what I want to do :

I don’t know if I can do all the 3 step in the same script, but I’am pretty sure that I can do step1 and step 2 in the same. I have found 2 different script that I want to weld together, on to distribute the bloc on the points, the other one to orient the bloc on the spline.
My problem is that the second script is just not working, when I launch it, it stop ( do I need a plugin or something like this ?)

bloc on point :


' Replaces points with blocks Call ReplacePointsWithBlocks Sub ReplacePointsWithBlocks       ' Select points to replace with a block     Dim arrObjects     arrObjects = Rhino.GetObjects("Select points to replace with a block", 1, True, True)     If Not IsArray(arrObjects) Then Exit Sub       ' Get the names of all block definitions in the document         Dim arrBlocks     arrBlocks = Rhino.BlockNames(True)     If Not IsArray(arrBlocks) Then         Rhino.Print "No block definitions found in the document."         Exit Sub     End If       ' Select a block name from a list     Dim strBlock     strBlock = Rhino.ListBox(arrBlocks, "Select block", "Replace Points")     If IsNull(strBlock) Then Exit Sub       ' Turn off redrawing (faster)     Rhino.EnableRedraw True             ' Process each selected point object     Dim strObject, arrPoint     For Each strObject In arrObjects         ' Get the point object's coordinates         arrPoint = Rhino.PointCoordinates(strObject)         ' Insert the block at that location         Rhino.InsertBlock strBlock, arrPoint     Next       ' Delete all of the point objects     Rhino.DeleteObjects arrObjects          ' Turn redrawing back on          Rhino.EnableRedraw True         End Sub


then the orient on curve script which doesn’t work :


Option Explicit
’Script written by Pascal
’Script copyrighted by RMA
’Script version Wednesday, October 24, 2007

Private sOldCopy

If isEmpty(sOldCopy) Then
    sOldCopy = "Yes"
End If

Sub OrientCrv2Pt()
    
    Dim aObj: aObj = Rhino.GetObjects(“Select objects to orient”,True,True,True)
    
    If Not isArray(aObj) Then Exit Sub
    
    Dim sCopy: sCopy = Rhino.GetString(“Copy?”,sOldCopy,array(“Yes”, “No”))
    If isnull(sCopy) Then Exit Sub
    sOldCopy = sCopy
    
    Dim abase: aBase = Rhino.GetPoints(True,“Set first base point”, “Set second base point”,2)
    If Not isarray(abase) Then Exit Sub
    
    Dim sTarg:    starg = Rhino.GetObject(“Select target curve”,4)
    If isnull(starg) Then Exit Sub

Dim aPt(1)
    aPt(0) = Rhino.GetPointOnCurve(sTarg,“Set first target point”)
    If Not isArray(aPt(0)) Then Exit Sub
    
    apt(1) = Rhino.GetPointOnCurve(starg, “Set a point on the curve near the desired target point”)
    If Not isArray(aPt(0)) Then Exit Sub
    
    Rhino.EnableRedraw(False)
    
    Dim Dist: Dist = Rhino.Distance (aBase(0), aBase(1))
    Dim param: Param = Rhino.CurveClosestPoint(starg,aPt(0))
    Dim plane: Plane = Rhino.CurveFrame(starg,Param)
    Dim sSphere: sSphere = Rhino.addSphere(apt(0),Dist)
    
    Dim aInt:aInt = Rhino.CurveSurfaceIntersection(starg,sSphere)
    Rhino.DeleteObject sSphere
    
    Dim aTest(), i
    If isArray(aInt) Then
        For i = 0 To Ubound(aInt)
            ReDim Preserve atest(i)
            atest (i) = aInt(i,1)
        Next
    End If
    
    Dim temp: temp = Rhino.PointArrayClosestPoint (aTest, apt(1))
    Dim atarg: atarg = aTest(temp)

Dim stargPt: stargPt = “W” & Rhino.Pt2str(atarg,True)
    Dim sRef:sRef = “W” & Rhino.Pt2str(aPt(0),True)
    Dim sbase1: sbase1 = “W” & Rhino.Pt2str(abase(0),True)
    Dim sbase2:sbase2 = “W” & Rhino.Pt2str(abase(1),True)

Dim Vecbase: vecbase = Rhino.VectorCreate(aBase(1), abase(0))
    Vecbase = Rhino.VectorUnitize(VecBase)
    Dim Vectarg: vectarg = Rhino.VectorCreate( aPt(0), aTarg)
    VecTarg = Rhino.VectorUnitize(VecTarg)
    
    Dim basePlane: BasePlane = Rhino.PlaneFromNormal(aBase(0),Vecbase)
    Dim targplane: targPlane = Rhino.PlaneFromNormal(atarg,Vectarg)
    
    Dim aNew: aNew = remapToPlane(aObj, BasePlane, TargPlane)
    
    Dim str
        
    Rhino.EnableRedraw(True)
    
    If isArray(aNew) Then
        
        Rhino.UnselectallObjects
        Rhino.SelectObjects aNew
        str = "_Rotate3D " &sRef &sTargPt
        Rhino.Command str,False
        
    End If

End Sub

Function RemapToPlane(aObj, Plane1, Plane2)
    
    Dim aXform: aXForm = Rhino.XformRotation(Plane1, Plane2)

Dim result: Result = Rhino.TransformObjects (aObj, aXform, True)  'bln Copy
    RemapToPlane = Result
    
End Function

Rhino.AddAlias “OrientCrv2Pt”, "_noEcho _-Runscript OrientCrv2Pt"
Rhino.AddStartupScript Rhino.LastLoadedScriptFile


So first thing is that I want the second sript to work, then I’ll try to mix them

Any help ?


(Rajaa Issa) #2

Looks like there is a small typo in the second script.
atest (i) = aInt(i,1)

should be changed to:
aTest (i) = aInt(i,1)


#3

thanks, It helps.
It have changed the error message, but it’s still not working
message is now :

what’s wrong ?


(Rajaa Issa) #4

Line 97 adds an alias command to Rhino so you can call the script from the command line after you run the script. This way you do not need to run the script every time you need the function. You will simply type “OrientCrv2Pt” in the command line.

Line 98 is used to add the “last loaded” script into Rhino when Rhino command starts. For this to work, you first need to save your script, then use LoadScript command from Rhino to load it. Once you do that, run the script, and line 98 will add your script to the list of scripts loaded when Rhino starts.

If you are in the process of developing a script, then you can comment out the last 2 lines (97 and 98) and use a main function to call and run your script.