캐드에서 VBA를 이용한 두점과 수평력에 의한 현수선 그리기(Drawing 2 points & Hor. force catenary in Autocad using VBA)

캐드에서 VBA를 이용한 두점과 수평력에 의한 현수선 그리기(Drawing 2 points & Hor. force catenary in Autocad using VBA)

오토캐드에서 VBA로 두 점과 수평력으로 현수선 그리는 법입니다.
먼저 아래의 코드를 긁으시고
Private Function COSH(p As Double)
   
    COSH = (Exp(p) + Exp(-p)) / 2

End Function


Private Function SINH(p As Double)
   
    SINH = (Exp(p) - Exp(-p)) / 2

End Function

Private Function ASINH(p As Double)
   
    ASINH = Log(p + Sqr(p * p + 1))
   
End Function


Sub catenary2() '2points & Horizontal Force


Dim Pnt1, Pnt3 As Variant  '2points for catenary
    
    Pnt1 = ThisDrawing.Utility.GetPoint(, "1st Point")

    Pnt3 = ThisDrawing.Utility.GetPoint(, "2nd Point")
   

Dim w As Double
   
    w = InputBox("Uniform load")
   
Dim H As Double
   
    H = InputBox("Horizontal Force")


 Dim x1, x3, y1, y3, plusx, plusy As Double

    x1 = Pnt1(0) - Pnt1(0): x3 = Pnt3(0) - Pnt1(0)
    y1 = Pnt1(1) - Pnt1(1): y3 = Pnt3(1) - Pnt1(1)

 
    Dim L, hh As Double 'hh는 높이
        
        L = x3 - x1
        hh = y3 - y1

    Dim aa, bb, cc As Double

        aa = H / w
        bb = L / 2 - aa * ASINH(hh / (2 * aa * SINH(L / 2 / aa)))

Dim n As Integer '등분'

    n = InputBox("What is the number of divided catenary?")

    Dim interval As Double

        interval = (Pnt3(0) - Pnt1(0)) / n

    Dim polyPnt() As Double

    ReDim polyPnt(2 * n + 1) As Double

    Dim i As Integer

    For i = 0 To n

        polyPnt(i * 2) = x1 + interval * i
        polyPnt(i * 2 + 1) = aa * (COSH((polyPnt(i * 2) - bb) / aa) - COSH(bb / aa))

    Next i

    Dim Opnt1(2) As Double
    Dim Opnt2(2) As Double
   
        Opnt1(0) = 0: Opnt1(1) = 0: Opnt1(2) = 0
        Opnt2(0) = Pnt1(0): Opnt2(1) = Pnt1(1): Opnt2(2) = 0

      Dim polyObj As AcadLWPolyline

        Set polyObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(polyPnt)

        polyObj.Move Opnt1, Opnt2

End Sub
 
Tools(도구)의 Macro - Visual Basic Editor 로 들어갑니다. Modules에서 오른쪽 마우스 누르고 Insert - Module 를 선택합니다. 빈 칸에 코드를 붙여넣습니다.
 
이제 실행만 시키면 됩니다. F5 를 누르거나 Visual Basic Editor의 초록색 화살표를 누르면 실행이 됩니다. 캐드창에서 아무 곳이나 두점을 찍고 아래와 같이 현수선의 단위당 중량, 수평력을 치면 됩니다.
 
다음으로 분할 개수를 적으면 두점 과 수평력에 대한 현수선이 그려집니다.
* VBA(Visual Basic for Aplication)를 지원하는 캐드버전이어야 합니다.

댓글

Designed by JB FACTORY