显示标签为“plugin”的博文。显示所有博文
显示标签为“plugin”的博文。显示所有博文

2009年1月13日星期二

plugin | unroll srf or brep into ordered plan

Snap2 Snap3 Snap4 Snap5

This little code is just for unroll a bunch of surfaces. The parameter include ordering by "bounding box size" or by spatial location, with or without labels.

if no srf or brep is selected, will show:Snap6 , if only one srf  is selected will show: Snap7 , lol….

the core of the code is the “order by size” and the “smash” rhino command.

these are the samples:

snap0426 snap0427

                without label                                          with/without label                     

snap0428 snap0429

                   by spatial relation                                             by size

 

Click to download plugin: drag to your rhino and you are all set.

Run it by typing command "xUnroll" or go to the menu "xTools".

__________________________________________________________

Option Explicit
'Script written by <xarch.blogspot.com>
'Script copyrighted by <xarch.blogspot.com>
'Script version Monday, January 12, 2009 4:33:17 PM

Call Main()
Sub main()

    Dim breps: breps=rhino.getobjects("select Srfs or breps",,True,True)
    If isnull(breps) Then Exit Sub
    Dim spacingfactor:
    spacingfactor=rhino.getreal("spacing factor?",2,0.001) 'x time biggest panel size
    If isnull(spacingfactor) Then Exit Sub
    Dim BestGuessSwitch
    BestGuessSwitch=rhino.getstring("Order method, by spatical location?","Yes",array("Size"))
    If isnull(BestGuessSwitch) Then Exit Sub
    If BestGuessSwitch="Yes" Then BestGuessSwitch=1
    If BestGuessSwitch="Size" Then BestGuessSwitch=2
    '1=order by spatical location(exploded)
    '2=order by size   
    Dim ShowTagSwitch
    ShowTagSwitch=rhino.getstring("add Label?","No",array("Yes"))
    If ShowTagSwitch="Yes" Then ShowTagSwitch=1
    If ShowTagSwitch="No" Then ShowTagSwitch=0
    Dim brep,n1,brepstemp()
    n1=0
    For Each brep In breps
        If rhino.ObjectType(brep)=8 Or rhino.ObjectType(brep)=16 Then
            ReDim Preserve brepstemp(n1)
        brepstemp(n1)=brep
            n1=n1+1       
        End If
    Next
    If n1=0 Then
        rhino.MessageBox "No srf selected"
        Exit Sub
    End If
    Call unrollsrfs(brepstemp,spacingfactor,BestGuessSwitch,ShowTagSwitch)
End Sub

Function unrollsrfs(ByVal breps,ByVal spacingfactor,ByVal BestGuessSwitch,ByVal ShowTagSwitch)
    Dim n:n=ubound(breps)
    If n<=0 Then
        rhino.MessageBox "Need 2 or more srfs to run, you lazybone!"
        Exit Function
    End If
    Dim allcenter:allcenter=rhino.Pointscale(rhino.PointAdd(rhino.BoundingBox(breps)(0),rhino.BoundingBox(breps)(6)),0.5)
    Dim sortsize,spacing,center
    sortsize=SortSrfBySize(breps)
    spacing=sortsize(1)(0)
    center=sortsize(2)
    ' testing
    'rhino.AddTextDot "the biggest panel is "&spacing , sortsize(2)(0)
    'rhino.AddTextDot "the smallest panel is "&sortsize(1)(n) , sortsize(2)(n)
    Dim k,obj,arrobj,arrUnroll
    k=-1
    arrUnroll = Array()
    If BestGuessSwitch=0 Then arrobj=breps
    If BestGuessSwitch=1 Then arrobj=sortsize(0)
    If BestGuessSwitch=2 Then arrobj=sortsize(0)
    rhino.EnableRedraw False
    For Each obj In arrobj
        k = k + 1
        If ShowTagSwitch=1 Then rhino.addtextdot k, center(k)
        Call Rhino.UnselectAllObjects
        Call Rhino.SelectObject(obj)
        'Call Rhino.Command (CStr("_smash LinearDirection=Natural _Enter Explode=No Labels=No _Enter"), vbFalse)       
        Call Rhino.Command (CStr("_smash _Enter _Enter"), vbFalse)       
        ReDim Preserve arrUnroll(k)
        arrUnroll(k) = Rhino.FirstObject
        If BestGuessSwitch=2 Then
            rhino.MoveObject arrUnroll(k),array(0,0,0),array((k Mod 10)*spacingfactor*spacing,(k\10)*spacingfactor*spacing,0)
            If ShowTagSwitch=1 Then rhino.addtextdot k&"'", array((k Mod 10)*spacingfactor*spacing,(k\10)*spacingfactor*spacing,0)
        End If
        If BestGuessSwitch=1 Then
            Dim vecMove:vecMove=rhino.vectorScale(rhino.VectorUnitize(_
                rhino.vectorcreate(center(k),allcenter)),((rhino.distance(center(k),allcenter)+spacingfactor*spacing)*2))
            rhino.MoveObject arrUnroll(k),array(0,0,0),array(vecMove(0),vecMove(1),0)
            If ShowTagSwitch=1 Then rhino.addtextdot k&"'", array(vecMove(0),vecMove(1),0)
        End If
    Next
    rhino.EnableRedraw True
End Function

Function SortSrfBySize (ByVal objs)
    Dim n:n=ubound(objs)
    Dim i,j,k,boxLong(),objtemp,boxcenter(),temp(2),boxLongTemp
    For k=0 To n       
        ReDim Preserve boxLong(k)
        boxLong(k)=rhino.distance(rhino.BoundingBox(objs(k))(0),rhino.BoundingBox(objs(k))(6))
    Next
    For i=0 To n-1
        For j=0 To n-1
            If j<n-1-i Then
                If boxLong(j)<boxLong(j+1) Then
                    objtemp=objs(j)
                    objs(j)=objs(j+1)
                    objs(j+1)=objtemp
                    boxLongTemp=boxLong(j)
                    boxLong(j)=boxLong(j+1)
                    boxLong(j+1)=boxLongTemp
                End If
            End If       
        Next       
    Next
    For k=0 To n       
        ReDim Preserve boxcenter(k)   
        boxcenter(k)=rhino.Pointscale(rhino.PointAdd(rhino.BoundingBox(objs(k))(0),rhino.BoundingBox(objs(K))(6)),0.5)
    Next

    temp(0)=objs
    temp(1)=boxLong
    temp(2)=boxcenter
    SortSrfBySize=temp
    'SortSrfBySize(0) are the sorted srfs ID
    'SortSrfBySize(1) are the sorted size dimension - SortSrfBySize(1)(0) is the biggest srf diaganal size
    'SortSrfBySize(2) are the array of the center points
End Function

2008年12月15日星期一

Plugin | Curve Real Distance Dividing

Snap1

This code is wrote for seeking certain points on a curve that the “real distances” are equal. It is providing two modes, similar to rhino curve divide, one is dividing by user input length, the other one is by numeric segment. Showing points and the polyline is optional too. 

The algorithmic on the back is the “divide and conquer”.

snap0401[4].jpg snap0400[4].jpg

 

download:

        rvb:                   plugin:

installation: drag the plugin to your rhino and you are all set.

Run it by typing command "xCurveDivRealDistance" or go to the menu "xTool".

2008年12月13日星期六

Plugin | even dividing lines

Snap1

The code is wrote for linework seating equally on the structure guides. Comparing to extracting UV isopalms , the benefit is the spacing is much more predictable. Plus, you don’t have to build a surface first for the UV lines – you can focus on working with construction lines.

[Snap6[5].jpg] [Snap5[4].jpg]

You need to have some construction guide for the linework.

then you can apply the code

[Snap7[4].jpg]

it is even concerned the circular conditions!

Here is another sample which you can see the difference:

[Snap1[4].jpg]  [Snap3[4].jpg]

extracted from UV rebuild: you can see some really dense area,where might hard to absorb architectural  element thickness

Here is much evener

download:

drug the rhp file into rhino and

Type in command “xEvenLines” to get it run