Author Topic: select outside circle DWGeditor help  (Read 3558 times)

0 Members and 1 Guest are viewing this topic.

hsheet

  • Guest
select outside circle DWGeditor help
« on: January 15, 2010, 02:54:51 PM »
I have a rectangular array of points which I would like to modify.  I want to erase points which lie outside of a circular area.  I would simply use the erase command and select the outside circle option if I were to do it manually, but cannot comprehend how to do this in VBA.  I assume I need to create a selection set of the points I would like to delete using the select method of type vicSelectionSetOutsideCircle, but I don't understand how that type is invoked.  Can someone explain its syntax to me?

Bryco

  • Water Moccasin
  • Posts: 1883
Re: select outside circle DWGeditor help
« Reply #1 on: January 16, 2010, 08:36:01 PM »
 if the point is further away from the circle center than the radius ditch it,
and welcome

fixo

  • Guest
Re: select outside circle DWGeditor help
« Reply #2 on: January 17, 2010, 07:12:40 AM »
I have a rectangular array of points which I would like to modify.  I want to erase points which lie outside of a circular area.  I would simply use the erase command and select the outside circle option if I were to do it manually, but cannot comprehend how to do this in VBA.  I assume I need to create a selection set of the points I would like to delete using the select method of type vicSelectionSetOutsideCircle, but I don't understand how that type is invoked.  Can someone explain its syntax to me?

As Bryco said:
Code: [Select]
Option Explicit

Sub DelOutSide()
    Dim oSSet As AcadSelectionSet
    Dim delSet As AcadSelectionSet
    Dim oEnt As AcadEntity
    Dim oCircle As AcadCircle
    Dim oPoint As AcadPoint
    Dim cp As Variant
    Dim varp As Variant
    Dim rad As Double
    Dim ftype(0) As Integer
    Dim fdata(0) As Variant
    Dim dxfCode, dxfValue
    Dim name As String
    Dim count As Integer

    On Error GoTo Err_Control

    With ThisDrawing.SelectionSets
        While .count > 0
            .Item(0).Delete
        Wend
        Set oSSet = .Add("$Points$")
        Set delSet = .Add("$Delete$")
    End With
    ftype(0) = 0: fdata(0) = "POINT"
    dxfCode = ftype: dxfValue = fdata

    ThisDrawing.Utility.GetEntity oEnt, varp, vbLf & "Select circle:"
    If Not TypeOf oEnt Is AcadCircle Then
        Exit Sub
    End If
    Set oCircle = oEnt
    cp = oCircle.Center
    rad = oCircle.Radius
    oSSet.SelectOnScreen dxfCode, dxfValue

    For Each oEnt In oSSet
        Set oPoint = oEnt
        varp = oPoint.Coordinates
        If Distance(varp, cp) > rad Then
            Dim varobj(0) As AcadEntity
            Set varobj(0) = oEnt
            delSet.AddItems (varobj)
        End If
    Next
    MsgBox delSet.count
    delSet.Erase

Exit_Here:
    Exit Sub

Err_Control:
    If Err.Number <> 0 Then
        MsgBox Err.Description
        Err.Clear
    End If
    Resume Exit_Here

End Sub
'' by Frank Oquendo
Public Function Distance(fPoint As Variant, sPoint As Variant) As Double

    Dim x1 As Double, x2 As Double
    Dim y1 As Double, y2 As Double
    Dim z1 As Double, z2 As Double
    Dim cDist As Double

    x1 = fPoint(0): y1 = fPoint(1): z1 = fPoint(2)
    x2 = sPoint(0): y2 = sPoint(1): z2 = sPoint(2)

    cDist = Sqr(((x2 - x1) ^ 2) + ((y2 - y1) ^ 2) + ((z2 - z1) ^ 2))
    Distance = cDist

End Function

~'J'~

hsheet

  • Guest
Re: select outside circle DWGeditor help
« Reply #3 on: January 18, 2010, 10:16:25 AM »
Thanks for the help. 

fixo

  • Guest
Re: select outside circle DWGeditor help
« Reply #4 on: January 18, 2010, 05:39:52 PM »
Thanks for the help. 
Glad to help

Cheers :)

~'J'~