Subtracting multiple Polysurfaces from multiple Polysurfaces in RhinoScript


#1

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`

#2

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.


#3

@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.


#4

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.

–Mitch


#5

@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.


#6

Dunno… Seems to be working here… This is python but vb Rhinoscript should be similar…

import rhinoscriptsyntax as rs

outer_crvs=rs.GetObjects("Select outer rectangles",4)
inner_crvs=rs.GetObjects("Select inner rectangles",4)
path=rs.GetObject("Select path curve",4)

outer_vols=[]
for crv in outer_crvs:
    extru=rs.ExtrudeCurve(crv,path)
    rs.CapPlanarHoles(extru)
    outer_vols.append(extru)
    
inner_vols=[]
for crv in inner_crvs:
    extru=rs.ExtrudeCurve(crv,path)
    rs.CapPlanarHoles(extru)
    inner_vols.append(extru)
    
result=rs.BooleanDifference(outer_vols,inner_vols)

–Mitch


#7

Here is my try , hope that help :slight_smile:

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

#8

@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?


#9

@Cyver
Thanks,
Correct me If I am wrong.
I can see by arrLst() you collected the data in arrays.


#10

exactly !


#11

The same in vb Rhinoscript…

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

–Mitch


#12

@Helvetosaur

Yep,
Thanks