Thursday, November 28, 2013

NanoCAD 5.0 มาแล้ว

ในที่สุดเราสามารถพัฒนา Application บน NanoCAD ได้แล้ว แถมเลือกได้หลายวิธีอีกด้วย

Download มาใช้งานกันเถอะ

Dowload NanoCAD
ต่อไปเราจะทดสอบการพัฒนา Application บน NanoCAD
  • Lisp
  • VBScript
  • Java Script

Lisp

NanoCAD รองรับ Lisp ที่เราเขียนไว้เดิมได้ทันที และรองรับ vl-lisp ที่ใช้ประจำอีกด้วย แต่กำลังทดสอบอยู่

VBScript

ของใหม่ ใช้ง่ายสำหรับท่านที่ใช้ VBA มาก่อน
Load ไฟล์ตัวอย่าง ด้านล่างสุดของหน้าเว็บ ไฟล์ demoscript.zip
หรือที่ demoscript.zip
Unzip ไฟล์ จะได้ VBScript ชื่อ demoscript.vbs



มาดู code กัน
Dim ms
Dim ut
Dim oLyrCone
Dim oLyrLine1
Dim LyrLine2
Dim SquareSize
Dim MaxX
Dim MaxY
Dim h
Dim x0
Dim y0
Dim Px
Dim Py

SquareSize = 25600
MaxX = 64000
MaxY = 48000

ThisDrawing.Utility.Prompt("Demonstration VBS-script, created by the example of LISP-program:")
ThisDrawing.Utility.Prompt("VBS-script was written 18.04.2012, by Nanosoft (www.nanocad.com)")
ThisDrawing.Utility.Prompt(" ")

Do
 count = ThisDrawing.Utility.GetInteger("Specify a positive number (>=1)")
Loop While count <= 0

h = SquareSize \ 4 ' integer division
x0 = MaxX \ 2  ' integer division
y0 = h + MaxY \ 2 ' integer division

Set oLyrCone = ThisDrawing.Layers.Add("Cone")
Set oLyrLine1 = ThisDrawing.Layers.Add("Connections")
Set oLyrLine2 = ThisDrawing.Layers.Add("Rectangles")

Dim oCone
Set oCone = ThisDrawing.ModelSpace.AddCone(CStr(x0)+","+CStr(y0-h)+","+CStr(SquareSize\2 - h\4), CStr(h), CStr(SquareSize))
oCone.Layer = oLyrCone.Name

for i = 1 to count
 ThisDrawing.Utility.Prompt("Iteration น" + CStr(i))
 x0 = x0 - h
 h = h \ 2
 y0 = y0 + h
 Px = x0
 Py = y0
 A(i)
 Line 1, h
 B(i)
 Line 3, h
 C(i)
 Line 5, h
 D(i)
 Line 7, h
next

' A(), B(), C() ่ D() are the recursive functions which draw the connection parts between "rectangles"
Sub A(k)
 if k > 0 then
  A(k-1)
  Line 1, h
  B(k-1)
  Line 0, 2 * h
  D(k-1)
  Line 7, h
  A(k-1)
 end if
End Sub

Sub B(k)
 if k > 0 then
  B(k-1)
  Line 3, h
  C(k-1)
  Line 2, 2 * h
  A(k-1)
  Line 1, h
  B(k-1)
 end if
End Sub

Sub C(k)
 if k > 0 then
  C(k-1)
  Line 5, h
  D(k-1)
  Line 4, 2 * h
  B(k-1)
  Line 3, h
  C(k-1)
 end if
End Sub

Sub D(k)
 if k > 0 then
  D(k-1)
  Line 7, h
  A(k-1)
  Line 6, 2 * h
  C(k-1)
  Line 5, h
  D(k-1)
 end if
End Sub

' lines rendering in the model space of the current drawing
' Direction - rendering direction 
' Size - "rectangle" size
Sub Line(Direction, Size)
 Dim oLine
 Dim oLyr
 x = Px
 y = Py
 Select Case Direction
  case 0:
   x = x + Size
   Set oLyr = oLyrLine2
  case 1:
   x = x + Size
   y = y - Size
   Set oLyr = oLyrLine1
  case 2:
   y = y - Size
   Set oLyr = oLyrLine2
  case 3:
   x = x - Size
   y = y - Size
   Set oLyr = oLyrLine1
  case 4:
   x = x - Size
   Set oLyr = oLyrLine2
  case 5:
   x = x - Size
   y = y + Size
   Set oLyr = oLyrLine1
  case 6:
   y = y + Size
   Set oLyr = oLyrLine2
  case 7:
   x = x + Size
   y = y + Size
   Set oLyr = oLyrLine1
 End Select
 Set oLine = ThisDrawing.ModelSpace.AddLine(CStr(Px)+","+CStr(Py)+","+CStr(Py), CStr(x)+","+CStr(y)+","+CStr(y))
 oLine.Layer = oLyr.Name
 Px = x
 Py = y
End Sub


Java Script

ของใหม่ สำหรับท่านที่ใช้ Java Script