Results 1 to 2 of 2

Thread: while loops for rotating blocks

  1. #1
    Member
    Join Date
    2012-01
    Posts
    2
    Login to Give a bone
    0

    Default while loops for rotating blocks

    (defun c:1300 ()
    (command "layer" "s" "Utility_Pole" "")
    (command "insert" "Utility_Pole" (getpoint) msc "")
    )

    (defun c:1301 ()
    (command "layer" "s" "Utility_Pole" "")
    (while
    (princ "\n1301 Light Pole: ")
    (setq pt (getpoint))
    (command "insert" "Light_Pole" pt msc "" "")
    )
    )
    This is the code for part of a *.lsp file I use to interactively collect plan for maps. The first set, 1301, will collect a block and allow me to orient it around the Z axis. This block needs to always be oriented. It will allow me to do it once. I can use the MULTIPLE command first and collect as many utility poles as I need to in any orientation about Z.
    The second set, 1301, of will allow me to place a light pole as many times as I need to. This block does not need to be oriented ever.
    The code for the utility pole 1300 can be structured the same as for the light pole 1301 and I can collect just one. The problem is getting the 1300 block to work correctly using the while command. It seems to ignore the loop and will only collect one block.
    The 1300 utility pole requires two clicks, one for the insertion point, mouse movement to set the orientation and a second click to finish the collection. In my case they are both left buttion clicks on a three button mouse.
    The the 1301 light pole requires one left click.
    Thanks.

  2. #2
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: while loops for rotating blocks

    First, welcome to AUGI. Second, just a bit of etiquette : Surround your code inside of code tags. In the advanced editor click the hash (#) button or type:
    [ code ]... your code here ... [ /code ] (without the spaces of course). It just makes your code more readable.

    Now to try and answer your question:
    1. The 1st item in a while loop is the predicate. I.e. if it returns nil the while loop stops, otherwise it continues to perform all the other items in the loop.
    2. Your first item is the princ, which means effectively that your while loop will never stop, since it will always return the string printed to the command line (i.e. not nil).
    3. Depending on if your Light_Pole block definition is set to be scaled uniformly or not, it expects either just a scale or a scale for XYZ (one each). So the command call needs to account for this before the rotate happens.
    4. The msc thingy is not defined in the code you posted, I'm not sure what it's meant to do. If I test your code it sends a nil to the insert command causing an ESC being pressed - and thus stopping all lisp.
    5. To cleanly stop a command defun, add a blank princ at the end so it doesn't print out whatever the last thing was inside the defun.

    So here's an alternative which might work:
    Code:
    (defun c:1301  ()
      (command "layer" "s" "Utility_Pole" "")
      (while (setq pt (getpoint "\n1301 Light Pole: "))
        (command "insert" "Light_Pole" pt "" ""))
      (princ))
    See how much nicer it looks when you surround your code with code tags?

    Edit: BTW, you could use the Make option for Layer instead of Set. If the layer exists then it acts the same as set, but if it doesn't in makes the layer before it set it as current.

Similar Threads

  1. Using BlockReferences for Inner Loops of Hatch
    By lambwill in forum VBA/COM Interop
    Replies: 8
    Last Post: 2009-09-28, 09:45 AM
  2. Closed Loops - good way to detect?
    By WYSIWYG-BIM in forum Revit Architecture - Families
    Replies: 5
    Last Post: 2009-08-14, 02:55 PM
  3. Routine loops itself in AutoCAD 2005
    By bim3d in forum VBA/COM Interop
    Replies: 4
    Last Post: 2007-02-14, 04:43 PM
  4. Highlight Self-intersecting Loops
    By inventor.wishlist1738 in forum Inventor Wish List
    Replies: 0
    Last Post: 2007-01-03, 03:52 PM
  5. Scaling & Rotating Dynamic Blocks
    By kwong in forum Dynamic Blocks - Technical
    Replies: 14
    Last Post: 2005-10-28, 07:35 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
  •