Custom fixed-scale lisp

Custom fixed-scale lisp

stuart.warnockG9UA9
Observer Observer
2,005 Views
8 Replies
Message 1 of 9

Custom fixed-scale lisp

stuart.warnockG9UA9
Observer
Observer

Hi everyone, I'm looking for help making a .lsp to save some time/clicks.  Probably 100 times I day I find myself entering the scale command to convert something from US Survey Feet to Texas Varas.  Manually entering the same scale factor (2.777777777778) every time gets extremely repetitive.  I imagine it would be extremely simple to create a LSP that automatically scales by a set amount (essentially functioning just like the built-in scale command, but the only user input required would be selecting object and base point).  However, I don't know the first thing about writing LSP's.  Anybody willing to write quick script or point me in the right direction?

0 Likes
Accepted solutions (1)
2,006 Views
8 Replies
Replies (8)
Message 2 of 9

Moshe-A
Mentor
Mentor

@stuart.warnockG9UA9  hi,

 

if you are talking about blocks, then select these blocks and in properties palette change the xScale, yScale, zScale.

 

Moshe

0 Likes
Message 3 of 9

tstorzuk
Advocate
Advocate

@stuart.warnockG9UA9 

 

Here's a great place to start learning;

https://www.ronleigh.com/autolisp/index.htm

0 Likes
Message 4 of 9

pbejse
Mentor
Mentor

@stuart.warnockG9UA9 wrote:

.. I day I find myself entering the scale command to convert something from US Survey Feet to Texas Varas.  Manually entering the same scale factor (2.777777777778)..  or point me in the right direction?


Tool palettes is your friend.

 

pbejse_0-1675484215644.png

HTH

 

 

0 Likes
Message 5 of 9

Sea-Haven
Mentor
Mentor

Something like this not tested very much certain objects may need to be scaled differently.

(defun c:27 ( / )
(command "scale" (entsel "\nPick object ") "" (getpoint "\nPick base point ") 2.777777777778)
)

 

Autoload or appload and save in start up suite. Just type 27.

0 Likes
Message 6 of 9

Kent1Cooper
Consultant
Consultant

@stuart.warnockG9UA9 wrote:

.....  Manually entering the same scale factor (2.777777777778) every time gets extremely repetitive.  ....


Even if manually entered, you can save yourself a bunch of keystrokes, and be more precise -- all the way out to the 16 significant figures that are the most AutoCAD can handle.  Type it this way:

25/9

Or, when used inside an AutoLisp (command "_.scale" ...) function:

(/ 25 9.0)

[one of them needs to be a real number, not both integers].  Or, you can even use it there as a text string as you would type it in:

"25/9"

Kent Cooper, AIA
0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

@stuart.warnockG9UA9 wrote:

.... a LSP that automatically scales by a set amount (essentially functioning just like the built-in scale command, but the only user input required would be selecting object and base point).  ....


If, as in the built-in Scale command, you want the usual selection options including multiple objects and selection modes, try this, which repeats as long as you want to select other things to Scale around other base points:

 

(defun C:25-9ths (/ ss)
  (while (setq ss (ssget "_:L"))
    (command "_.scale" ss "" pause (/ 25 9.0))
  )
  (prin1)
)

 

If you only do single objects, the above command needs you to tell it you're done selecting after one object.  You can eliminate the need for that Enter/space, and also continue to Scale as many things as you want, one at a time:

 

(defun C:25-9ths (/ ent)
  (while (setq ent (entsel "\nObject to Scale by 25 9ths: "))
    (command "_.scale" (car ent) "" pause (/ 25 9.0))
  )
  (prin1)
)

 

The first one prevents selection of objects on locked Layers -- (ssget) can do that, but (entsel) can't.  So the second [as written] will quit if a selected object is on a locked Layer.  But it could be made to go on and let you pick other things, by checking whether each object's Layer is locked before trying to Scale it.

Kent Cooper, AIA
0 Likes
Message 8 of 9

stuart.warnockG9UA9
Observer
Observer

@Kent1Cooper that 2nd version works perfectly - and fits with exactly what I was looking for.

@tstorzuk  thank you very much for that link.  I spent some time Saturday reading through it and learned some interesting historical CAD tidbits!  I've always wanted to learn LISP programming, but between working 70 hours weeks and being a father to (3) children under five - time is a premium.  You've refreshed my interest though!  Does anyone have any recommendations of more in-depth training courses (even paid options)?  That link has great breakdowns of the different functions and function definitions - but I'm more of a "learn by following" type of guy...if no recommendations I'll start Googling!

 

To everyone else - it was interesting to see the different ways people tried attacking the same problem.  Even though I do it fairly regularly, I tend to forget the "convert to fraction" trick.  That would get just as repetitive as the original value eventually, but there's always more than one way to skin a cat!

0 Likes
Message 9 of 9

tstorzuk
Advocate
Advocate

@stuart.warnockG9UA9 

 

The link I gave you was where I started learning LISP. There are tons of sites out there, but that one puts it into easy to understand categories.

 

I went through that one, then several others before I finally sought out my local college and took a couple of classes there (I too benefit from visual and hands on learning).

 

If you don't have the option for a local college that offers classes, there are lots of websites that offer video tutorials as well. Most require payment.

 

I too would be interested in seeing what other site recommendations other users suggest.

0 Likes