Region troubles

Discussion in 'AutoCAD' started by Nathan Guill, Jan 23, 2004.

  1. Nathan Guill

    Nathan Guill Guest

    The below code works, but no matter what I try, I can't erase the region in
    the code. I tried to declare objRegion as AcadRegion, but then the code
    doesn't make the solid.

    Does anyone know how to fix this?


    Function GetVolume(Optional Density As Double)
    Dim AxisPoint(0 To 2) As Double
    Dim AxisDir(0 To 2) As Double
    Dim basePnt As Variant
    Dim centerObj As AcadLine
    Dim objArray(0) As AcadEntity
    Dim objRegion As Variant
    Dim pLine As AcadLWPolyline
    Dim Response As VbMsgBoxResult
    Dim returnObj As AcadObject
    Dim strCenter As String

    On Error Resume Next

    ThisDrawing.Utility.InitializeUserInput 8
    Start:
    ThisDrawing.Utility.GetEntity returnObj, basePnt, _
    "Select cross-section for calculation: "

    If Not TypeOf returnObj Is AcadLWPolyline Then
    VBA.MsgBox "This entity is not a closed polyline," & VBA.vbCrLf & _
    "Please correct and run this program again.", vbCritical + vbOKOnly, _
    "Error"
    End
    Else
    Set pLine = returnObj
    If pLine.Closed = False Then
    VBA.MsgBox "This entity is not a closed polyline," & VBA.vbCrLf & _
    "Please correct and run this program again.", vbCritical + vbOKOnly,
    _
    "Error"
    End
    End If
    End If

    ThisDrawing.Utility.InitializeUserInput 1, "Xaxis Yaxis Object"

    ' Prompt the user to input any of the keywords.
    strCenter = ThisDrawing.Utility.GetKeyword("Select center line (Xaxis
    Yaxis Object):")

    ThisDrawing.Utility.InitializeUserInput 8

    Select Case strCenter
    Case "Xaxis"
    AxisPoint(0) = 0#: AxisPoint(1) = 0#: AxisPoint(2) = 0#
    AxisDir(0) = 10#: AxisDir(1) = 0#: AxisDir(2) = 0#
    Case "Yaxis"
    AxisPoint(0) = 0#: AxisPoint(1) = 0#: AxisPoint(2) = 0#
    AxisDir(0) = 0#: AxisDir(1) = 10#: AxisDir(2) = 0#
    Case "Object"
    ThisDrawing.Utility.GetEntity centerObj, basePnt, _
    "Select center line object: "
    AxisPoint(0) = centerObj.startPoint(0)
    AxisPoint(1) = centerObj.startPoint(1)
    AxisPoint(2) = centerObj.startPoint(2)
    AxisDir(0) = centerObj.endPoint(0)
    AxisDir(1) = centerObj.endPoint(1)
    AxisDir(2) = centerObj.endPoint(2)
    Case Else
    End
    End Select

    Set objArray(0) = pLine
    objRegion = ThisDrawing.ModelSpace.AddRegion(objArray)
    Set objSolid = ThisDrawing.ModelSpace.AddRevolvedSolid _
    (objRegion(0), AxisPoint, AxisDir, 6.28)

    ThisDrawing.Application.ActiveDocument.EndUndoMark

    If VBA.IsMissing(Density) Then
    VBA.MsgBox "The volume of this part is " & VBA.Format(objSolid.Volume, _
    "##,###,##0.0000")
    Else
    Weight = VBA.Format(objSolid.Volume * Density, "##,###,##0.00")
    VBA.MsgBox "This part weighs " & Weight
    End If

    objSolid.Delete

    ThisDrawing.Regen acAllViewports
    End Function
     
    Nathan Guill, Jan 23, 2004
    #1
  2. Nathan Guill

    Jeff Mishler Guest

    objRegion(0).Delete

    works for me....

    Jeff
     
    Jeff Mishler, Jan 23, 2004
    #2
  3. Nathan Guill

    Nathan Guill Guest

    Thanks. I just realised that since no options appeared when I entered
    objRegion(0). that I didn't try Delete at all.
     
    Nathan Guill, Jan 23, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.