Jump to content

Recommended Posts

Posted

Hi everyone!

 

I'd like to write an autolisp function, to insert a specific block.

 

So: Insert-> Block-> "myblock" + ENTER.

 

That's what I want to do from code, because it has to do 1000 times....

 

Thanks any help!

 

(it has to do somehow with "_insert" command... )

Posted

Give us some specifics.

1. Name of Block

2. Scale factor

3. Rotation angle

4. Any specific layer you want them inserted on.

Posted
Give us some specifics.

1. Name of Block

2. Scale factor

3. Rotation angle

4. Any specific layer you want them inserted on.

 

For example:

1. Name of Block: myblock

2. Scale factor: Specify on screen

3. Rotation: Specify on screen

 

or scale factor: 1 , 1 , 1

rotation: 0.0

Posted
For example:

1. Name of Block: myblock

2. Scale factor: Specify on screen

3. Rotation: Specify on screen

 

or scale factor: 1 , 1 , 1

rotation: 0.0

Quickie example...

 

(defun _InsertBlock (block x y / x y)
 ;; block - name of block
 ;; x     - X scale for block (nil for on-screen prompt)
 ;; y     - Y scale for block (nil for on-screen prompt)
 ;; Alan J. Thompson, 07.19.10
 (if (or (tblsearch "BLOCK" block) (findfile (strcat block ".DWG")))
   (if (and (or x
                (setq x (cond ((getdist "\nSpecify X value <1.0>: "))
                              (1.)
                        )
                )
            )
            (or y
                (setq y (cond ((getdist (strcat "\nSpecify Y value <" (rtos x) ">: ")))
                              (x)
                        )
                )
            )
       )
     (command "_.-insert" block "_X" x "_Y" y)
   )
   (alert (strcat "Block: \"" block "\" cannot be found!"))
 )
 (princ)
)

(defun c:Test1 (/) (_InsertBlock "P6" nil nil) (princ))

(defun c:TEst2 (/) (_InsertBlock "P6" 1. 1.) (princ))

(defun c:TEst3 (/) (_InsertBlock "P6" 1. nil) (princ))

Posted

Thanks a lot!

 

Could you give me some advice, where can I found some information about "_.-insert" command.

I've just found "_insert"...

 

And how can I wait for user input from Lisp code?

 

Thanks!!!

 

 

Quickie example...

 

(defun _InsertBlock  (block x y / x y)
 ;; block - name of block
 ;; x     - X scale  for block (nil for on-screen prompt)
 ;; y     - Y scale for block  (nil for on-screen prompt)
 ;; Alan J. Thompson, 07.19.10
 (if  (or (tblsearch "BLOCK" block) (findfile (strcat block ".DWG")))
    (if (and (or x
                (setq x (cond ((getdist "\nSpecify X  value <1.0>: "))
                              (1.)
                         )
                )
            )
             (or y
                (setq y (cond ((getdist (strcat "\nSpecify  Y value <" (rtos x) ">: ")))
                               (x)
                        )
                )
            )
       )
     (command "_.-insert" block "_X" x "_Y" y)
   )
   (alert (strcat "Block: \"" block "\" cannot be found!"))
 )
  (princ)
)

(defun c:Test1 (/) (_InsertBlock "P6" nil nil)  (princ))

(defun c:TEst2 (/) (_InsertBlock "P6" 1. 1.) (princ))

(defun  c:TEst3 (/) (_InsertBlock "P6" 1. nil) (princ))

Posted
Thanks a lot!

 

Could you give me some advice, where can I found some information about "_.-insert" command.

I've just found "_insert"...

 

And how can I wait for user input from Lisp code?

 

Thanks!!!

_ ignores language change

. ignores redefined command

- issue commandline version of command (if available)

 

Actually, this may suite you better...

 

(defun _InsertBlock (block x y r / x y r)
 ;; block - name of block
 ;; x     - X scale for block (nil for on-screen prompt)
 ;; y     - Y scale for block (nil for on-screen prompt)
 ;; r     - rotation of block (nil for on-screen prompt) [MUST BE IN RADIANS]
 ;; Alan J. Thompson, 07.19.10
 (if (or (tblsearch "BLOCK" block) (findfile (strcat block ".DWG")))
   (if (and (or x
                (setq x (cond ((getdist "\nSpecify X value <1.0>: "))
                              (1.)
                        )
                )
            )
            (or y
                (setq y (cond ((getdist (strcat "\nSpecify Y value <" (rtos x) ">: ")))
                              (x)
                        )
                )
            )
       )
     (progn
       (command "_.-insert" block "_X" x "_Y" y)
       (and r (command "_r" (angtos r)))
     )
   )
   (alert (strcat "Block: \"" block "\" cannot be found!"))
 )
 (princ)
)

(defun c:Test1 (/) (_InsertBlock "P6" nil nil nil) (princ))

(defun c:TEst2 (/) (_InsertBlock "P6" 1. 1. nil) (princ))

(defun c:TEst3 (/) (_InsertBlock "P6" nil nil pi) (princ))

Posted

Hi!

 

I want to iterate this command , so how can I wait for the user input?

 

Specificly: I want to insert my blocks, until the user say OK, its enough.

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...