Membuat Formasi Segi 6 Otomatis Sarang lebah di CorelDraw X7

Siapa yang tidak kenal sarang lebah? jika di lihat tampak muka bentuknya simetris terdiri dari kumpulan objek-objek polygon segi 6 yang tersusun rapih.
Taukah Anda meskipun demikian yang menjadi ajaib adalah lebah-lebah tersebut membuat sarang lebah tidak dari tengah atau 1 posisi, melainkan secara acak dari berbagai macam posisi, tapi akhirnya bisa menyatu dengan rapih. #Amazing.
Di CorelDraw anda bisa membuatnya dengan toolbox Polygon kemudian diatur sudutnya menjadi 6 bagian. Dan di duplikasi sebanyak yang anda inginkan dan diatur posisinya, dalam hal ini saya tidak ingin menjelaskan cara manualnya, karena ingin membahas cara otomatisnya menggunakan macro.

Berikut analisanya:
Analisa Susunan Sarang lebah Segi 6


  • Jumlah Baris : jumlah segi 6 di baris pertama di kali 2 dikurangi 1 (jb_pertama*2) -1
  • Pada baris pertama : Objek segi 6 berikutnya terbentuk dari duplikasi objek pertama digeser sejauh lebar segi 6
  • Pada baris ke dua : Jumlah segi enam di baris pertama ditambah 1, posisi digeser ke kiri sjauh 1/2 Lebar segi 6 dan digeser ke bawah sejauh 3/4 tinggi segi 6. Kemudian objek disusun posisinya dengan menggeser sejauh lebar segi 6 di kali posisinya.
Berikut kode formasi untuk model (pyramida + pyramida terbalik):

Sub TransformasiSegi6()

ActiveDocument.Unit = cdrMillimeter
Dim ObjekAsli As ShapeRange
Set ObjekAsli = ActiveSelectionRange
Dim dup1 As ShapeRange
Dim x As Double, y As Double

ObjekAsli.Cut ' Menghapus sementara dan di simpan di Memory Windows

' Coding : Desember 2014 | Ade Sanusi
' ========== Cara Penggunaan ============
' Buat Objek Segi Enam kemudian Seleksi
' Atur Jumlah Baris Pertama di bawah kemudian Jalankan macro

'Masukan Kode Anda ===========
jb_pertama = 7 ' Jumlah Objek di Baris Pertama Atur Sesuai yang anda inginkan

'jb = 6 'Jumlah Baris yang diinginkan ( Untuk Model Piramid atau Selang Seling )
jb = (jb_pertama * 2) - 1 'Jumlah Baris Otomatis ( Untuk Model Piramid + Piramid Terbalik )
For i = 0 To jb_pertama - 1
For j = 0 To jb_pertama - 1 + i
ActiveLayer.Paste
Set dup1 = ActiveSelectionRange
x = 1 / 2 * dup1.SizeWidth ' Untuk Menggeser Ke Kiri seberas 1/2 L
y = 3 / 4 * dup1.SizeHeight ' Untuk Menggeser ke Bawah sebesar 3/4 T
dup1.Move -(i * x), 0 'Objek yang di Copy di Geser dulu 1/2 L
dup1.Move (j * 2 * x), -(i * y) 'Objek di Cek berada di baris berapa, kemudain di kali posisi kanan, kemudian di kali posisi bawah,
Next j
Next i
For i = 0 To jb_pertama - 2
For j = 0 To jb_pertama - 1 + i
ActiveLayer.Paste
Set dup1 = ActiveSelectionRange
x = 1 / 2 * dup1.SizeWidth 'Objek yang di Copy di Geser dulu 1/2 L
y = 3 / 4 * dup1.SizeHeight ' Untuk Menggeser ke Bawah sebesar 3/4 T
dup1.Move -(i * x), -((jb - 1) * y) 'Di Atur ke Posisi Akhir Dulu
dup1.Move (j * 2 * x), (i * y) 'Objek di Cek berada di baris berapa, kemudain di kali posisi kanan, kemudian di kali posisi atas,
Next j
Next i

'===Akhir Kode Anda ====
End Sub


Maka hasilnya sebagai berikut :
Membuat Sarang Lebah Otomatis di CorelDraw dengan Macro

Berikut ini kode untuk model selang-seling :

Sub TransformasiSegi6SelangSeling()

ActiveDocument.Unit = cdrMillimeter
Dim ObjekAsli As ShapeRange
Set ObjekAsli = ActiveSelectionRange
Dim dup1 As ShapeRange
Dim x As Double, y As Double

ObjekAsli.Cut ' Menghapus sementara dan di simpan di Memory Windows

' Coding : Desember 2014 | Ade Sanusi
' ========== Cara Penggunaan ============
' Buat Objek Segi Enam kemudian Seleksi
' Atur Jumlah Baris Pertama di bawah kemudian Jalankan macro

'Masukan Kode Anda ===========

jb_pertama = 10 ' Jumlah Objek di Baris Pertama
jb = 6 'Jumlah Baris yang diinginkan
    offset_x = 2 'Untuk jarak antar segi 6 ke kanan
    offset_y = 2 ' Untuk jarak antar segi 6 ke bawah

For i = 0 To jb - 1
'If i <= jb_pertama - 1 Then
If i Mod 2 = 0 Then
akhir = jb_pertama - 1 'Boleh +1 atau -1
geser = 0
Else
akhir = jb_pertama
geser = 1
End If
For j = 0 To akhir
ActiveLayer.Paste
Set dup1 = ActiveSelectionRange
 x = (1 / 2 * dup1.SizeWidth) + (1/2 *offset_x)
 y = (3 / 4 * dup1.SizeHeight) + offset_y
dup1.Move -(geser * x), 0
dup1.Move (j * 2 * x), -(i * y)
Next j
'Else
'For j = 0 To (i - (jb_pertama - 1))

'Next j
'End If
Next i

Hasilnya sebagai berikut:

Anda juga bisa mengatur offset di bagian offset_x dan offset_ y untuk memberikan jarak antar segi 6.

Cara penggunaan macronya:
  • Alt + F11 di CorelDraw,
  • Cari GlobalMacros sebelah kiri bagian Projek Explorer
  • Cari CorelMacros trus double Clik modul tersebut dan masukan kode di atas di dalamnya
  • Kemudian Runing.
Demikian Tips Trik Membuat Sarang lebah Otomatis dengan Macro di CorelDraw #GRAFISin

Posting Komentar

6 Komentar

  1. bagaimanakah cara menyeleksi objek dengan jumlah node tertentu

    BalasHapus
    Balasan
    1. Sub SelectByNodes()
      Dim x#, y#, Smith As Shape, sh As Shape, sr As ShapeRange, _
      Shift As Long, B As Boolean, sr2 As ShapeRange, n&, ns&

      On Error GoTo myEnd
      ActiveDocument.BeginCommandGroup "SelectByNodes by JRM"
      Optimization = True

      If ActiveSelectionRange.Count = 0 Then MsgBox ("Nothing Selected"), vbCritical: GoTo myEnd

      Set sr = ActiveSelectionRange
      Set sr2 = New ShapeRange

      1001:
      If Not B Then
      B = ActiveDocument.GetUserClick(x, y, Shift, 15, False, cdrCursorEyeDrop) 'cdrCursorEyeDrop'cdrCursorEyeDrop

      Set Smith = ActivePage.SelectShapesAtPoint(x, y, True)
      Set Smith = Smith.Shapes.Last
      If ActiveShape Is Nothing Then MsgBox ("Nothing Selected"), vbInformation: GoTo 1001: Exit Sub

      If Smith.Type = cdrCurveShape Then
      n = Smith.Curve.Nodes.Count
      Else
      MsgBox ("Object Selected is not a curve shape"), vbInformation: GoTo myEnd
      End If
      End If

      Optimization = True
      For Each sh In sr
      If sh.Type = cdrCurveShape Then
      If sh.Curve.Nodes.All.Count = n Then sr2.Add sh
      End If
      Next sh
      sr.RemoveAll
      sr2.CreateSelection
      Optimization = False

      myEnd:
      sr.CreateSelection
      Optimization = False
      ActiveDocument.EndCommandGroup
      Application.Refresh
      ActiveWindow.Refresh
      End Sub

      Hapus
  2. memperbaiki kode sedikit ... salam 8)

    Sub TransformasiSegi6SelangSeling()
    Dim sr As ShapeRange, dup1 As ShapeRange, _
    x#, y#
    ActiveDocument.Unit = cdrMillimeter
    Set sr = ActiveSelectionRange
    If sr.Count < 1 Then MsgBox "tanpa objek yang dipilih", vbInformation: Exit Sub

    'sr.Cut ' Menghapus sementara dan di simpan di Memory Windows

    ' Coding : Desember 2014 | Ade Sanusi
    ' ========== Cara Penggunaan ============
    ' Buat Objek Segi Enam kemudian Seleksi
    ' Atur Jumlah Baris Pertama di bawah kemudian Jalankan macro

    'Masukan Kode Anda ===========
    ActiveDocument.BeginCommandGroup "duplicate now"
    Optimization = True

    jb_pertama = 5 ' Jumlah Objek di Baris Pertama
    jb = 6 'Jumlah Baris yang diinginkan
    offset_x = 0 'Untuk jarak antar segi 6 ke kanan
    offset_y = 0 ' Untuk jarak antar segi 6 ke bawah

    For i = 0 To jb - 1
    'If i <= jb_pertama - 1 Then
    If i Mod 2 = 0 Then
    akhir = jb_pertama - 1 'Boleh +1 atau -1
    geser = 0
    Else
    akhir = jb_pertama
    geser = 1
    End If

    For j = 0 To akhir
    Set dup1 = sr.Duplicate
    x = (1 / 2 * dup1.SizeWidth) + (1 / 2 * offset_x)
    y = (3 / 4 * dup1.SizeHeight) + offset_y
    dup1.Move -(geser * x), 0
    dup1.Move (j * 2 * x), -(i * y)
    Next j
    Next i

    ActiveSelection.Delete

    Optimization = False
    ActiveDocument.EndCommandGroup
    ActiveWindow.Refresh
    Application.Refresh
    End Sub

    -------------------------

    Sub TransformasiSegi6()
    Dim sr As ShapeRange, dup1 As ShapeRange, _
    x#, y#
    ActiveDocument.Unit = cdrMillimeter
    Set sr = ActiveSelectionRange
    If sr.Count < 1 Then MsgBox "tanpa objek yang dipilih", vbInformation: Exit Sub
    'sr.Cut ' Menghapus sementara dan di simpan di Memory Windows

    ' Coding : Desember 2014 | Ade Sanusi
    ' ========== Cara Penggunaan ============
    ' Buat Objek Segi Enam kemudian Seleksi
    ' Atur Jumlah Baris Pertama di bawah kemudian Jalankan macro

    'Masukan Kode Anda ===========
    jb_pertama = 7 ' Jumlah Objek di Baris Pertama Atur Sesuai yang anda inginkan
    ActiveDocument.BeginCommandGroup "duplicate now"
    Optimization = True

    'jb = 6 'Jumlah Baris yang diinginkan ( Untuk Model Piramid atau Selang Seling )
    jb = (jb_pertama * 2) - 1 'Jumlah Baris Otomatis ( Untuk Model Piramid + Piramid Terbalik )
    For i = 0 To jb_pertama - 1
    For j = 0 To jb_pertama - 1 + i
    'ActiveLayer.Paste
    Set dup1 = sr.Duplicate
    x = 1 / 2 * dup1.SizeWidth ' Untuk Menggeser Ke Kiri seberas 1/2 L
    y = 3 / 4 * dup1.SizeHeight ' Untuk Menggeser ke Bawah sebesar 3/4 T
    dup1.Move -(i * x), 0 'Objek yang di Copy di Geser dulu 1/2 L
    dup1.Move (j * 2 * x), -(i * y) 'Objek di Cek berada di baris berapa, kemudain di kali posisi kanan, kemudian di kali posisi bawah,
    Next j
    Next i
    For i = 0 To jb_pertama - 2
    For j = 0 To jb_pertama - 1 + i
    'ActiveLayer.Paste
    Set dup1 = sr.Duplicate
    x = 1 / 2 * dup1.SizeWidth 'Objek yang di Copy di Geser dulu 1/2 L
    y = 3 / 4 * dup1.SizeHeight ' Untuk Menggeser ke Bawah sebesar 3/4 T
    dup1.Move -(i * x), -((jb - 1) * y) 'Di Atur ke Posisi Akhir Dulu
    dup1.Move (j * 2 * x), (i * y) 'Objek di Cek berada di baris berapa, kemudain di kali posisi kanan, kemudian di kali posisi atas,
    Next j
    Next i
    ActiveSelection.Delete
    Optimization = False
    ActiveDocument.EndCommandGroup
    ActiveWindow.Refresh
    Application.Refresh
    '===Akhir Kode Anda ====
    End Sub

    BalasHapus
  3. mejorando el código 8)

    Sub TransformasiSegi6SelangSeling()
    Dim sr As ShapeRange, dup1 As ShapeRange, _
    x#, y#
    ActiveDocument.Unit = cdrMillimeter
    Set sr = ActiveSelectionRange
    If sr.Count < 1 Then MsgBox "tanpa objek yang dipilih", vbInformation: Exit Sub

    'sr.Cut ' Menghapus sementara dan di simpan di Memory Windows

    ' Coding : Desember 2014 | Ade Sanusi
    ' ========== Cara Penggunaan ============
    ' Buat Objek Segi Enam kemudian Seleksi
    ' Atur Jumlah Baris Pertama di bawah kemudian Jalankan macro

    'Masukan Kode Anda ===========
    ActiveDocument.BeginCommandGroup "duplicate now"
    Optimization = True

    jb_pertama = 5 ' Jumlah Objek di Baris Pertama
    jb = 6 'Jumlah Baris yang diinginkan
    offset_x = 0 'Untuk jarak antar segi 6 ke kanan
    offset_y = 0 ' Untuk jarak antar segi 6 ke bawah

    For i = 0 To jb - 1
    'If i <= jb_pertama - 1 Then
    If i Mod 2 = 0 Then
    akhir = jb_pertama - 1 'Boleh +1 atau -1
    geser = 0
    Else
    akhir = jb_pertama
    geser = 1
    End If

    For j = 0 To akhir
    Set dup1 = sr.Duplicate
    x = (1 / 2 * dup1.SizeWidth) + (1 / 2 * offset_x)
    y = (3 / 4 * dup1.SizeHeight) + offset_y
    dup1.Move -(geser * x), 0
    dup1.Move (j * 2 * x), -(i * y)
    Next j
    Next i

    ActiveSelection.Delete

    Optimization = False
    ActiveDocument.EndCommandGroup
    ActiveWindow.Refresh
    Application.Refresh
    End Sub
    Sub TransformasiSegi6()
    Dim sr As ShapeRange, dup1 As ShapeRange, _
    x#, y#
    ActiveDocument.Unit = cdrMillimeter
    Set sr = ActiveSelectionRange
    If sr.Count < 1 Then MsgBox "tanpa objek yang dipilih", vbInformation: Exit Sub
    'sr.Cut ' Menghapus sementara dan di simpan di Memory Windows

    ' Coding : Desember 2014 | Ade Sanusi
    ' ========== Cara Penggunaan ============
    ' Buat Objek Segi Enam kemudian Seleksi
    ' Atur Jumlah Baris Pertama di bawah kemudian Jalankan macro

    'Masukan Kode Anda ===========
    jb_pertama = 7 ' Jumlah Objek di Baris Pertama Atur Sesuai yang anda inginkan
    ActiveDocument.BeginCommandGroup "duplicate now"
    Optimization = True

    'jb = 6 'Jumlah Baris yang diinginkan ( Untuk Model Piramid atau Selang Seling )
    jb = (jb_pertama * 2) - 1 'Jumlah Baris Otomatis ( Untuk Model Piramid + Piramid Terbalik )
    For i = 0 To jb_pertama - 1
    For j = 0 To jb_pertama - 1 + i
    'ActiveLayer.Paste
    Set dup1 = sr.Duplicate
    x = 1 / 2 * dup1.SizeWidth ' Untuk Menggeser Ke Kiri seberas 1/2 L
    y = 3 / 4 * dup1.SizeHeight ' Untuk Menggeser ke Bawah sebesar 3/4 T
    dup1.Move -(i * x), 0 'Objek yang di Copy di Geser dulu 1/2 L
    dup1.Move (j * 2 * x), -(i * y) 'Objek di Cek berada di baris berapa, kemudain di kali posisi kanan, kemudian di kali posisi bawah,
    Next j
    Next i
    For i = 0 To jb_pertama - 2
    For j = 0 To jb_pertama - 1 + i
    'ActiveLayer.Paste
    Set dup1 = sr.Duplicate
    x = 1 / 2 * dup1.SizeWidth 'Objek yang di Copy di Geser dulu 1/2 L
    y = 3 / 4 * dup1.SizeHeight ' Untuk Menggeser ke Bawah sebesar 3/4 T
    dup1.Move -(i * x), -((jb - 1) * y) 'Di Atur ke Posisi Akhir Dulu
    dup1.Move (j * 2 * x), (i * y) 'Objek di Cek berada di baris berapa, kemudain di kali posisi kanan, kemudian di kali posisi atas,
    Next j
    Next i
    ActiveSelection.Delete
    Optimization = False
    ActiveDocument.EndCommandGroup
    ActiveWindow.Refresh
    Application.Refresh
    '===Akhir Kode Anda ====
    End Sub

    BalasHapus
  4. Sub SelectByNodes()
    Dim x#, y#, Smith As Shape, sh As Shape, sr As ShapeRange, _
    Shift As Long, B As Boolean, sr2 As ShapeRange, n&, ns&

    On Error GoTo myEnd
    ActiveDocument.BeginCommandGroup "SelectByNodes by JRM"
    Optimization = True

    If ActiveSelectionRange.Count = 0 Then MsgBox ("Nothing Selected"), vbCritical: GoTo myEnd

    Set sr = ActiveSelectionRange
    Set sr2 = New ShapeRange

    1001:
    If Not B Then
    B = ActiveDocument.GetUserClick(x, y, Shift, 15, False, cdrCursorEyeDrop) 'cdrCursorEyeDrop'cdrCursorEyeDrop

    Set Smith = ActivePage.SelectShapesAtPoint(x, y, True)
    Set Smith = Smith.Shapes.Last
    If ActiveShape Is Nothing Then MsgBox ("Nothing Selected"), vbInformation: GoTo 1001: Exit Sub

    If Smith.Type = cdrCurveShape Then
    n = Smith.Curve.Nodes.Count
    Else
    MsgBox ("Object Selected is not a curve shape"), vbInformation: GoTo myEnd
    End If
    End If

    Optimization = True
    For Each sh In sr
    If sh.Type = cdrCurveShape Then
    If sh.Curve.Nodes.All.Count = n Then sr2.Add sh
    End If
    Next sh
    sr.RemoveAll
    sr2.CreateSelection
    Optimization = False

    myEnd:
    sr.CreateSelection
    Optimization = False
    ActiveDocument.EndCommandGroup
    Application.Refresh
    ActiveWindow.Refresh
    End Sub

    BalasHapus