how to copy a line to another layer in vba

Discussion in 'AutoCAD' started by Vrijbuiter, Jun 10, 2007.

  1. Vrijbuiter

    Vrijbuiter Guest

    Hello,

    Can anyone tell me how I can copy a line from one layer to another
    layer with vba, not move but copy line.

    Thanks and with best regards,

    Alexander from the Netherlands
     
    Vrijbuiter, Jun 10, 2007
    #1
  2. Vrijbuiter

    Rodrigues Guest

    Public Function isAcadLine(obj As Object) As Boolean
    Dim line1 As AcadLine
    On Error GoTo fim
    Set line1 = obj
    isAcadLine = True
    Exit Function
    fim:
    isAcadLine = False
    End Function





    sub copy_line
    dim obj as object
    dim line1 as AcadLine, line2 as Acadline

    for each obj in Thisdrawing.Modelspace
    if IsAcadLine(obj)=True then
    set line1=obj
    set line2=line1.copy
    line2.layer = "the name of the layer you want to place the
    copy"
    end if
    next obj

    end sub



    the function tells you if it is a line or not.
    p.s. you can add conditions. this sub will only look for all lines,
    and place a copy on another layer.

    if they are AcadPolyLines, AcadLWPolyLines, you just have to change
    the variables to suit your needs.
    for example to PolyLines:


    Public Function isAcadPolyLine(obj As Object) As Boolean
    Dim line1 As AcadLWPolyLine
    On Error GoTo fim
    Set line1 = obj
    isisAcadPolyLine = True
    Exit Function
    fim:
    isisAcadPolyLine = False
    End Function

    sub copy_line
    dim obj as object
    dim line1 as AcadLWPolyLine, line2 as AcadLWPolyLine

    for each obj in Thisdrawing.Modelspace
    if isAcadPolyLine(obj)=True then
    set line1=obj
    set line2=line1.copy
    line2.layer = "the name of the layer you want to place the
    copy"
    end if
    next obj

    end sub
     
    Rodrigues, Jun 17, 2007
    #2
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.