Jump to content

Recommended Posts

Posted

Hello -

 

Is there a way to write a lisp add-on that will prompt the user for a ltscale setting before the routine is run, then will revert the ltscale to .333 when the routine finishes?

 

At work we have a dimensioning routine that I use often (I don't know who to credit for writing the code which is why I'm hesitant to post it here), but I always need to remember to reset the scale before and after running...

 

Thanks!

 

- M.

Posted

call this at the start:

 

(defun LTPrompt (/ lts)
   (if (setq lts (getreal "\nSpecify Linetype Scale: "))
   (setvar "LTSCALE" lts)))

and just put

 

(setvar "LTSCALE" 0.333)

at the end of the code.

 

Should do the trick - I'd like to simplify it some more, but I haven't really got the time.

Posted

Thank you very much, both for the help and the speed of your reply. Your code does exactly what I was asking for!

Posted

No Probs, your welcome.

 

If you have any other queries, just ask. :thumbsup:

Posted

Well... since you offered :D

 

I'm getting interested in this whole lisp thing, and now I'm trying to make this dimensioning routine a little bit slicker...

 

Once the routine is loaded, the user is prompted to pick 4 points to be the boundary of the ground plan. Each subsequent point picked inserts a block with the x and y dimensions to the nearest boundary point. This information shows up inside an orientation arrow block that the program picks dependant on which quadrant the point is located.

 

The original routine scaled that block based on the global ltscale variable. I have rewritten it so that the routine prompts the user to input a block scaling factor, so now the ltscale never has to change.

 

This works, but is a little clunky. If the plan is in 3/4" plot scale, the proper block scaling factor is 7.5; for 1/2" scale the factor is 10, etc... I would love to be able to input the plot scale and have the program shift the appropriate number into the scaling factor variable (sf).

 

I've been reading through my AutoCAD book and checking out tutorials online, and this is as close as I have come so far...

 

;   Input the plot scale

(defun LTPrompt ()
   (setq ans  (getstring "\nSpecify Linetype Scale: ")
   )

;   Set the correct block scale

(defun symbol ()
    (if (= ans "1/4")(progn
           (setq sf 15)      ;if "1/4", set sf to 15
              
    ))
    (if (= ans "3/8")(progn 
           (setq sf 15)      ;if "3/8", set sf to 15
              
    ))
    (if (= ans "1/2")(progn 
           (setq sf 10)      ;if "1/2", set sf to 10
              
    ))
    (if (= ans "3/4")(progn 
           (setq sf 7.5)     ;if "3/4, set sf to 7.5
              
    ))
)

 

Somehow this always sets the scaling factor (sf) to 2. So I guess my minimal understanding of what's going on in there is even more minimal than I thought.

 

The hope, once this is resolved, is that a similar bit of code would allow the user to input what kind of dimensioning they are doing (we use different symbols for electrical vs. audio/visual vs. rigging), and that the routine would select the block with the proper symbol and orientation.

 

Any advice is appreciated. I'll keep reading through tutorials and post back if I find a solution.

 

Thanks!

Posted

Ok, I would use something like this:

 

 ;   Set the correct block scale

(defun Scaleset    (/ ans sf)
   (setq ans (getstring "\nSpecify Linetype Scale: "))
   (cond ((= ans "1/4") (setq sf 15)) ;if "1/4", set sf to 15
     ((= ans "3/8") (setq sf 15)) ;if "3/8", set sf to 15
     ((= ans "1/2") (setq sf 10)) ;if "1/2", set sf to 10
     ((= ans "3/4") (setq sf 7.5)) ;if "3/4, set sf to 7.5
     (T (princ "\nOption Unavailable."))
   )
   (princ)
)

Posted

A few pointers:

 

  • I would not define a separate function just to prompt for a string - this is unnecessary and means that you would have to call the function also, when the prompt could be included inside another function

  • When there are multiple options available, use "cond", and enclose each possibility inside a separate condition bracket. - the program will sequentially go through each condition until it finds one that returns True. Therefore, the last condition, "(T... " will always return True - if all others do not.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...