Create a region from a polyline code?

Discussion in 'AutoCAD' started by pfeifern, Mar 17, 2005.

  1. pfeifern

    pfeifern Guest

    Does anyone have a sample VBA code for creating a region from a polyline. I can't figure it out.

    thanks,
    Nathan
     
    pfeifern, Mar 17, 2005
    #1
  2. pfeifern

    Jeff Mishler Guest

    This is very rudimentary, but it should give you a start....

    Code:
    Sub addRegion_Example()
    Dim oEnt As AcadEntity
    Dim vPick
    Dim oRegions
    Dim oRegObjects(0) As AcadEntity
    
    ThisDrawing.Utility.GetEntity oEnt, vPick, "Select pline to create region
    from: "
    If TypeOf oEnt Is AcadLWPolyline Then
    Set oRegObjects(0) = oEnt
    oRegions = ThisDrawing.ModelSpace.AddRegion(oRegObjects)
    End If
    End Sub
    
     
    Jeff Mishler, Mar 17, 2005
    #2
  3. pfeifern

    pfeifern Guest

    thanks for the post. Im actually looking to convert the following polyline code in to a region automatically (without having to pick).



    Sub Example_AddLightWeightPolyline()
    ' This example creates a light weight polyline in model space.

    Dim plineObj As AcadLWPolyline
    Dim points(0 To 9) As Double

    ' Define the 2D polyline points
    points(0) = 0: points(1) = 0
    points(2) = 2: points(3) = 0
    points(4) = 2: points(5) = 2
    points(6) = 0: points(7) = 2
    points(8) = 0: points(9) = 0

    ' Create a light weight Polyline object in model space
    Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)

    End Sub
     
    pfeifern, Mar 17, 2005
    #3
  4. pfeifern

    pfeifern Guest

    thanks for the post. Im actually looking to convert the following polyline code in to a region automatically (without having to pick).



    Sub Example_AddLightWeightPolyline()
    ' This example creates a light weight polyline in model space.

    Dim plineObj As AcadLWPolyline
    Dim points(0 To 9) As Double

    ' Define the 2D polyline points
    points(0) = 0: points(1) = 0
    points(2) = 2: points(3) = 0
    points(4) = 2: points(5) = 2
    points(6) = 0: points(7) = 2
    points(8) = 0: points(9) = 0

    ' Create a light weight Polyline object in model space
    Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)

    End Sub
     
    pfeifern, Mar 17, 2005
    #4
  5. pfeifern

    Joe Sutphin Guest

    Take the plineObj created by your code and poke it in the objRegObjects(0)
    array and you have it.

    Joe
     
    Joe Sutphin, Mar 17, 2005
    #5
  6. pfeifern

    pfeifern Guest

    thanks Joe, By the way I've got your book and it's becoming a great resource for me (im an AutoCAD vet, but new to the programming thing).
     
    pfeifern, Mar 18, 2005
    #6
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.