Hello,
Can anyone please help with the following code?
Just imagine there are two squares and inside each one there are two rectangles. the code is supposed to take all inner rectangles, extrude and convert them to solid objects and subtract them from their outer extruded curves.
The current result is to apply BooleanDifference on the last selected inner curve and its bounding box only.
Thanks;
`Call Main()
Sub Main()
Dim arrInput0, arrInput1,strObject0,strObject1,strPath,surface1,surface2
arrInput0 = Rhino.GetObjects("Select inner Curves")
strPath = Rhino.GetObject("pick path")
If IsArray(arrInput0) Then
For Each strObject0 In arrInput0
surface1 = rhino.ExtrudeCurve(strObject0, strPath)
rhino.CapPlanarHoles(surface1)
Next
arrInput1 = Rhino.GetObjects("Select bounding Curves")
If IsArray(arrInput1) Then
For Each strObject1 In arrInput1
surface2 = rhino.ExtrudeCurve(strObject1, strPath)
rhino.CapPlanarHoles(surface2)
Rhino.BooleanDifference surface2, surface1
Next
End If
End If
End Sub`
Are the inner rectangles always only completely inside one of the squares? In which case you could script the “ExtrudeCrv” command itself using Rhino.Command and have it make them solids automatically. I guess to avoid doing that you could first make a surface from the curves using Rhino.AddPlanarSrf, then use Rhino.ExtrudeSurface.
@JimCarruthers
Yes, the rectangles (or any other closed curves) are completely inside another closed curve.
so the output should be a solid polysurface with 2 holes in it.
I am quite sure that your suggestion with Rhino.Command and Rhino.AddPlanarSrf works perfectly.
But I am still curious about what I am missing to get this code working.
Just off the top of my head, I would say you need to extrude the outer squares first, cap them and collect the capped objects in an array (say arrOuterVols), then the extruded capped inner rectangles in another array (say, arrInnerVols), then use Rhino.BooleanDifference(arrOuterVols,arrInnerVols)… Not tested though.
@Helvetosaur
That is pretty much the same as how I am trying to approach to the solution.
But only the last selected inner rectangle gets subtracted.
I don know how to make arrays of Solid extruded objects.
Call Main()
Sub Main()
Dim arrInput0, arrInput1,strObject0,strObject1,strPath,surface1,surface2
Dim arrLst1(), arrLst2()
Dim i,j
i = -1
j = i
arrInput0 = Rhino.GetObjects("Select inner Curves")
strPath = Rhino.GetObject("pick path")
ReDim arrLst1 (Ubound (arrInput0))
Rhino.EnableRedraw(False)
If IsArray(arrInput0) Then
For Each strObject0 In arrInput0
i = i + 1
surface1 = rhino.ExtrudeCurve(strObject0, strPath)
rhino.CapPlanarHoles(surface1)
arrLst1(i) = surface1
Next
Rhino.EnableRedraw(True)
arrInput1 = Rhino.GetObjects("Select bounding Curves")
ReDim arrLst2 (Ubound (arrInput1))
If IsArray(arrInput1) Then
Rhino.EnableRedraw(False)
For Each strObject1 In arrInput1
j = j + 1
surface2 = rhino.ExtrudeCurve(strObject1, strPath)
rhino.CapPlanarHoles(surface2)
arrLst2(j) = surface2
Next
End If
Rhino.BooleanDifference arrLst2, arrLst1
End If
Rhino.EnableRedraw(True)
End Sub
@Helvetosaur
Yeah your python code is working.
I guess what is missed in my code is to Collect the Polysurfaces (inners and boundings) in 2 different arrays.
Thoughts?
Option Explicit
Call Test()
Sub Test()
Dim outer_crvs,inner_crvs,crv,path,extru,n,result
Dim outer_vols(),inner_vols()
outer_crvs = Rhino.GetObjects("Select outer rectangles", 4)
inner_crvs = Rhino.GetObjects("Select inner rectangles", 4)
path = Rhino.GetObject("Select path curve", 4)
n = -1
For Each crv In outer_crvs:
extru = Rhino.ExtrudeCurve(crv, path)
Rhino.CapPlanarHoles(extru)
n = n + 1
ReDim Preserve outer_vols(n)
outer_vols(n) = extru
Next
n = -1
For Each crv In inner_crvs:
extru = Rhino.ExtrudeCurve(crv, path)
Rhino.CapPlanarHoles(extru)
n = n + 1
ReDim Preserve inner_vols(n)
inner_vols(n) = extru
Next
result = Rhino.BooleanDifference(outer_vols, inner_vols)
End Sub