Showing posts with label 라이노스크립트. Show all posts
Showing posts with label 라이노스크립트. Show all posts

February 21, 2012

RhinoScript | Black&White gradient

얼마 전 MeshHighlightField 커맨드를 활용하여 타이어 패턴 디자인 이미지의 그라디언트로 부조형상을 만들어 모델링 작업을 최소화하여 3D프린팅이 가능하도록 프로세스 설정하는 교육을 진행하였다. 필요한 형상의 높이 변화에 알맞는 그라디언트 이미지를 조금 쉽게 만들 수 있는 스크립트를 만들어 사용하였는데, x,y좌표 (0,0)에서 (10,10)사이에 하나의 커브를 그려주면 y값 0-10을 밝기 0-255로 변환하여 이미지 그라디언트를 만들어 준다.

다음 스크립트는 GDI bitmap extension인 RhPicture를 사용하기에 설치되어있어야 사용가능하다. http://wiki.mcneel.com/developer/rhinoscriptimageextension 그리고 LineCurveIntersection method를 사용하기에 라이노 V5에서 사용할 수 있다. V4용으로는 일부 수정이 필요하다.

Option explicit
Call Main()
Sub Main()
    Dim strCrv    
    strCrv = Rhino.GetObject("Select a gradient curve", 4, True)
    If isNull(strCrv) Then Exit Sub
    Dim arrFace(0), arrVertices(3)
    Dim i, x, arrLine, arrCX, arrP, lngColor, H, arrC, j
    Dim RhPicture
    Set RhPicture = Rhino.GetPluginObject("RhPicture")
    Call RhPicture.CreateImage(200, 255, vbWhite)
    For i=0 To 255
        x = i / 25.5
        arrLine = array(array(x, 0, 0), array(x, 10, 0))
        arrCX = Rhino.LineCurveIntersection(arrLine, strCrv)
        If isArray(arrCX) Then
            arrP = arrCX(0, 1)
            H = round(arrP(1) * 25.5)
            lngColor = RGB(H, H, H)
            For j=0 To 200
                Call RhPicture.SetPixel(j, 255 - i, lngColor)
            Next
        End If           
    Next
    Call RhPicture.ShowImage("Black&White Gradient")           
    Set RhPicture = Nothing
End Sub


February 9, 2010

Let it go straight on

곡면을 하나 생성한 뒤에 그 곡면 위에서 방향을 하나 설정하여 그 방향으로 계속 이어지는 직선을 그려보면 곡면 위에 한 선으로 그려진 곡선을 얻을 수 있다. 라이노 스크립트를 이용해서 앞의 과정을 수행한 후 그 곡선에 Smooth, Fair 커맨드를 이용해 보았다. 가상의 3d 공간 상에서는 쉽게 존재하는 것들이 실제에서는 힘든 경우가 많은데 이것도 그런 경우인 듯 하다.

February 15, 2009

RhinoScript | Print Layout pages to Pdf files with Bullzip Pdf printer

지난 주말 도면 작업을 할 일이 있어 Layout 기능을 활용해 쉽게 작업할 수 있었다. 그런데, 여러장의 Layout을 사용하다 보니, 일일히 프린트 하는 것이 문제가 될줄이야...
Rhino의 Print 커맨드가 여러장을 선택적으로 프린트 하는 기능이 없어, 여러가지 방법을 생각하다가 Pdf printer를 이용하는 방법을 시도해보았다.

Bullzip Pdf printer는 문서출력의 결과를 Pdf파일로 저장해주는 가상 프린터이다.여러종류의 pdf프린터가 있지만, Bullzip은 무료로 쓸수 있으면서도 많은 기능을 제공한다. COM/ActiveX interface도 제공하기에 스크립트를 이용한 자동화를 가능 하다.
http://www.bullzip.com/products/pdf/info.php

아래 스크립트를 이용하기 위해서는 Bullzip printer가 설치되어 있어야 한다. 그리고 Page Layout이 있어야 하며 모든 Layout을 pdf파일로 저장한다. 하나의 파일로 저장할지, 각각의 파일로 저장할지 선택할 수 있다. 물론 각 Layout의 프린터를 Bullzip pdf printer로 설정되어 있어야 한다. 프린트를 할때 뿐만 아니라 pdf파일을 생성하기 위한 도구로도 사용이 가능해보인다.


Option Explicit
'2009.2.15
'Script by Sanghoon Yoon @ +plastic
'http://www.byRhino3d.com | http://www.rhinos.co.kr | http://sac3.blogspot.com
'sac3yoon@gmail.com
'This script let Rhino to print all layout pages as pdf files through Bullzip pdf printer.
'Download Bullzip pdf printer @ http://www.bullzip.com/products/pdf/info.php

PrintLayoutAsPDF
Sub PrintLayoutAsPDF
Dim strSS
strSS = Rhino.GetString ("File option" , "As_one_Pdf", Array ("As_one_Pdf", "As_each_Pdf") )
If IsNull(strSS) Then Exit Sub
Select Case strSS
Case "As_one_Pdf"
SaveAsOnePdf
Case "As_each_Pdf"
SaveAsEachPdf
End Select
End Sub

Sub SaveAsEachPdf()
Dim strFile,strFolder, arrViews,fileName, strM
strM=""
strFolder = Rhino.BrowseForFolder
arrViews = Rhino.ViewNames (True ,1)
If IsNull(arrViews) Then Rhino.Print "No layout pages!" : Exit Sub
For Each fileName In arrViews
Rhino.CurrentView fileName
strFile=strFolder&fileName&".pdf"
BatchPrint strFile,strM
Rhino.Print strFile&" was created."
Next
End Sub

Sub SaveAsOnePdf()
Dim strFile,strFolder, arrViews,fileName
strFile= Rhino.SaveFileName ("Save as pdf" ,"pdf files (*.pdf)|*.pdf||" , "" , ,"pdf")
arrViews = Rhino.ViewNames (True ,1)
If IsNull(arrViews) Then Rhino.Print "No layout pages!" : Exit Sub
For Each fileName In arrViews
Rhino.CurrentView fileName
BatchPrint strFile,strFile
Next
Rhino.Print strFile&" was created."
End Sub

Function BatchPrint(strFile,strM)
Const PDF_PRINTERNAME = "Bullzip PDF Printer"
Const PRINTER_PROGID = "Bullzip.PDFPrinterSettings"
Dim prtidx, obj
'Configure the PDF print job
Set obj = CreateObject(PRINTER_PROGID)
obj.SetValue "mergefile",strM
obj.SetValue "mergeposition","bottom"
obj.SetValue "Output", strFile
obj.SetValue "ConfirmOverwrite", "no"
obj.SetValue "ShowSaveAS", "never"
obj.SetValue "ShowSettings", "never"
obj.SetValue "ShowPDF", "no"
obj.SetValue "RememberLastFileName", "no"
obj.SetValue "RememberLastFolderName", "no"
obj.WriteSettings True

Rhino.Command "-print go ",False

'Wait for runonce settings file to disappear
Dim runonce, fso
runonce = obj.GetSettingsFileName(True)
Set fso = CreateObject("Scripting.FileSystemObject")
While fso.FileExists(runonce)=True
Sleep 100
Wend
End Function