Message 1 of 2
Rotate solid object
Not applicable
01-29-2009
11:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
With the following code I am drawing a cylinder which I then want to get in a different orientation. At the moment it draws it vertically in WCS. How do I now get the object aligned along the 2 points I originally selected.
{Option Explicit
Public Sub Bolts()
Dim IntDiameter As Integer
Dim varPnt1 As Variant
Dim varPnt1UCS As Variant
Dim varPnt2 As Variant
Dim dblRadius As Double
Dim dblHeight As Double
Dim dblCenter(2) As Double
Dim objEnt As Acad3DSolid
IntDiameter = ThisDrawing.Utility.GetInteger("Input bolt diameter: ")
varPnt1 = ThisDrawing.Utility.GetPoint(, "Pick bolt head side")
varPnt1UCS = ThisDrawing.Utility.TranslateCoordinates(varPnt1, acWorld, acUCS, False)
varPnt2 = ThisDrawing.Utility.GetPoint(varPnt1UCS, "Pick nut side")
dblHeight = Distance(varPnt1, varPnt2)
dblRadius = IntDiameter / 2
'' calculate center point from input
dblCenter(0) = varPnt1(0)
dblCenter(1) = varPnt1(1)
dblCenter(2) = varPnt1(2) + (dblHeight / 2)
'' draw the entity
Set objEnt = ThisDrawing.ModelSpace.AddCylinder(dblCenter, dblRadius, dblHeight)
objEnt.Update
End Sub
Function Distance(P1, P2) As Variant
Dim xDist As Variant
Dim yDist As Variant
Dim zDist As Variant
xDist = P1(0) - P2(0)
yDist = P1(1) - P2(1)
zDist = P1(2) - P2(2)
Distance = Sqr(xDist ^ 2 + yDist ^ 2 + zDist ^ 2)
End Function}
{Option Explicit
Public Sub Bolts()
Dim IntDiameter As Integer
Dim varPnt1 As Variant
Dim varPnt1UCS As Variant
Dim varPnt2 As Variant
Dim dblRadius As Double
Dim dblHeight As Double
Dim dblCenter(2) As Double
Dim objEnt As Acad3DSolid
IntDiameter = ThisDrawing.Utility.GetInteger("Input bolt diameter: ")
varPnt1 = ThisDrawing.Utility.GetPoint(, "Pick bolt head side")
varPnt1UCS = ThisDrawing.Utility.TranslateCoordinates(varPnt1, acWorld, acUCS, False)
varPnt2 = ThisDrawing.Utility.GetPoint(varPnt1UCS, "Pick nut side")
dblHeight = Distance(varPnt1, varPnt2)
dblRadius = IntDiameter / 2
'' calculate center point from input
dblCenter(0) = varPnt1(0)
dblCenter(1) = varPnt1(1)
dblCenter(2) = varPnt1(2) + (dblHeight / 2)
'' draw the entity
Set objEnt = ThisDrawing.ModelSpace.AddCylinder(dblCenter, dblRadius, dblHeight)
objEnt.Update
End Sub
Function Distance(P1, P2) As Variant
Dim xDist As Variant
Dim yDist As Variant
Dim zDist As Variant
xDist = P1(0) - P2(0)
yDist = P1(1) - P2(1)
zDist = P1(2) - P2(2)
Distance = Sqr(xDist ^ 2 + yDist ^ 2 + zDist ^ 2)
End Function}