PDA

View Full Version : Lisp for inserting a block ans scaling it



mairanta
10-01-2006, 11:38 AM
I need some help. I'm a real novice on making autolisps...

How can I make a lisp that inserts a block "block1" where the user wants and changes the blocks scale to same as the whole drawings scale.

I allready got a hint that it has something to do with (setq scale (getvar "DIMSCALE")) but I need the the whole code...

Eddie
10-01-2006, 09:13 PM
And if you post your entire code we maybe able to help...

mairanta
11-01-2006, 04:22 AM
But I don't have any code!

CarLB
11-01-2006, 06:22 AM
The format for lisp functions that basically mimic the Autocad commands have the format:

(command "Command namehere" "Response1" "Response2" etc....)

The responses are in the same order as on the AutoCAD command line. The responses can be a variable you define, a number, or text (in quotes). you can also use "pause" for a single user input.

So for an insert command you could use:

(command "insert" "blockname" pause (getvar "dimscale") 0)

The 0 is for the rotation in this case. You could also define variables and use them, such as the 'scale' varaiable you set. Then the lisp code would be

(command "insert" "blockname" pause scale "dimscale") 0)

There are other ways to do this, depends on what you want to accomplish.

Eddie
11-01-2006, 10:16 PM
:cool: Try something like this..

(defun c:InsB ()
(setq osnapold (getvar "osmode"))
(setq dimsc (getvar "dimscale"))
(setq Inspt (getpoint "\nSelect Block insertion point: "))
(command "-insert" "Your Block Name" Inspt dimsc "" "" )
(setvar "osmode" osnapold)
)

mad@cad
16-01-2008, 12:37 PM
Yikes, Did I do it the hard way? I set my menu up with a pulldown where you pick the desired scale....

***POP12
**MEHA
ID_MnMEHA [&MEHA]
[->Symbol Insertion Scales]
[SCALES @ 3/32" PLOT ***]
[ PLAN: 3/32" -- PLOT: 3/32"]^C^C(setq xscale 1.20)(setq XFULL 1.0)(SETQ XTEXT 1.333333)
[ PLAN: 1/8" -- PLOT: 3/32"]^C^C(setq xscale 1.33)(setq XFULL 1.33)(SETQ XTEXT 1.333333)
[--]
[SCALES @ 1/8" PLOT *** ]
[ PLAN: 3/32" -- PLOT: 1/8"]^C^C(setq xscale 0.9)(setq XFULL 0.75)(SETQ XTEXT 1.0)
[ PLAN: 1/8" -- PLOT: 1/8"]^C^C(setq xscale 1.0)(setq XFULL 1.0)(SETQ XTEXT 1.0)
[ PLAN: 1/4" -- PLOT: 1/8"]^C^C(setq xscale 1.4)(setq XFULL 2.0)(SETQ XTEXT 1.0)
[ PLAN: 1/2" -- PLOT: 1/8"]^C^C(setq xscale 2.0)(setq XFULL 4.0)(SETQ XTEXT 1.0)
[--]
[SCALES @ 3/8" PLOT *** ]
[ PLAN: 3/8" -- PLOT: 3/8"]^C^C(setq xscale 0.85)(setq XFULL 1.0)(SETQ XTEXT 0.666667)
[ PLAN: 1/8" -- PLOT: 3/8"]^C^C(setq xscale 0.33)(setq XFULL 0.333333333)(SETQ XTEXT 0.666667)
[ PLAN: 1/4" -- PLOT: 3/8"]^C^C(setq xscale 0.5)(setq XFULL 0.666666667)(SETQ XTEXT 0.666667)
[ PLAN: 1/2" -- PLOT: 3/8"]^C^C(setq xscale 1.0)(setq XFULL 1.333333333)(SETQ XTEXT 0.666667)
[ PLAN: 3/4" -- PLOT: 3/8"]^C^C(setq xscale 0.56)(setq XFULL 2.0)(SETQ XTEXT 0.666667)
[--]
[SCALES @ 1/4" PLOT *** ]
[ PLAN: 1/4" -- PLOT: 1/4"]^C^C(setq xscale 0.7)(setq XFULL 1.0)(SETQ XTEXT 0.5)
[ PLAN: 1/8" -- PLOT: 1/4"]^C^C(setq xscale 0.5)(setq XFULL 0.5)(SETQ XTEXT 0.5)
[--]
[SCALES @ 1/16" PLOT *** ]
[ PLAN: 1/16" -- PLOT: 1/16"]^C^C(setq xscale 1.7)(setq XFULL 1.0)(SETQ XTEXT 2.0)
[ PLAN: 1/8" -- PLOT: 1/16"]^C^C(setq xscale 2.0)(setq XFULL 2.0)(SETQ XTEXT 2.0)
[<- PLAN: 1/4" -- PLOT: 1/16"]^C^C(setq xscale 2.8)(setq XFULL 4.0)(SETQ XTEXT 2.0)

My symbols are all on toolbars and depending on if they have attributes (this example does) look something like
-INSERT DATA;NEA;\(if xscale xscale 1);;\-ATTEDIT;;;;;L;;A;0;;

of course I DID lose my car yesterday, so maybe i should shut up

CarLB
16-01-2008, 03:58 PM
There's nothing wrong with your insert code as long as it works, it just uses command-line type input (mostly).

You could make your code shorter though..

(setq xscale 1.20)(setq XFULL 1.0)(SETQ XTEXT 1.333333)

could be:

(setq xscale 1.20 XFULL 1.0 XTEXT 1.333333)

And you seemed to have different ideas on how many decimals to use :)

mad@cad
16-01-2008, 04:55 PM
oh man I did that for release 9, it still works so....i use it

CAD-dillac
17-02-2009, 06:28 PM
Give this a try, It is annotated thru-out.
You can build your own symbols library with it.

I will help you with any questions you may have.

CAD-dillac

CAD-dillac
17-02-2009, 08:23 PM
Here is an image of the dialog.
It contains a symbols list and drawing scale insertion.
You build DXF lists in the program so you do not have
the need for external blocks.
If this is what you may be looking for, I can help you
with it if you want to suit your own needs and at
the same time learn some lisp.

CAD-dillac