ExtrudeCurveStraight/Bothsides?


#1

Hi all,

i’m trying to extrude planar curves on bothsides, but ExtrudeCurveStraight has no bothsides options.

I’m wondering how can i do this , any help appreciated.

Thanks.

Call Main()
Sub Main()
	
	Dim arrCrv, Dist, strCrv, arrPlane
	Dim arrDir,arrPoint
	
	arrCrv = Rhino.GetObjects("Select planar curves", 4, True, True)
	
	If IsNull(arrCrv) Then Exit Sub
	
	Dist = 20
	
	For Each strCrv In arrCrv
		
		If Rhino.IsCurvePlanar(strCrv) Then
			
			arrPlane = Rhino.CurvePlane(strCrv)	
			
			arrDir = Rhino.VectorScale(arrPlane(3), Dist)
			arrPoint = Rhino.PointAdd(arrPlane(0), arrDir)						
			Rhino.ExtrudeCurveStraight strCrv, arrPlane(0), arrPoint
		
		End If
	Next

		
End Sub


#2

hey Cyril

i made a python script for extruding multiple planar curves which has a bothSides option… for that one, i moved the curve to one side then extruded from there… here’s the script if you want to have a look at it:

ExtrudeMulti.py (2.6 KB)

(*note, if you actually use this script’s bothSides option, the entered distance will be for the overall thickness of the extrusion as opposed to half the distance as seen in rhino’s extrudeCurve)


#3

Basically if you have your extrusion vector and magnitude, you can first move/copy the curve to be extruded in the opposite direction by that vector, then extrude it 2x the magnitude… --Mitch

Option Explicit

Call Main()
Sub Main()    
    Dim arrCrv, Dist, strCrv, strBaseCrv, arrPlane
    Dim arrDir, arrMove, arrPoint
    
    arrCrv = Rhino.GetObjects("Select planar curves", 4, True, True)
    
    If IsNull(arrCrv) Then Exit Sub
    
    Dist = 20
    
    For Each strCrv In arrCrv
        
        If Rhino.IsCurvePlanar(strCrv) Then
            
            arrPlane = Rhino.CurvePlane(strCrv)
            arrMove = Rhino.VectorScale(arrPlane(3), -Dist)
            strBaseCrv = Rhino.CopyObject(strCrv, arrMove)
            
            arrDir = Rhino.VectorScale(arrPlane(3), 2 * Dist)
            arrPoint = Rhino.PointAdd(arrPlane(0), arrDir)                        
            Rhino.ExtrudeCurveStraight strBaseCrv, arrPlane(0), arrPoint
            Rhino.DeleteObject strBaseCrv        
        End If
    Next        
End Sub

#4

Hey Jeff, i’m not really comfortable with python, but thanks for script and explanation, i’ll take a look.

Mitch , perfect ! as always ( you just made a little mistake in variable declaration baseCrv > strBaseCrv)

Merci :wink:


#5

probably no need to have a look at the python script… it’s pretty much the same thing that mitch showed in the language you’re familiar with (which i’m not… that rhinoscript isn’t available on mac)


#6

Here’s my example…

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def ExtrudeCrvBothSides(crv,dir_vec,cap):
    crv.Translate(-dir_vec)
    return Rhino.Geometry.Extrusion.Create(crv,2*dir_vec.Length,cap)

#planar closed curves
def cp_crv_filt(rhino_object, geometry, component_index):
    return rs.IsCurvePlanar(geometry) and rs.IsCurveClosed(geometry)

def TestExtrudeBS():
    msg="Select planar curve to extrude both sides"
    crvID=rs.GetObject(msg,4,preselect=True,custom_filter=cp_crv_filt)
    if not crvID: return
    
    ht=rs.GetReal("Extrusion length?")
    if not ht: return
    
    cap=True #cap extrusion
    crv=sc.doc.Objects.Find(crvID).Geometry
    rc,plane=crv.TryGetPlane()
    if rc:
        result=ExtrudeCrvBothSides(crv,ht*plane.Normal,cap)
        if result:
            sc.doc.Objects.AddExtrusion(result)
            sc.doc.Views.Redraw()
TestExtrudeBS()

#7

(Fixed…) --M