Results 1 to 8 of 8

Thread: I can use some help cleaning up a simple program

  1. #1
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    385
    Login to Give a bone
    0

    Default I can use some help cleaning up a simple program

    Hello all,
    I am really just looking to simplify my program.

    This program justs inserts a block at a selected point and uses the selected point as a layer setting.

    I am sure there is a better way.

    Edit: I do desire to preview the block as I insert it.

    Thanks all in advance

    Code:
    ;bn = block name
    ;bs = block scale
    ;rl = referenced layer
    
    (defun C:xxx (/ sp1 bn bs rlay)
      (setq bn "XXX")
      (setq bs (getvar "Dimscale"))
    
      (command "undo" "mark")
      (command "-insert" bn "s" bs "r" 0 pause)
      (setq sp1 (getvar "lastpoint"))
      (command "undo" "back")  
      (command "laymcur" sp1)
      (setq rl (getvar "clayer"))
      
      (command "-insert" bn "s" bs "r" 0 "non" sp1)
      (command "Change" (entlast)  "" "P" "LA" rl "")  
      (princ))
    Last edited by ReachAndre; 2014-10-17 at 05:13 PM.

  2. #2
    Member
    Join Date
    2015-10
    Location
    Alhambra
    Posts
    27
    Login to Give a bone
    0

    Default Re: I can use some help cleaning up a simple program

    Since the purpose of the 1st block insertion really is to get the layer change info & insert point, I would do the following instead:
    Code:
    ;bn = block name
    ;bs = block scale
    ;rl = referenced layer
    
    (defun C:xxx (/ sp1 bn bs rlay)
      (setq bn "XXX")
      (setq bs (getvar "Dimscale"))
    
      (while (not sp1)
       (setq sp1 (entsel"\nSelect object whose layer will become current:")) ; use entsel to return object & point selection
      )
      
      (command "_.Laymcur" (car sp1)) ; pass the first element of sp1 to laymcur command which is the selected object 
      (setq rl (getvar "clayer"))
      
      (command "_.-Insert" bn "s" bs "r" 0 "non" (cadr sp1)) ; pass the second element of sp1 to the Insert command which is the selected point 
      (command "_.Change" (entlast)  "" "P" "LA" rl "")  
      (princ))

    Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
    Exchange App Store
    Paul Li
    Senior Associate
    ALTOON PARTNERS LLP
    Los Angeles • Amsterdam • Shanghai
    Last edited by Wanderer; 2014-10-17 at 02:43 PM. Reason: added code tags

  3. #3
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    385
    Login to Give a bone
    0

    Default Re: I can use some help cleaning up a simple program

    pli - I am trying to still preview the block (in dragmode) as I am inserting it. With your posted code, it does not allow this.

    Thanks,
    Andre

  4. #4
    Member
    Join Date
    2015-10
    Location
    Alhambra
    Posts
    27
    Login to Give a bone
    0

    Default Re: I can use some help cleaning up a simple program

    In that case then you may want to try this which uses the erase last command instead of the undo mark & undo back sequence:
    Code:
    ;bn = block name
    ;bs = block scale
    ;rl = referenced layer
    
    (defun C:xxx (/ sp1 bn bs rlay)
      (setq bn "XXX")
      (setq bs (getvar "Dimscale"))
    
      (command "_.-Insert" bn "_s" bs "_r" 0 pause)
      (command'_.erase""_last""")
      (setq sp1 (getvar "lastpoint"))
      (command "laymcur" sp1)
      (setq rl (getvar "clayer"))
      
      (command "_.-insert" bn "_s" bs "_r" 0 "_non" sp1)
      (command "_.Change" (entlast)  "" "_P" "_LA" rl "")  
      (princ))

    Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
    Exchange App Store
    Paul Li
    Senior Associate
    ALTOON PARTNERS LLP
    Los Angeles • Amsterdam • Shanghai
    Last edited by Opie; 2014-10-18 at 06:02 PM. Reason: [code] tags added

  5. #5
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    385
    Login to Give a bone
    0

    Default Re: I can use some help cleaning up a simple program

    I originally used an erase, I then have to reset the current layer. That's when I decided to go with undo and back.
    Guess there's not an easier way.

    Thanks

  6. #6
    Member
    Join Date
    2015-10
    Location
    Alhambra
    Posts
    27
    Login to Give a bone
    0

    Default Re: I can use some help cleaning up a simple program

    Now I'm really confused. Why would you have to reset the current layer if you used the ERASE LAST command?
    I thought the purpose of what you're trying to do is Insert the block by picking a point once. From that point you get the layer information and then make sure the block is placed on that layer.
    This is what you are trying to do, right?

    Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
    Exchange App Store
    Paul Li
    Senior Associate
    ALTOON PARTNERS LLP
    Los Angeles • Amsterdam • Shanghai

  7. #7
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    385
    Login to Give a bone
    0

    Default Re: I can use some help cleaning up a simple program

    pli - after the following code

    Code:
    (command "laymcur" sp1)
    my current layer would have been changed.

  8. #8
    Member
    Join Date
    2015-10
    Location
    Alhambra
    Posts
    27
    Login to Give a bone
    0

    Default Re: I can use some help cleaning up a simple program

    Ok, let me get this straight. Currently your code shows the Undo back command before the (command "laymcur" sp1). So your current layer has changed. If what you really want is to not change the current layer, then you should place this code at the beginning to save the current layer info:
    (setq cl (getvar"clayer"))
    Then after you've executed the last line of code, change the layer back to the original layer:
    (setvar"clayer" cl)

    So again instead of using Undo Mark & Undo Back, the Erase Last command will work like this:

    Code:
    ;bn = block name
    ;bs = block scale
    ;rl = referenced layer
    ;cl = current layer
    
    (defun C:xxx (/ sp1 bn bs cl rl)
      (setq cl (getvar"clayer"))  ; save current layer info
      (setq bn "XXX")
      (setq bs (getvar "Dimscale"))
    
      (command "_.-Insert" bn "_s" bs "_r" 0 pause)
      (command'_.erase""_last""")
      (setq sp1 (getvar "lastpoint"))
      (command "laymcur" sp1)
      (setq rl (getvar "clayer"))
      
      (command "_.-insert" bn "_s" bs "_r" 0 "_non" sp1)
      (command "_.Change" (entlast)  "" "_P" "_LA" rl "")  ; you really would not need this Change command sequence since you've already changed to the new layer with laymcur
      (setvar"clayer" cl) ; restore layer to original
      (princ))

    Area Object Link | Attribute Modifier | Dwg Setup | Feet-Inch Calculator | Layer Apps | List on Steroids | VP Zoom Scales
    Exchange App Store
    Paul Li
    Senior Associate
    ALTOON PARTNERS LLP
    Los Angeles • Amsterdam • Shanghai
    Last edited by pli; 2014-10-22 at 04:40 PM. Reason: added code

Similar Threads

  1. Please help. Probably a simple fix to LISP program
    By sicilianbrother398578 in forum AutoLISP
    Replies: 3
    Last Post: 2013-09-19, 07:10 PM
  2. simple lables on simple entities
    By Maverick91 in forum AutoCAD Civil 3D - General
    Replies: 13
    Last Post: 2010-09-22, 09:38 PM
  3. Need program to create simple AutoCAD point objects from point file
    By Bob T in forum AutoCAD Civil 3D - General
    Replies: 3
    Last Post: 2009-09-08, 10:51 PM
  4. reactor based simple lisp program needed
    By rajat_bapi_mallick in forum AutoLISP
    Replies: 2
    Last Post: 2007-10-11, 10:21 PM

Posting Permissions

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