Results 1 to 9 of 9

Thread: offset or copy AND change to current layer

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2005-04
    Posts
    1
    Login to Give a bone
    0

    Default offset or copy AND change to current layer

    Anyone know of a way to save time by combining the "copy" or "offset" commands with "change to current layer"?

    I'm new to the AUGI, so forgive me if the answer is posted and I couldn't find it.

    Thanks.

  2. #2
    100 Club lance.81922's Avatar
    Join Date
    2005-01
    Location
    Santa Fe, NM
    Posts
    176
    Login to Give a bone
    0

    Default Re: offset or copy AND change to current layer

    I did this for AutoCAD 2000-2004. Now with 2006 it's obsolete... . The way I did it was to set up a command reactor to watch for the OFFSET command, and then a database reactor to count the additions to the database after the first reactor fires. That way you get a selection set of new objects that get changed to the current layer. This works great BUT it didn't allow you to use OFFSET the "old" way, placing objects on the layer of the source object. Since one of my test users wanted to do that, I added a conditional flag to the reactor routine so it would only fire if the flag was true. That way, "OCL" would offset to the current layer and "O" or "OFFSET" worked the standard way. The reactor code looks like this:
    Code:
    ;;; OffsetChangeLayerFlag.lsp
    ;;; Was ReactorOffsetChangeLayer.lsp
    ;;; Changes entities created by OFFSET to the current layer
    ;;; Added OFFSETFLAG to allow 2 versions of OFFSET
    ;;; Copyright 2005 Lance Gordon Custom Software
    (vl-load-com)
    ;;; Define routine to strip reactors away before calling it
    (defun remove (Name / ReactorsinDwg ReactorGrp ReactorObj)
      (setq ReactorsinDwg (vlr-reactors))
      (foreach ReactorGrp ReactorsinDwg
    	(foreach ReactorObj (cdr ReactorGrp)
    	  (if (= (vlr-data ReactorObj) Name)
     (vlr-remove ReactorObj)
    	  )
    	)
      )
    )
    ;;; Before starting, remove any current OFFSET reactors
    (remove "off-rctEnded")
    (remove "off-rctWillStart")
    ;;; Manually empty running total in case we're loaded twice
    (setq entlist nil)
    ;;; First, set up CommandWillStart and CommandEnded reactors
    ;;; to watch for OFFSET command and to call our Change routine
    (setq off-rctWillStart
    		 (vlr-command-reactor
    	"off-rctWillStart"
    	'((:VLR-CommandWillStart . off-CmdStarted))
    		 )
    	  off-rctEnded
    		 (vlr-command-reactor
    	"off-rctEnded"
    	'((:VLR-CommandEnded . off-CmdEnded))
    		 )
    )
    ;;; This routine runs right after OFFSET has started, assuming the flag is set.
    ;;; It sets up the Appended reactor to fire for anything added to the database.
    (defun off-CmdStarted (off-rctWillStart str)
      (if (and (= (strcase (car str)) "OFFSET") offsetflag)
    	 ; Fire only if OFFSET is running
    	(progn	; and flag is set.
    	  (setq off-rctAppended  ; If so, set up the reactor
    	  (vlr-AcDb-reactor
    		nil
    		'((:VLR-ObjectAppended . off-ObjAdded))
    	  )
    	  )
    	)
      )
    )
    ;;; This routine runs after each object is added to the database
    ;;; by the reactor conditional on "OFFSET" running
    (defun off-ObjAdded (off-rctAppended str / ent cl)
      (setq cl (getvar "CLAYER"))
      (if (vlr-added-p off-rctAppended)
    	(progn	; avoid double reactor action
    	  (vlr-remove off-rctAppended)
    	  ;;(princ "\n*** Reactor Active *** ") ; FOR TESTING
    	)
      )
      (if (= (type (cadr str)) 'EName)
    	(progn	; Keep a running list of new objects appended
    	  (setq ent (entlast))
    	  (if (not (= cl (cdr (assoc 8 (entget ent)))))
     (progn	; if they're not on the current layer.
       (if entlist   ; Make sure they aren't duplicates
    	 (if (not (member ent entlist))
    	   (setq entlist (append (list ent) entlist))
    	 )
    	 (setq entlist (list ent))
       )
       (princ "\nChange to current layer pending...")
     )
    	  )
    	)
      )
      (if (and (vlr-added-p off-rctWillStart)
    	(not (vlr-added-p off-rctAppended))
    	  )	 ; Reset the Appended reactor
    	(vlr-add off-rctAppended)
      )	 ; if something was appended
    )
    ;;; This runs after OFFSET has finished
    ;;; so that objects can be modified
    (defun off-CmdEnded (off-rctEnded str / ent el cl)
      (if (= (strcase (car str)) "OFFSET")
    	(progn
    	  (foreach ent entlist
     (setq
       el (entget ent)
       cl (getvar "CLAYER")
     )
     (setq el (subst (cons 8 cl) (assoc 8 el) el))
     (entmod el)
    	  )	 ; Move appended stuff to current layer
    	  (if off-rctAppended  ; Check to be sure it's defined (NOT if flag is nil)
     (vlr-remove off-rctAppended) ; Remove last Appended reactor now
    	  )
    	  (if entlist
     (progn	; Notify about changed objects
       (princ (strcat "\n"
    	(itoa (length entlist))
    	" objects changed to current layer."
       )
       )
       (setq entlist nil)  ; and manually delete the list.
       (setq offsetflag nil)  ; Kill the flag, if any
     )
    	  )
    	)
      )
      (princ)
    )
    (princ "\nOffset ChangeLayer utility loaded.\n")
    (princ)
    and the OCL program is simply
    Code:
    ;;; OCL Function
    (defun c:ocl()
      (setvar "CMDECHO" 0)
      (setq offsetflag T)  
      (command "_OFFSET")
      (setvar "CMDECHO" 1)
      (princ)
    )
    (princ "\nOffsetChangeLayer loaded.  (C)LGCS 2005.\n")
    (princ)
    Note that offsetflag is a GLOBAL variable so it persists until the reactor code turns it off. To use this code, you load the reactor code with ACADDOC.LSP, and then just load/run OCL.LSP when you want it.

  3. #3
    I could stop if I wanted to pnorman's Avatar
    Join Date
    2005-02
    Location
    Calgary
    Posts
    203
    Login to Give a bone
    0

    Default Re: offset or copy AND change to current layer

    Well you could also just do this, and it works the old fashioned way.
    And doesn't need messy reactors and vla. In my humble opinion an example of how autolisp still has its place! (could easily be modified for copy as well)

    (add to your acaddoc.lsp or similar)
    Sets layer, col, linetype, and ltscale of new object to match existing object.
    Pick 'nothing' at the first Select Object prompt for current layer.
    Also sets current layer to that of object picked.

    Code:
     
     
    (defun ppn_get (E1 ITEM ITEM# / E1DATA)
    	 (if E1
    		(progn
    		 (setq E1DATA (entget (car E1)))
    		 (set (read ITEM) (cdr (assoc ITEM# E1DATA)))
    		)
    	 )
    )
     
    (defun c:of (/ SS1 SS2 DST E1 E2 LYR COL LT LTSC SC)
    (setq SC (getvar "dimscale"))
    (setvar "cmdecho" 0)
    (setq SS1 (ssadd))
    	(if (not *PPN_OFDST*)
    		(setq *PPN_OFDST* (* SC 0.75))
    	)
    (setq DST (getdist (strcat "\nOffset distance: <" (rtos *PPN_OFDST*) ">: ")))
    	(if (= DST nil)
    		(setq DST *PPN_OFDST*)
    		(setq *PPN_OFDST* DST)
    	)
    	(if (setq E1 (entsel "Pick an object on the desired layer: "))
    		(progn
    		 (ppn_get E1 "LYR" 8)
    		 (ppn_get E1 "COL" 62)
    		 (ppn_get E1 "LT" 6)
    		 (ppn_get E1 "LTSC" 48)
    )
    		(setq LYR (getvar "clayer"))
    	)
    	(if (not COL) (setq COL "bylayer"))
    	(if (not LT) (setq LT "bylayer"))
    	(if (not LTSC) (setq LTSC 1))
    	(while (setq E2 (entsel "\nSelect object to offset: "))
    		 (progn 
    			 (setq P1 (getpoint "\nSelect side: "))
    			 (command "_.offset" DST E2 P1 "")
    			 (setq SS2 (entlast))
    			 (ssadd SS2 SS1)
    		 )
    	)
    (command "_.change" SS1 "" "_p" "_la" LYR "_c" COL "_lt" LT "_s" LTSC "")
    (princ)
    )
    Last edited by pnorman; 2005-04-21 at 05:25 PM.

  4. #4
    Wish List Manager BrenBren's Avatar
    Join Date
    2000-11
    Location
    150700
    Posts
    3,439
    Login to Give a bone
    0

    Default Re: offset or copy AND change to current layer

    Quote Originally Posted by mpriest
    Anyone know of a way to save time by combining the "copy" or "offset" commands with "change to current layer"?

    I'm new to the AUGI, so forgive me if the answer is posted and I couldn't find it.

    Thanks.
    In 2006, you can, while using the offset command, have it offset to the current layer. After starting the offset command, hit m for mode and set it to current layer.

  5. #5
    I could stop if I wanted to pnorman's Avatar
    Join Date
    2005-02
    Location
    Calgary
    Posts
    203
    Login to Give a bone
    0

    Wink Re: offset or copy AND change to current layer

    I might just keep using my macro for another 2 years or so until I get 2006


    In 2006 offset can you select a target object like in matchprop or is it only the current layer option?

  6. #6
    Wish List Manager BrenBren's Avatar
    Join Date
    2000-11
    Location
    150700
    Posts
    3,439
    Login to Give a bone
    0

    Default Re: offset or copy AND change to current layer

    Quote Originally Posted by pnorman
    I might just keep using my macro for another 2 years or so until I get 2006


    In 2006 offset can you select a target object like in matchprop or is it only the current layer option?
    nope, current layer is the only option, but it is a step in the right direction

  7. #7
    Certified AUGI Addict jaberwok's Avatar
    Join Date
    2000-12
    Location
    0,0,0 The Origin
    Posts
    8,570
    Login to Give a bone
    0

    Default Re: offset or copy AND change to current layer

    Quote Originally Posted by brenda.richardson
    In 2006, you can, while using the offset command, have it offset to the current layer. After starting the offset command, hit m for mode and set it to current layer.
    That's worth knowing but, for me, it's not M for mode but L for layer.

    As you say, it's a step in the right direction.

  8. #8
    Wish List Manager BrenBren's Avatar
    Join Date
    2000-11
    Location
    150700
    Posts
    3,439
    Login to Give a bone
    0

    Default Re: offset or copy AND change to current layer

    Quote Originally Posted by johnbogie
    That's worth knowing but, for me, it's not M for mode but L for layer.

    As you say, it's a step in the right direction.
    ~slaps herself on the head~ ops: sorry about that, I really need to learn to check Vanilla and make sure it is the same as it is in Mechanical. You're correct, it is L for layer. The M thing only works in mechanical

  9. #9
    Certified AUGI Addict jaberwok's Avatar
    Join Date
    2000-12
    Location
    0,0,0 The Origin
    Posts
    8,570
    Login to Give a bone
    0

    Default Re: offset or copy AND change to current layer

    Quote Originally Posted by brenda.richardson
    sorry about that, I really need to learn to check Vanilla and make sure it is the same as it is in Mechanical. You're correct, it is L for layer. The M thing only works in mechanical
    Since it's now in vanilla acad it seems daft that they recode it for mech, doesn't it?
    Different teams following different paths, I guess.

Similar Threads

  1. Replies: 0
    Last Post: 2011-10-11, 08:38 AM
  2. Copy and offset to current layer
    By sinc in forum AutoCAD General
    Replies: 11
    Last Post: 2009-04-13, 07:57 PM
  3. Ability to Change Current Layer during Hatch Command
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2007-05-02, 05:07 PM
  4. Convert AutoCAD 2007 Offset Layer Current functionality to VBA
    By Capt. Computer Crasher in forum VBA/COM Interop
    Replies: 5
    Last Post: 2007-03-26, 12:08 PM
  5. Offset command - New Line to be on current layer
    By neilcheshire in forum AutoCAD General
    Replies: 8
    Last Post: 2005-06-17, 11:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •