Code Red > AutoLISP (Vanilla / Visual)

Insert block and ask for scale

(1/5) > >>

like_citrus:
I have a few blocks inserted from a pull down menu, and wanted to scale them as the block is inserted. The scale is variable and the user inputs this when the block is inserted.

The code below inserts blocks but needs something to ask for a scale.
All the blocks, except for one can be scaled using the "SCALE" command if done manually. The Dimension block can't be scaled using "SCALE", it's adjusted manually from the Properties toolbar by changing "Dim scale overall".

The process used:
- Create a folder and save the AutoCAD source files and menu (MNU) file in there.
- Load the menu file using the command "CUILOAD".
- Link this to AutoCAD by including in Support File Search Path. Tools/Options/Files tab. Add folder to Support File Search Path.
- Have the LISP code load automatically using the command "APPLOAD". Add the file to the Startup Suite.

MENU CODE

--- Code: ---***MENUGROUP=MENU_TEMPORARY
***POP110
**CTOPopAID_DYNAMIC_TEMPORARY

            [Temporary]
            [<-Leader]^C^C(BlockInsertAndScale "CAD_Leader");
            [<-Dimension]^C^C(BlockInsertAndScale "CAD_Dimension");
            [--]
--- End code ---

LISP

--- Code: ---(defun BlockInsertAndScale (blkname)
    (command "_.-insert" (substr (strcat blkname "-" (menucmd "m=$(edtime,0,yymoddhhmmss)") "=" blkname) (+ (vl-string-position (ascii "_") blkname 1) 2)) pause 1 "" 0)
    (command "explode" "last")
)
--- End code ---

BIGAL:
try replacing pause with (getreal "Enter scale")

like_citrus:
Thanks.
I did try it, something happened but it didn't work exactly.
There was this prompt in the command line: Specify insertion point or [Basepoint Scale X Y Z Rotate]
After typing in a value it just pasted the object. And it didn't paste in the location clicked on. Also I couldn't see a silhouette of the object before it was pasted like before.


--- Code: ---(defun BlockInsertAndScale (blkname)
    (command "_.-insert" (substr (strcat blkname "-" (menucmd "m=$(edtime,0,yymoddhhmmss)") "=" blkname) (+ (vl-string-position (ascii "_") blkname 1) 2)) (getreal "Enter scale") 1 "" 0)
    (command "explode" "last")
     (setq blkname (getvar "dimscale")) 
)
--- End code ---

ribarm:
AFAIK, first pause is for specifying insertion point and not for speciying scale... So IMHO, you should leave first pause and replace 1 with (progn (initget 3) (getreal "\nEnter scale : "))...

like_citrus:
Thanks, that actually works.
I think it will work for all the blocks except as expected, for the Dimension block.
With the Dimension block, the arrow, offset, etc. are no scaled for some reason. If it's done manually, it's adjusted from the Properties toolbar by changing "Dim scale overall".


--- Code: ---(defun BlockInsertAndScale (blkname)
    (command "_.-insert" (substr (strcat blkname "-" (menucmd "m=$(edtime,0,yymoddhhmmss)") "=" blkname) (+ (vl-string-position (ascii "_") blkname 1) 2)) pause (progn (initget 3) (getreal "\nEnter scale : ")) "" 0)
    (command "explode" "last")
)
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version