I am trying to reinvent the wheel by converting old VBA code to VLisp. I have gotten to the point of being able to draw a cylinder in WCS, but cant figure out how to read a line to determine the vector to create the cylinder. In VBA, we had to get the normal or the circle, and in VLisp, I am not seeing where this is located.
Public Sub DrawBus()
On Error GoTo err_control
Dim InsPt As Variant, dblRot As Double, strPrompt As String, intBusCenterLine As Integer
Dim strDrawing As String, dblBusDia As Double
Dim oLayer As AcadLayer, oLine As AcadLine
Dim newPT1 As Variant
Dim newPT2 As Variant
Dim P1, P2
Dim V(2) As Double, Unit As Double, Vn(2) As Double
Dim oCyl As Acad3DSolid, oCircle As AcadCircle
Dim regent(0) As AcadEntity
Dim oReg
Start:
IsSetup
frmBus.Show
If frmBus.optHighBus.Value = True Then
intBusCenterLine = RegistryEdit.getRegVal(HighBus)
Else
intBusCenterLine = RegistryEdit.getRegVal(LowBus)
End If
Select Case (getRegVal(BusSize))
Case "30"
dblBusDia = (3# / 2) + 0.25
Case "35"
dblBusDia = (3.5 / 2) + 0.25
Case "40"
dblBusDia = (4# / 2) + 0.25
Case "50"
dblBusDia = (5# / 2) + 0.25
End Select
Set oLayer = ThisDrawing.Layers.Add("3D-BUSS-CALC")
oLayer.color = 234
Dim objSelected As Object
Dim objSelSet As AcadSelectionSet
Set oLayer = ThisDrawing.Layers.Add("3D-BUSS")
oLayer.color = 3
Set objSelSet = ThisDrawing.SelectionSets.Add("Bus")
objSelSet.SelectOnScreen
For Each objSelected In objSelSet
If Not TypeOf objSelected Is AcadLine Then
MsgBox "That was not a Layout Line"
Exit Sub
End If
Set oLine = objSelected
newPT1 = oLine.StartPoint
newPT2 = oLine.EndPoint
newPT1(2) = intBusCenterLine
newPT2(2) = intBusCenterLine
Set oLine = ThisDrawing.ModelSpace.AddLine(newPT1, newPT2)
oLine.Layer = "3D-BUSS-CALC"
P1 = oLine.StartPoint: P2 = oLine.EndPoint
V(0) = P2(0) - P1(0): V(1) = P2(1) - P1(1): V(2) = P2(2) - P1(2)
'Normalise the vector(It's length=1)
Unit = Sqr(V(0) * V(0) + V(1) * V(1) + V(2) * V(2))
Vn(0) = V(0) / Unit: Vn(1) = V(1) / Unit: Vn(2) = V(2) / Unit
Set oCircle = ThisDrawing.ModelSpace.AddCircle(oLine.StartPoint, dblBusDia)
oCircle.Normal = Vn ' Vn or V both work here.
Set regent(0) = oCircle
oReg = ThisDrawing.ModelSpace.AddRegion(regent)
Set oCyl = ThisDrawing.ModelSpace.AddExtrudedSolid(oReg(0), oLine.Length, 0)
oCyl.Layer = "3D-BUSS"
oCircle.Delete
oReg(0).Delete
Next
ThisDrawing.SelectionSets.Item("Bus").Delete
ThisDrawing.Application.Update
Exit_Here:
ThisDrawing.SetVariable "INSUNITS", 1
Unload frmBus
Exit Sub
err_control:
Select Case Err.Number
Case "-2145320851"
ThisDrawing.SelectionSets.Item("Bus").Delete
Err.Clear
Resume
Case Else
MsgBox Err.Description
Resume Exit_Here
End Select
End Sub
In the middle of the above is the normalization of the vector. Can anyone point me in the direction to do this in VLisp