Results 1 to 3 of 3

Thread: AutoLisp programming help - COPY ROTATE PASTE

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

    Post AutoLisp programming help - COPY ROTATE PASTE

    Hello, I'm trying to learn autolisp. So I'm writing a simply program to understand it better.
    I am using AutoCad 2007. The picture shows what I am trying to automate.

    I created a box entity and now I want to Copy it, Rotate the copy and Paste that copy some distance in the X coordinate.
    I don't need an entire program, just some code fragments to understand how AutoLisp is handling entity's/objects.
    I will add a loop later to make multiple rotated boxes.

    Here's my basic program... HELP!!!

    ;boxcopyrot program
    ;I want to copy a box or square selecting it's basepoint and simply
    ;move it a distance along the X coordinate
    ;


    (defun c:boxcopyrot()


    (setq box (entsel "\nSelect box: "))

    (setq pt1 (getpoint "\n Base: "));This gets the basepoint of the object


    (setq angle 10);next box rotation


    (setq offset (getreal "\n Offset: ")); distance to place second box


    (setq X_val (car pt1))


    (setq Y_val (cadr pt1))


    (setq Z_val 0.0)


    (setq New_X_Val (+ X_val offset))


    (setq pt2 (list New_X_val Y_val Z_val))


    (command ".COPY" box "" pt1); This copies the entity (box)

    (command "ROTATE" (entlast) "" pt1 angle ""); This rotates the object (entlast)


    (command ".MOVE" (entlast) pt1 pt2); This moves the object

    (princ)


    );end of defun boxcopyrot

    box1.jpg
    Last edited by timothybarnard_22641168; 2014-04-21 at 04:27 PM.

  2. #2
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: AutoLisp programming help - COPY ROTATE PASTE

    Welcome on board, Tim
    I've edited your code just slightly
    seems it's working in A2017,
    see attached file

    Also you maywant to take a look at these links
    http://ronleigh.com/autolisp/
    http://www.afralisp.net/index.php
    Attached Files Attached Files
    Last edited by fixo; 2014-04-21 at 07:35 PM.

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

    Default Re: AutoLisp programming help - COPY ROTATE PASTE

    I have modified your code a little bit. fixo started you off pretty well though.

    Code:
    (defun c:foo (/ pt1 box boxangle offset X_val Y_val Z_val New_X_Val pt1 pt2 )
    
    (setq box (entsel "\nSelect box: "))
    
      (if (/= box nil); <---- added only do something if an object is selected, otherwise do nothing
        (progn
          (setq pt1 (getpoint "\n Base: "));This gets the basepoint of the object
          (setq boxangle 10);next box rotation<---------;"angle" changed to "boxangle" ("angle" is a function in lisp)
          (setq offset (getreal "\n Offset: ")); distance to place second box
          (setq X_val (car pt1))
          (setq Y_val (cadr pt1))
          (setq Z_val 0.0)
    
          (setq New_X_Val (+ X_val offset))
          (setq pt2 (list New_X_val Y_val Z_val))
    
          (command ".COPY" box "" pt1 pt1 ""); This copies the entity (box);<-------------added destination for copy
          (command "ROTATE" (entlast) "" pt1 boxangle ""); This rotates the object (entlast)
          (command ".MOVE" (entlast) "" pt1 pt2); This moves the object<--- added end of selection ""
          ));end of if statement
      (princ)
      );end of defun boxcopyrot

Similar Threads

  1. Autolisp programming for Room size
    By archsubhankar165015 in forum AutoLISP
    Replies: 2
    Last Post: 2012-07-31, 08:53 PM
  2. Right-click copy, paste, paste aligned
    By revit.wishlist1942 in forum Revit Architecture - Wish List
    Replies: 0
    Last Post: 2008-07-04, 11:39 AM
  3. Copy and Paste, Rotate on insert
    By sschwartz85916 in forum AutoCAD Tips & Tricks
    Replies: 5
    Last Post: 2006-11-13, 08:55 PM
  4. Co-ordinate Autolisp programming
    By saifi2003 in forum AutoLISP
    Replies: 1
    Last Post: 2004-06-05, 03:16 PM

Tags for this Thread

Posting Permissions

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