Results 1 to 9 of 9

Thread: Using SETQ to assign a block to a variable

  1. #1
    I could stop if I wanted to
    Join Date
    2011-09
    Posts
    308
    Login to Give a bone
    0

    Default Using SETQ to assign a block to a variable

    Hey gang,

    I'm writing a LISP routine to create a slope arrow. At one point I need to assign a block to a variable, but that block is in another drawing.

    I could use this line if it was just one drawing that made up the block:

    Code:
    (setq block1 "arrow.dwg")
    But what I want is to have all the blocks I need for the routine in one drawing and use something like this:

    Code:
    (setq block1 "arrowblock from blocks.dwg")
    FYI the reason I want to do it this way is because I need to have these blocks come in with all possible annotations scales pre populated and I can't seem to do that when they are separated out into individual drawings. If you know how to do that... let me know.

    Any help is, as always, greatly appreciated.

    -JP
    Last edited by BlackBox; 2014-02-04 at 04:50 PM. Reason: Please use [CODE] Tags

  2. #2
    Active Member
    Join Date
    2013-07
    Posts
    66
    Login to Give a bone
    0

    Default Re: Using SETQ to assign a block to a variable

    Quote Originally Posted by jpcadconsulting347236 View Post
    Hey gang,

    I'm writing a LISP routine to create a slope arrow. At one point I need to assign a block to a variable, but that block is in another drawing.

    I could use this line if it was just one drawing that made up the block:

    Code:
    (setq block1 "arrow.dwg")
    But what I want is to have all the blocks I need for the routine in one drawing and use something like this:

    Code:
    (setq block1 "arrowblock from blocks.dwg")
    FYI the reason I want to do it this way is because I need to have these blocks come in with all possible annotations scales pre populated and I can't seem to do that when they are separated out into individual drawings. If you know how to do that... let me know.

    Any help is, as always, greatly appreciated.

    -JP
    Whatever is before ".dwg" when referencing a block is the block's name. You can't just on-the-fly name these per your needs. That is in effect what (setq) is doing.
    Additionally, as long as the blocks reside in a directory that's within your save file search paths, you're able to call it with just the block name without the ".dwg" if you're attempting to create or add to a selectionset via (ssget).
    Here's an example I just finished doing.

    Code:
     (if (setq ss (ssget "_X" (list (cons 0 "INSERT")(cons 2 a2))))
        (progn
          (setq pfst (getvar 'PICKFIRST))
          (setvar 'PICKFIRST 1)
          (sssetfirst nil ss)
          (c:burst)
          (setvar 'PICKFIRST pfst)
    (princ)
    );progn
    You can see here that I'm using the a2 variable to represent a block name.
    I know all of the blocks that may be represented by "a2" are within my search paths, so the ssget is successful in finding them with the parameters shown

  3. #3
    I could stop if I wanted to
    Join Date
    2011-09
    Posts
    308
    Login to Give a bone
    0

    Default Re: Using SETQ to assign a block to a variable

    Thanks bhull1985403354,

    maybe I should have been more precise... (or maybe I just don't understand the code you posted)

    I have a drawing called slopeblocks.dwg which contains 3 blocks:

    slopeorigin
    slopevalue
    slopearrow


    I'm trying to write a lisp routing that draws a line and then inserts those 3 blocks at the start, midpoint and end of the line respectively.

    I can do it if the blocks are each a separate file, but then I can get them to bring in the annotation scales.

    All drawing are in my search path and the lisp would always pull the same blocks form the same drawing.... no need for user input other than picking the start and end points of the line.

    For reference, here is the code (which almost works) using separate drawings:

    (defun c:slope (/ block1 block2 block3 p1 p2 p3 dist ang angdeg)

    (setq block1 "slopeorigin.dwg")
    (setq block2 "slopearrow.dwg")
    (setq block3 "slopevalue.dwg")

    (setq p1 (getpoint "\npick high point of slope: "))
    (setq p2 (getpoint "\npick low point of slope: "))
    (setq dist (distance P1 P2))
    (setq ang (angle P1 P2))
    (setq p3 (POLAR P1 ANG (/ DIST 2)))
    (setq angdeg (* (/ ang pi) 180.0))

    (command "line" p1 p2 "")
    (command "-insert" block1 p1 "1" "1" angdeg "")
    (command "-insert" block2 p2 "1" "1" angdeg "")
    (command "-insert" block3 p3 "1" "1" angdeg "")

    (princ)
    )


    -JP

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,096
    Login to Give a bone
    0

    Default Re: Using SETQ to assign a block to a variable

    You could insert your container drawing into your current drawing. Once it is in your drawing, the other blocks would then be available.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  5. #5
    Active Member
    Join Date
    2013-07
    Posts
    66
    Login to Give a bone
    0

    Default Re: Using SETQ to assign a block to a variable

    Quote Originally Posted by Opie View Post
    You could insert your container drawing into your current drawing. Once it is in your drawing, the other blocks would then be available.
    Yeah, I tried to post here twice already and the webpage keeps eating them. Dang IE!!
    Anyhow, just try this:
    Code:
    (defun c:slope (/ block1 block2 block3 p1 p2 p3 dist ang angdeg)
     (setq block1 "slopeblocks")
     
     (setq p1 (getpoint "\npick high point of slope: "))
     (setq p2 (getpoint "\npick low point of slope: "))
     (setq dist (distance P1 P2))
     (setq ang (angle P1 P2))
     (setq p3 (POLAR P1 ANG (/ DIST 2)))
     (setq angdeg (* (/ ang pi) 180.0))
     (command "line" p1 p2 "")
     (command "-insert" block1 p1 "1" "1" angdeg "")
     
     (if (setq ss (ssget "_X" (list (cons 0 "INSERT")(cons 2 block1))))
        (progn
          (setq pfst (getvar 'PICKFIRST))
          (setvar 'PICKFIRST 1)
          (sssetfirst nil ss)
          (c:burst)
          (setvar 'PICKFIRST pfst)
    (princ)
    );progn
    );if
     (princ)
     )
    Try that, assumes you already have express tools installed.

  6. #6
    I could stop if I wanted to
    Join Date
    2011-09
    Posts
    308
    Login to Give a bone
    0

    Default Re: Using SETQ to assign a block to a variable

    Ok, thanks. Much closer.

    However, this inserts all three blocks contained in slopeblocks.dwg at the first picked point (and actually, just a bit off that point.)

    Thoughts?

    Thanks for all your help with this.

    -JP

  7. #7
    Active Member
    Join Date
    2013-07
    Posts
    66
    Login to Give a bone
    0

    Default Re: Using SETQ to assign a block to a variable

    True,
    you can assign the midpoint and endpoint of your line to variables
    then issue a command "move" on the blocks that are now in your drawing, perhaps re-adding block1/block2/block3 , and tell it to move block1 to endpoint1, move block2 to midpoint, move block3 to other endpoint.
    HTH

  8. #8
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,658
    Login to Give a bone
    0

    Default Re: Using SETQ to assign a block to a variable

    Quote Originally Posted by Opie View Post
    You could insert your container drawing into your current drawing. Once it is in your drawing, the other blocks would then be available.
    I think what Opie meant was something like
    Code:
     (command "-insert" container.dwg (command))
    would add the blocks to the drawing without actually inserting them anywhere. Afterwards insert "slopeorigin.dwg", "slopearrow.dwg", & "slopevalue.dwg" where you want them.

  9. #9
    I could stop if I wanted to
    Join Date
    2011-09
    Posts
    308
    Login to Give a bone
    0

    Default Re: Using SETQ to assign a block to a variable

    Thanks for all your help everyone! I've got it working well in this form (except for one issue regrading text alignment which I'll post separately):

    (defun c:slope (/ origin slope arrow1 p1 p2 dist ang angdeg p3)

    (setq origin "slopeorigin.dwg")
    (setq arrow1 "slopearrow.dwg")
    (setq slope "slopevalue.dwg")

    (setq p1 (getpoint "\npick high point of slope: "))
    (setq p2 (getpoint "\npick low point of slope: "))
    (setq dist (distance P1 P2))
    (setq ang (angle P1 P2))
    (setq p3 (POLAR P1 ANG (/ DIST 2)))
    (setq angdeg (* (/ ang pi) 180.0))

    (command "line" p1 p2 "")
    (command "-insert" origin p1 "1" "1" angdeg "")
    (command "-insert" slope p3 "1" "1" angdeg "")
    (command "-insert" arrow1 p2 "1" "1" angdeg "")


    (princ)
    )

Similar Threads

  1. Replies: 14
    Last Post: 2018-11-10, 07:28 PM
  2. Replies: 4
    Last Post: 2015-08-29, 04:40 AM
  3. error: bad variable name in SETQ?
    By stusic in forum AutoLISP
    Replies: 6
    Last Post: 2013-05-21, 05:46 PM
  4. COND Statement to Setq Variable
    By stusic in forum AutoLISP
    Replies: 9
    Last Post: 2012-04-05, 08:47 PM
  5. setq Selection Set to a variable
    By gisdude in forum AutoLISP
    Replies: 2
    Last Post: 2006-05-30, 03:05 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
  •