divide a line

Discussion in 'AutoCAD' started by cmedinag, Feb 24, 2005.

  1. cmedinag

    cmedinag Guest

    hi! i want to know how to divide a line into multiple little lines, with a for cicle or something, so it can be divided many times. thanks!
     
    cmedinag, Feb 24, 2005
    #1
  2. cmedinag

    MP Guest

    for cicle or something, so it can be divided many times. thanks!

    'just some quick pseudo code to give the general idea
    'syntax likely not correct check help for details
    'dimension variables
    'oLineOrig as AcadLine etc
    'dLen as Double, lDiv as Long, etc etc
    'Get the line
    set oLineOrig = 'select or iterate or however you identify the original line
    'get the length
    dLen = oLineOrig.Length
    'get the number of divisions
    lDiv = 'prompt for input or get from form or ???
    'calc length of new lines
    dNewLen = dLen / lDiv
    'get startpoint
    vStPt = oLineOrig.Startpoint
    'get the angle
    dAng = oLineOrig.Angle
    'was orig line in modelspace,paperspace or a block?
    Set oOwner = oLineOrig.Owner
    'create new lines
    for lIdx = 1 to lDiv
    oOwner.AddLine vStPt, ThisDrawing.Utility.PolarPoint( vStPt, dAng,
    dNewLen)
    'adjust startpoint for next line
    vStPt = ThisDrawing.Utility.PolarPoint( vStPt, dAng, dNewLen)
    next lIdx
    'erase orig line if req'd
    oLineOrig.Delete

    hth
    Mark
     
    MP, Feb 24, 2005
    #2
  3. cmedinag

    cmedinag Guest

    hi, thanks for the tip, i tried to implement it but it doesn't seem to be working. this is the code... im new in VB and dont know how to make it work...

    Public Sub Separado2()

    Dim oLineOrig As AcadLine
    Dim dLen As Double
    Dim iDiv As Integer
    Dim newLen As Double
    Dim varStPt As Variant
    Dim ang As Double
    Dim oOwner As Object
    Dim idlX As Integer



    On Error Resume Next

    With ThisDrawing.Utility
    ''OBTENER LINEA ORIGINAL
    Set oLineOrig = .GetLine(, vbCr & "Seleccione la linea a dividir: ")
    dLen = oLineOrig.Length
    intDiv = .GetInteger(vbCr & "Cuantos puntos desea agregar a ese segmento?: ")
    newLen = dLen / iDiv
    varStPt = oLineOrig.StartPoint
    ang = oLineOrig.Angle
    Set oOwner = oLineOrig.Owner

    For idlX = 1 To iDiv
    oOwner.AddLine varStPt, ThisDrawing, Utilily.PolarPoint(varStPt, ang, newLen)
    varStPt = ThisDrawing.Utility.PolarPoint(varStPt, ang, newLen)
    Next idlX

    oLineOrig.Delete
    MsgBox ("Se ha dividido la linea")
    End With

    End Sub

    thanks!
     
    cmedinag, Feb 24, 2005
    #3
  4. Sub ChopLine()

    Dim returnObj As AcadObject
    Dim lineObj As AcadLine
    Dim copyObj As AcadLine
    Dim nextCopyObj As AcadLine
    Dim lCurDiv As Long
    Dim lNumDiv As Long
    Dim basePnt As Variant

    Do

    On Error Resume Next

    ' The following example waits for a selection from the user

    ThisDrawing.Utility.GetEntity returnObj, basePnt, "Select a line"

    If Err <> 0 Then
    Err.Clear
    Exit Sub
    Else

    On Error GoTo 0

    If TypeOf returnObj Is AcadLine Then
    Set lineObj = returnObj
    Set copyObj = lineObj.Copy

    lNumDiv = Int(Val(InputBox("Number of Divisions?", "Line Divide
    Info", "2")))
    If lNumDiv < 1 Then Exit Sub

    copyObj.ScaleEntity copyObj.StartPoint, 1 / lNumDiv
    For lCurDiv = 1 To lNumDiv - 1
    Set nextCopyObj = copyObj.Copy
    nextCopyObj.Move copyObj.StartPoint, copyObj.EndPoint
    Set copyObj = nextCopyObj
    Next 'lCurDiv

    'lineobj.Delete 'uncomment if you want to delete original
    line

    End If
    End If

    Loop


    End Sub


    working. this is the code... im new in VB and dont know how to make it
    work...
    Utilily.PolarPoint(varStPt, ang, newLen)
     
    James Belshan, Feb 24, 2005
    #4
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.