Author Topic: Lisp results based on external data  (Read 9767 times)

0 Members and 1 Guest are viewing this topic.


  • Guest
Lisp results based on external data
« Reply #30 on: November 20, 2003, 07:26:39 AM »
ok, here's something to get you started....

create userform with 5 textboxes and 1 command button as shown above, double-click the command button and add this code....
Code: [Select]

Private Sub CommandButton1_Click()
 Dim length As Double, width As Double, height As Double
 Dim boxObj As Acad3DSolid
 Dim center As Variant
 Dim BoxPnt As Variant
 Dim cylinderObj As Acad3DSolid
 Dim radius As Double
 Dim Cylcen As Variant
 Dim Cylheight As Double
' get data for the box, first get the insertion point from user
    BoxPnt = ThisDrawing.Utility.GetPoint(, "Enter a point for centre of box: ")
    length = TextBox1.Value
    width = TextBox2.Value
    height = TextBox3.Value
' now create the box
 Set boxObj = ThisDrawing.ModelSpace.AddBox(BoxPnt, length, width, height)
' before we can add the cylinder, we need to define a new UCS and set it current
' So, let's get the current UCS so we can restore it later
 Dim UCSColl As AcadUCSs
    Set UCSColl = ThisDrawing.UserCoordinateSystems
 Dim ucsObj As AcadUCS
 Dim CurrUCS As AcadUCS
    Set CurrUCS = ThisDrawing.ActiveUCS
' Now change the viewing direction so it's easier to place the cylinder
 Dim NewDirection(0 To 2) As Double
        NewDirection(0) = -1: NewDirection(1) = -1: NewDirection(2) = 1
        ThisDrawing.ActiveViewport.Direction = NewDirection
        ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport
    ZoomAll ' so we can see the box we just created
' Now we can create the new UCS by picking 3 points on a box face
    Dim origin As Variant
    Dim xAxisPnt As Variant
    Dim yAxisPnt As Variant
        origin = ThisDrawing.Utility.GetPoint(, "Enter ORIGIN point for face: ")
        xAxisPnt = ThisDrawing.Utility.GetPoint(, "Enter point on X Axis : ")
        yAxisPnt = ThisDrawing.Utility.GetPoint(, "Enter point on Y Axis : ")
    Set ucsObj = UCSColl.Add(origin, xAxisPnt, yAxisPnt, "Face1")
    ThisDrawing.ActiveUCS = ucsObj
' now get the cylinder values from the form
    radius = TextBox4.Value
    Cylheight = TextBox5.Value
 ' now get the insertion point of the cylinder
    Cylcen = ThisDrawing.Utility.GetPoint(, "Enter a point for centre of cylinder: ")
 ' and since we've got the point in the World UCS we need to convert it to our new UCS
  Cylcen = ThisDrawing.Utility.TranslateCoordinates(Cylcen, acWorld, acUCS, False)
    Dim Cyl(0 To 2) As Double
        Cyl(0) = Cylcen(0)
        Cyl(1) = Cylcen(1)
' but since the solid is created using the picked point as the object CENTRE, we
' need to change the "Z" value so that the object is created on the face of the box
        Cyl(2) = 0 + (Cylheight / 2)
' and create the cylinder
 Set cylinderObj = ThisDrawing.ModelSpace.AddCylinder(Cyl, radius, Cylheight)
' then transform it to our new UCS
 Dim TransMatrix As Variant
    TransMatrix = ucsObj.GetUCSMatrix()
    cylinderObj.TransformBy (TransMatrix)

Unload Me
End Sub

I've given this as an example. It will prompt you for an insertion point for the "box", then ask for 3 points for a new UCS, then create the cylinder on the new UCS.
At least it should get you started.