Anda di halaman 1dari 11

[XLS-SVY-007]: Plotting Cross Section dari Excel ke AutoCAD | coreta...

1 of 11

https://cadex.wordpress.com/2011/01/16/xls-svy-007-plotting-cross-se...

coretan tentang autocad dan excel

January 16, 2011

[XLS-SVY-007]: Plotting Cross Section dari Excel ke AutoCAD


Filed under: AutoCAD, Excel, Tukang Ukur Tags: cross section, Visual Basic Application cadex
@ 23:08
About
these ads
Referensi
:
[XLS-MAP-03]: Plo ing List Koordinat dari Excel ke AutoCAD
Platform

Excel dan AutoCAD

Lokasi File

xls-svy-007.zip

Rencananya program ini akan saya masukkan ke program perhitungan cut and ll cross section
dengan vba/macro. Tetapi mempertimbangkan bahwa untuk melakukan koneksi excel ke autocad
harus menggunakan library autocad yang sesuai dengan versi autocad yang sudah terinstall, maka
code koneksi ini tidak saya masukkan.
Saat saya menulis program ini, saya menggunakan AutoCAD versi 2011. Versi autocad yang lain dan
cara se ing di Visual Basic Application, silahkan membaca [XLS-MAP-03]: Plo ing List Koordinat
dari Excel ke AutoCAD di section Se ing Reference ke AutoCAD Library.
Code dalam visual basic application, saya bagi menjadi dua bagian yaitu Procedure Utama dan
Procedure/Function Pendukung. Procedure Utama adalah nama macro yang akan dijalankan
melalui menu excel, sedangkan procedure/function pendukung adalah procedure2 yang tidak
ditampilkan dalam menu macro di excel.
Procedure Utama:
Option Explicit
Dim appCAD As AcadApplication
Dim acadDoc As AcadDocument
Dim acadMspace As AcadModelSpace
Sub PlotGarisCrossSection()
Dim LstKoordExisting() As Double, LstKoordDesign() As Double
Dim BasePoint As Variant, OK As Boolean
OK = True
Membaca list koordinat existing dan design
If Not BacaListKoordinat(LstKoordExisting, Pilih List Koordinat Existing ) Then Exit Sub
If Not BacaListKoordinat(LstKoordDesign, Pilih List Koordinat Design ) Then Exit Sub

28/08/2014 9:07

[XLS-SVY-007]: Plotting Cross Section dari Excel ke AutoCAD | coreta...

2 of 11

https://cadex.wordpress.com/2011/01/16/xls-svy-007-plotting-cross-se...

Jika bisa connect autocad, ganti window ke autocad


If ConnectAutoCAD = Not OK Then Exit Sub
GantiWindowKeCAD
BasePoint = GetPointInCAD(Base Point) base point untuk menggambar cross section
Buat Layer dengan nama Existing
SetLayerAktif Existing
Plot Garis (Polyline) Existing di layer Existing
PlotGaris2D LstKoordExisting, CDbl(BasePoint(0)), CDbl(BasePoint(1))
Buat Layer dengan nama Design
SetLayerAktif Design
Plot Garis (Polyline) Design di layer Design
PlotGaris2D LstKoordDesign, CDbl(BasePoint(0)), CDbl(BasePoint(1))
plot label dengan jarak baris exiting =1, design =1, tinggi huruf=0.1
x_section_label CDbl(BasePoint(0)), CDbl(BasePoint(1)), 1, 1, 0.1
End Sub
Text warna biru adalah procedure atau function pendukung.
Procedure Pendukung (Private):
==private sub dan function====
=================
1. Objects Excel
=================
Private Function BacaListKoordinat(rtnListXY() As Double, ByVal strTitle As String) As Boolean
Dim aRange As Range, cr As Range
On Error GoTo Err_Trap:
Set aRange = Application.InputBox(Prompt:=strTitle, Type:=8)
If aRange.Columns.Count < 2 And aRange.Columns.Count > 2 Then
MsgBox List Koordinat Harus 2 (Dua) Kolom. Kolom Pertama X, Kolom Kedua Y
GoTo Err_Trap
End If
membaca koordinat x dan y, hasilnya disimpan di rtnListXY()
Dim i As Integer
i = -1
For Each cr In aRange.Columns(1).Cells
i=i+2
ReDim Preserve rtnListXY(i)
rtnListXY(i 1) = cr
rtnListXY(i) = cr.Oset(, 1)
Next
BacaListKoordinat = True
Exit Function
Err_Trap:
Err.Clear
BacaListKoordinat = False
End Function
==================

28/08/2014 9:07

[XLS-SVY-007]: Plotting Cross Section dari Excel ke AutoCAD | coreta...

3 of 11

https://cadex.wordpress.com/2011/01/16/xls-svy-007-plotting-cross-se...

2. Objects AutoCAD
==================
Private Function ConnectAutoCAD() As Boolean
On Error Resume Next
ConnectAutoCAD = True
Set appCAD = GetObject(, AutoCAD.Application)
Set acadDoc = appCAD.ActiveDocument
Set acadMspace = acadDoc.ModelSpace
If Err.Number Then
ConnectAutoCAD = False
Exit Function
End If
End Function
Private Sub GantiWindowKeCAD()
AppActivate appCAD.Caption
End Sub
Private Function GetPointInCAD(strPrompt As String) As Variant
GetPointInCAD = acadDoc.Utility.GetPoint(, strPrompt)
End Function
Private Sub SetLayerAktif(strNamaLayer As String)
Dim aLayer As AcadLayer
On Error Resume Next
Set aLayer = acadDoc.Layers(strNamaLayer)
If Err.Number Then
Err.Clear
Set aLayer = acadDoc.Layers.Add(strNamaLayer)
End If
acadDoc.ActiveLayer = aLayer
End Sub
Private Sub PlotGaris2D(ListTitik() As Double, Optional Xorigin As Double = 0, Optional Yorigin
As Double = 0)
Dim i As Integer
For i = LBound(ListTitik) To UBound(ListTitik) Step 2
ListTitik(i) = ListTitik(i) + Xorigin
ListTitik(i + 1) = ListTitik(i + 1) + Yorigin
Next i
acadMspace.AddLightWeightPolyline ListTitik
End Sub
Private Function GetOneEntity(ByVal strPrompt As String) As AcadEntity
Dim objEntity As AcadObject, PickedPoint(0 To 2) As Double
AppActivate appCAD.Caption
acadDoc.Utility.GetEntity objEntity, PickedPoint, strPrompt
Set GetOneEntity = objEntity
End Function
Private Sub x_section_label(Xorigin As Double, Yorigin As Double, _
TinggiBaris1 As Double, TinggiBaris2 As Double, TinggiHuruf As Double)
Dim anEntity As AcadEntity, polyExisting As AcadLWPolyline, polyDesign As AcadLWPolyline

28/08/2014 9:07

[XLS-SVY-007]: Plotting Cross Section dari Excel ke AutoCAD | coreta...

4 of 11

https://cadex.wordpress.com/2011/01/16/xls-svy-007-plotting-cross-se...

Dim aText As AcadText


Dim i As Integer, stLine(0 To 2) As Double, edLine(0 To 2) As Double, Xmin As Double, Xmax As
Double
Dim Existing_XY() As Double, Design_XY() As Double, Ymin As Double
Dim pntText(0 To 2) As Double, textRotation As Double
textRotation = Application.Radians(90)
Ymin = Yorigin TinggiBaris1 TinggiBaris2
Set anEntity = GetOneEntity(Pilih Polyline Existing)
If anEntity.ObjectName = AcDbPolyline Then
Set polyExisting = anEntity
Existing_XY = polyExisting.Coordinates
Xmin = Existing_XY(0)
gambar garis vertikal
SetLayerAktif Grid Existing
For i = LBound(Existing_XY) To UBound(Existing_XY) Step 2
stLine(0) = Existing_XY(i)
stLine(1) = Existing_XY(i + 1)
Xmax = stLine(0)
edLine(0) = stLine(0)
edLine(1) = Ymin
acadMspace.AddLine stLine, edLine
menulis text elevasi dan jarak
pntText(1) = Yorigin TinggiBaris1
Label jarak
pntText(0) = stLine(0) TinggiHuruf
Set aText = acadMspace.AddText(Format(stLine(0) Xorigin, 0.00), pntText, TinggiHuruf)
aText.Rotate pntText, textRotation
Label elevasi
pntText(0) = stLine(0) + TinggiHuruf
Set aText = acadMspace.AddText(Format(stLine(1) Yorigin, 0.00), pntText, TinggiHuruf)
aText.Rotate pntText, textRotation
Next i
End If
Gambar Garis Base Line
SetLayerAktif Datum
stLine(0) = Xmin: edLine(0) = Xmax
stLine(1) = Yorigin: edLine(1) = stLine(1)
acadMspace.AddLine stLine, edLine
stLine(0) = Xmin: edLine(0) = Xmax
stLine(1) = Yorigin TinggiBaris1: edLine(1) = stLine(1)
acadMspace.AddLine stLine, edLine
stLine(0) = Xmin: edLine(0) = Xmax
stLine(1) = Yorigin TinggiBaris1 TinggiBaris2: edLine(1) = stLine(1)
acadMspace.AddLine stLine, edLine

28/08/2014 9:07

[XLS-SVY-007]: Plotting Cross Section dari Excel ke AutoCAD | coreta...

5 of 11

https://cadex.wordpress.com/2011/01/16/xls-svy-007-plotting-cross-se...

Set anEntity = GetOneEntity(Pilih Polyline Design)


If anEntity.ObjectName = AcDbPolyline Then
Set polyDesign = anEntity
Design_XY = polyDesign.Coordinates
menggambar garis vertikal di layer grid design
SetLayerAktif Grid Design
For i = LBound(Design_XY) To UBound(Design_XY) Step 2
stLine(0) = Design_XY(i)
stLine(1) = Design_XY(i + 1)
edLine(0) = stLine(0)
edLine(1) = Ymin
acadMspace.AddLine stLine, edLine
menulis text elevasi dan jarak
pntText(1) = Yorigin TinggiBaris1 TinggiBaris2
Label jarak
pntText(0) = stLine(0) TinggiHuruf
Set aText = acadMspace.AddText(Format(stLine(0) Xorigin, 0.00), pntText, TinggiHuruf)
aText.Rotate pntText, textRotation
Label elevasi
pntText(0) = stLine(0) + TinggiHuruf
Set aText = acadMspace.AddText(Format(stLine(1) Yorigin, 0.00), pntText, TinggiHuruf)
aText.Rotate pntText, textRotation
Next i
End If
End Sub
===end private sub dan function
Download List Program (mdlPlot2CAD.bas)
Download contoh cross section (xls-svy-007.zip)
Menjalankan Makro
1. Buka Excel yang ada di le xls-svy-007.zip dan AutoCAD
2. Pada Program Excel tekan Alt+F11 untuk membuka Microsoft Visual Basic Editor
3. Di Microsoft Visual Basic Editor, tekan Ctr+M kemudian pilih le mdlPlot2CAD.bas yang sudah
didownload.
4. Se ing library ke AutoCAD yang ada di komputer Anda.
5. Keluar dari Microsoft Visual Basic Editor dengan menekan Alt+Q
6. Pada le xls-svy-007.xls, tekan Alt+F8 kemudian double click macro PlotGarisCrossSection

28/08/2014 9:07

[XLS-SVY-007]: Plotting Cross Section dari Excel ke AutoCAD | coreta...

6 of 11

https://cadex.wordpress.com/2011/01/16/xls-svy-007-plotting-cross-se...

Gunakan Mouse untuk mengeblok koordinat (oset, elevasi) Existing yaitu $Q$7:$R$57, kemudian
click OK. Akan muncul kotak dialog seperti di atas lagi, untuk memilih (mengeblok) koordinat design
yaitu $S$7:$T$11. Akhiri dengan click OK
7. Pindah ke program AutoCAD, jika program tidak pindah ke AutoCAD secara otomatis.
8. Di Autocad akan muncul prompt
Command: Base Point >> Click sembarang lokasi di AutoCAD
Command: Pilih Polyline Existing >> Pilih Polyline Existing di AutoCAD
Command: Pilih Polyline Design >> Pilih Polyline Design di autoCAD
9. Lakukan se ing warna Layer
10. Gambar cross section di AutoCAD, lengkap dengan label oset dan elevasi

selamat mencoba
==zainul==

28/08/2014 9:07

[XLS-SVY-007]: Plotting Cross Section dari Excel ke AutoCAD | coreta...

7 of 11

https://cadex.wordpress.com/2011/01/16/xls-svy-007-plotting-cross-se...

You May Like


1.

Comments (28)

28 Comments
1. thanks bgt boss
ilmunya
Comment by alakadarnya April 1, 2011 @ 14:22
Reply
2. setelah double click macro PlotGarisCrossSection kok muncul error gan
gmn mengatasinya?
Comment by epoyz November 23, 2011 @ 17:46
Reply
bisa kirim le excelnya dan informasi versi autocadnya ke zainul_ulum@yahoo.com
Comment by cadex November 24, 2011 @ 05:33
Reply
3. mas, bagaimna men-seting library pada poin 4 diatas? masih bingung nech hehehe
ka kasih sebelumnya ya mas..
Comment by weeil January 1, 2012 @ 11:18
Reply
4. mas, maksud dari point 4 apa? Se ing library ke AutoCAD yang ada di komputer Anda
ka ga ngerti saya, hehe. ma kasih sebelumnya ya!
Comment by weel January 1, 2012 @ 13:07
Reply
mas, pertanyaanku sudah terjawab kok mas, masalahnya muncul di point 8, pada cad
memang muncul prompt diatas, gambarnya yang ga jadi, cuma menghasilkan dua point saja
;(
Comment by weel January 1, 2012 @ 13:36

28/08/2014 9:07

[XLS-SVY-007]: Plotting Cross Section dari Excel ke AutoCAD | coreta...

8 of 11

https://cadex.wordpress.com/2011/01/16/xls-svy-007-plotting-cross-se...

Reply
apakah semua data sudah dipilih (block)?
Comment by cadex January 8, 2012 @ 23:19
5. mas, bagaimana cara menambahkan elevasix.. dengan kata lain kisa sdh se ing elevasi rencanax..
untuk di munculkan scr otomatis.. mkasiih
Comment by Abdulloh Ali May 25, 2012 @ 18:05
Reply
program belum support untuk elevasi design atau rencana.
Comment by cadex May 25, 2012 @ 20:24
Reply
6. gan,,,
command : base point ( di klik sembarang sudah)
command : pilih polyline existing ( nie maksudnya gimana ya )
command : pilih polyline design ( nie maksudnya gimana ya )
tolong dibantu gan karena tidak muncul otomatis ditempat saya.
Comment by andreas June 9, 2012 @ 09:47
Reply
apakah format isian datanya sesuai dengan le contohnya? jika sudah seharusnya tergambar
dua polyline existing dan design. apabila menu command: tidak muncul di autocad, cobat
tekan Ctrl+9 di autocad untuk menampilkan menu atau prompt command:
Comment by cadex June 9, 2012 @ 10:44
Reply
7. massy sdh ikuti semua langkahnya n sebelumnya berhasil, tapi kali ini di le yg berbeda koq
ga mau pindah otomatis ke autocad ya????tolong penjelasannya donk..
(autocad saya 2011 n excel 2007)
trims so much before. :)
Comment by Ri 23 June 20, 2012 @ 11:59
Reply
coba program baru di
h ps://cadex.wordpress.com/2012/05/16/xls-svy-13-plo ing-cross-section-dari-excelke-autocad-versi-1-0/
Comment by cadex June 20, 2012 @ 15:32
Reply
8. Assalamualaikum, bagaimana caranya saya merubah angka decimal daripada 2 decimal ke 3
decimal. Setelah saya cuba,
hasil text di autocad tetap 2 decimal. Saya telah mencuba versi terbaru namun saya gagal
melakukan operasinya , jadi saya cuba
versi sebelumnya dan ia berhasil. Terima kasih.

28/08/2014 9:07

[XLS-SVY-007]: Plotting Cross Section dari Excel ke AutoCAD | coreta...

9 of 11

https://cadex.wordpress.com/2011/01/16/xls-svy-007-plotting-cross-se...

Comment by Mazele Mohamad January 16, 2013 @ 18:06


Reply
9. waalaikum salam,
salam kenal. thanks for visiting my blog.
Comment by cadex January 18, 2013 @ 09:06
Reply
10. makasi buat ilmunya mas,, salam kenal
mau nanya sedikit untuk tampilan cross section di autocad utk label elevasix bs dirubah ke arah
sumbu Y gk..?
makasi
Comment by eka February 19, 2013 @ 13:47
Reply
11. mas..mau tanyasaya udh coba cara ini sampai langkah terakhir, tapi koq label oset dan elevasi
serta layer yg lain (kecuali layer existing) gak ada yang muncul di autocad(autocad yang saya
pakai autocad 2011)trims sebelumnya
Comment by Joeantho March 24, 2013 @ 02:56
Reply
12. Cek apakah pemisah desimal di excel menggunakan , koma atau . titik? .Jika pemisah
desimal adalah , koma rubah ke . titik
Comment by cadex March 24, 2013 @ 09:37
Reply
13. mas kenapa tabel oset ,ukuran dimensi dibawah cross section tidak muncul saat jalankan
program
Comment by wan September 26, 2013 @ 01:53
Reply
memang nggak muncul dimensi krn tidak terpogram. atau program yang saya buat tidak
menampilkan dimensi yang dimaksud
Comment by cadex September 26, 2013 @ 08:03
Reply
14. yang memunculkan dimensi bisa gak mas dibuat programnya
Comment by wan October 6, 2013 @ 13:53
Reply
memunculkan dimensi sangat tergantung dari client jadi tidak bisa dibuat secara general.
sebetulnya dari label oset dan elevasi, bisa diketahui juga dimensinya. Sebenarnya dengan
vba bisa juga dibuat programmnya tetapi terus terang saya belum pernah membuat.
Comment by cadex October 14, 2013 @ 08:43
Reply

28/08/2014 9:07

[XLS-SVY-007]: Plotting Cross Section dari Excel ke AutoCAD | coreta...

10 of 11

https://cadex.wordpress.com/2011/01/16/xls-svy-007-plotting-cross-se...

15. mas kalau misalnya garis vertikalnya sy mau buat dengan skala tertentu gimana caranya?
Comment by yogi nugroho December 20, 2013 @ 15:57
Reply
silakan dicoba h ps://cadex.wordpress.com/2012/05/16/xls-svy-13-plo ing-cross-sectiondari-excel-ke-autocad-versi-1-0
Comment by cadex December 21, 2013 @ 06:07
Reply
16. Assallamualaikum Warrohmatullohi Wabarokatuh
Mas Zainul , di program mas di poin jarak itu kan akumulatif jarak yang terploting,
bagaimana caranya yang terploting itu jarak antar titiknya.
mohon bantuan dari mas zainul.
wassallam
Comment by wahyudi wibowo May 23, 2014 @ 09:45
Reply
Waalaikum salam Wr. Wb.
harus dirubah coding programnya Mas. Sampai saat ini belum sempat merubah
Comment by cadex June 2, 2014 @ 10:31
Reply
17. Ass.. Mas Zainul, program mas Zainul bisa g dibuatkan langkah2nya dari awal memproses data
ukur di excel sampai dengan memplo ing ke autocad dalam bentuk buku panduan. nanti aku
beli deh mas. tolong infonya. Aku sangat butuh program ini mas. aku tunggu infonya di email
saya suryantopakiding@gmail.com
sukses selalu utk Mas Zainul..
Comment by suryanto July 30, 2014 @ 09:14
Reply
program yang saya buat ini dipakai untuk hasil pengukuran cross section metode jarak/oset
dan elevasi. Alat yang dipakai bisa menggunakan total station atau waterpass.
Biasanya saat mengukur cross section pakai alat apa?
Comment by cadex August 5, 2014 @ 10:22
Reply
RSS (Really Simple Syndication) feed for comments on this post. TrackBack URI (Uniform Resource
Identier)
The Shocking Blue Green Theme. Create a free website or blog at WordPress.com.
Follow

28/08/2014 9:07

[XLS-SVY-007]: Plotting Cross Section dari Excel ke AutoCAD | coreta...

11 of 11

https://cadex.wordpress.com/2011/01/16/xls-svy-007-plotting-cross-se...

Follow coretan tentang autocad dan excel


Powered by WordPress.com

28/08/2014 9:07

Anda mungkin juga menyukai