Change Layer

Discussion in 'AutoCAD' started by GaryDF, Jan 11, 2005.

  1. GaryDF

    GaryDF Guest

    How would I use co1 in a routine to change a layer?
    I want to change the layer of the line selected to clayer.

    (setq co1 (objsel "\n* Select First Line *"))

    ;;code by Dan <no last name>
    ;;code taken from Corner Notch routine posted eariler today.
    (defun objsel ($prompt / ent obj)
    (setq ent (car (entsel $prompt)))
    (if (/= ent nil)
    (setq obj (vlax-ename->vla-object ent))
    (princ "\n* No Object Selected *"))
    obj ;returns result for use in calling program
    )


    Gary
     
    GaryDF, Jan 11, 2005
    #1
  2. GaryDF

    T.Willey Guest

    (vla-put-Layer Obj (getvar "clayer")) ??

    Tim
     
    T.Willey, Jan 11, 2005
    #2
  3. (vla-put-layer <vla-object> "MyLayerName")
     
    Jason Piercey, Jan 11, 2005
    #3
  4. GaryDF

    GaryDF Guest

    Thanks for the reply...
    Here is my modified code.
    The layer does not stay changed...what am I missing?

    ;;;by Dan <no last name>
    ;;;ARCH#_DIS global distance
    (defun c:CNOTCH (/ mspc xdim pt1 pt2 pt3 pt4 pt5 ang ang3 ang4 int co1 co2 nlin1
    nlin2 nco1
    nco2)
    (vl-load-com)
    (command "undo" "mark")
    (setq mspc (vla-get-ModelSpace
    (vla-get-activeDocument (vlax-get-object "Autocad.application"))))
    (cond
    ((= ARCH#_DIS nil)
    (setq xdim (getreal "\n* Enter Dimension For Notch: "))
    (setq ARCH#_DIS xdim)
    )
    ((/= ARCH#_DIS nil)
    (setq xdim (getreal (strcat "\n* Enter Dimension For Notch <" (rtos
    ARCH#_DIS 4 6) ">: ")))
    (if (= xdim nil)(setq xdim ARCH#_DIS))
    )
    )
    (setq co1 (objsel "\n* Select First Line *"))
    (setq co2 (objsel "\n* Select Second Line *"))
    (if (and (= (vla-get-ObjectName co1) "AcDbLine")
    (= (vla-get-ObjectName co2) "AcDbLine"))
    (progn (setq int (vlax-invoke co1 'IntersectWith co2 acExtendBoth))
    (reline co1 int xdim)
    (setq pt3 pt1)
    (setq ang3 ang)
    (vlax-invoke co1 'Erase)
    (setq nco1 (vla-AddLine mspc (vlax-3d-point pt1) (vlax-3d-point pt2)))
    (reline co2 int xdim)
    (setq pt4 pt1)
    (setq ang4 ang)
    (vlax-invoke co2 'Erase)
    (setq nco2 (vla-AddLine mspc (vlax-3d-point pt1) (vlax-3d-point pt2)))
    (setq pt5 (polar pt4 ang3 xdim))
    (setq nlin1 (vla-AddLine mspc (vlax-3d-point pt4) (vlax-3d-point
    pt5)))
    (setq nlin2 (vla-AddLine mspc (vlax-3d-point pt3) (vlax-3d-point
    pt5))))
    (princ "\n* Object Must Be A Line *"))
    (princ))
    ;;;
    (defun reline (lin int xdim / stpt endpt)
    (setq stpt (vlax-get lin 'StartPoint))
    (setq endpt (vlax-get lin 'EndPoint))
    (if (> (distance int stpt) (distance int endpt))
    (progn (setq ang (angle endpt stpt))
    (setq pt1 (polar int ang xdim))
    (setq pt2 stpt))
    (progn (setq ang (angle stpt endpt))
    (setq pt1 (polar int ang xdim))
    (setq pt2 endpt))))
    ;;;The following gets and returns a selected object in activex format
    ;;;usage = (setq obj (objsel "\n* Select Object *"))
    (defun objsel ($prompt / ent obj)
    (setq ent (car (entsel $prompt)))
    (if (/= ent nil)
    (progn
    (setq obj (vlax-ename->vla-object ent))
    ;(if ARCH#NLAY (vla-put-Layer obj ARCH#NLAY))
    (vla-put-Layer obj (getvar "clayer")) ;added here
    )
    (princ "\n* No Object Selected *"))
    obj ;returns result for use in calling program
    )
     
    GaryDF, Jan 11, 2005
    #4
  5. GaryDF

    GaryDF Guest

    Thanks...see my reply to Tim.

     
    GaryDF, Jan 11, 2005
    #5
  6. GaryDF

    Jeff Mishler Guest

    Gary,
    You are "Erasing" the objects that you changed the layer of......

    I'm not following what you are trying to end up with here.
     
    Jeff Mishler, Jan 12, 2005
    #6
  7. GaryDF

    GaryDF Guest

    Thats what I thought it was doing....
    I want the lines selected and the corner notched lines added to be
    changed to the clayer.

    This vla stuff has be confused.

    I have a work around, but would like to see how to modify the existing
    code.

    Thanks for the help.

    Gary
     
    GaryDF, Jan 12, 2005
    #7
  8. GaryDF

    GaryDF Guest

    This is what I was trying to do...your tips helped.
    Here is the revised code:

    Code:
    ;;;Dann
    ;;;ARCH#_DIS global distance var
    ;;;ARCH#NLAY global new layer var
    ;;;
    (defun C:NOTCH  (/ mspc xdim pt1 pt2 pt3 pt4 pt5 ang ang3 ang4 int co1 co2 nlin1
    nlin2 nco1 nco2)
    (vl-load-com)
    (command "undo" "mark")
    (setq mspc (vla-get-ModelSpace
    (vla-get-activeDocument (vlax-get-object "Autocad.application"))))
    (cond
    ((= ARCH#_DIS nil)
    (setq xdim (getreal "\n* Enter Dimension For Notch: "))
    (setq ARCH#_DIS xdim)
    )
    ((/= ARCH#_DIS nil)
    (setq xdim (getreal (strcat "\n* Enter Dimension For Notch <" (rtos
    ARCH#_DIS 4 6) ">: ")))
    (if (= xdim nil)(setq xdim ARCH#_DIS))
    )
    )
    (setq co1 (objsel "\n* Select First Line *"))
    (setq co2 (objsel "\n* Select Second Line *"))
    (if (and (= (vla-get-ObjectName co1) "AcDbLine")
    (= (vla-get-ObjectName co2) "AcDbLine"))
    (progn (setq int (vlax-invoke co1 'IntersectWith co2 acExtendBoth))
    (reline co1 int xdim)
    (setq pt3 pt1)
    (setq ang3 ang)
    (vlax-invoke co1 'Erase)
    (setq nco1 (vla-AddLine mspc (vlax-3d-point pt1) (vlax-3d-point pt2)))
    (if ARCH#NLAY (vla-put-Layer nco1 ARCH#NLAY)) ;<---new
    (reline co2 int xdim)
    (setq pt4 pt1)
    (setq ang4 ang)
    (vlax-invoke co2 'Erase)
    (setq nco2 (vla-AddLine mspc (vlax-3d-point pt1) (vlax-3d-point pt2)))
    (if ARCH#NLAY (vla-put-Layer nco2 ARCH#NLAY)) ;<---new
    (setq pt5 (polar pt4 ang3 xdim))
    (setq nlin1 (vla-AddLine mspc (vlax-3d-point pt4) (vlax-3d-point
    pt5)))
    (if ARCH#NLAY (vla-put-Layer nlin1 ARCH#NLAY)) ;<---new
    (setq nlin2 (vla-AddLine mspc (vlax-3d-point pt3) (vlax-3d-point
    pt5)))
    (if ARCH#NLAY (vla-put-Layer nlin2 ARCH#NLAY)) ;<---new
    )
    (princ "\n* Object Must Be A Line *"))
    (princ))
    ;;;
    (defun reline  (lin int xdim / stpt endpt)
    (setq stpt (vlax-get lin 'StartPoint))
    (setq endpt (vlax-get lin 'EndPoint))
    (if (> (distance int stpt) (distance int endpt))
    (progn (setq ang (angle endpt stpt))
    (setq pt1 (polar int ang xdim))
    (setq pt2 stpt))
    (progn (setq ang (angle stpt endpt))
    (setq pt1 (polar int ang xdim))
    (setq pt2 endpt))))
    ;;;The following gets and returns a selected object in activex format
    ;;;usage = (setq obj (objsel "\n* Select Object *"))
    (defun objsel  ($prompt / ent obj)
    (setq ent (car (entsel $prompt)))
    (if (/= ent nil)
    (setq obj (vlax-ename->vla-object ent))
    (princ "\n* No Object Selected *"))
    obj ;returns result for use in calling program
    )
    
    Gary
     
    GaryDF, Jan 12, 2005
    #8
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.