Jump to content

repeat insert block - while loop


mestar

Recommended Posts

One more code.

 

MyBlock3.lsp will preset all the insert inputs such as Block Scale and Block Rotation assuming that they are the same for all inserts.

You can change these values in the code. All you need to supply is an insertion point and the code is ready for the next insert.

Of course you will need to hit escape to break the loop.

MyBlock3.lsp

Link to comment
Share on other sites

  • Replies 37
  • Created
  • Last Reply

Top Posters In This Topic

  • The Buzzard

    10

  • mestar

    10

  • Lee Mac

    7

  • gile

    6

Why all the needless functions Buzzard?

 

What you have could be achieved with just:

 

(defun c:MIns ( / b )
 (if (setq b (getfiled "Select Block" "" "dwg" 16))
   (while (not (command "_.-insert" b pause 1. 1. 0.)))
 )
 (princ)
)

Link to comment
Share on other sites

That real nice Lee, But as I said before "I am not a Lee Mac".

You are one of a kind.

 

I assume there is no need for getfiled if the block is in the working directory.

 

I think the OP was trying to avoid extra steps.

Link to comment
Share on other sites

Well I am Italian and I love my spaghetti all the same.

Since you brought it up, I think I will go have some.

Link to comment
Share on other sites

Well I am Italian and I love my spaghetti all the same.

Since you brought it up, I think I will go have some.

 

I predicted that kind of response - I almost avoided using the term, but I stick by my point however much you may disregard it.

Link to comment
Share on other sites

Another to add to the mix, if the user has Express Tools installed:

 

(defun c:MIns ( / *error* b p )

 (setq *error* (lambda ( x ) (and e (entdel e)) (princ x) (princ)))

 (if (and (setq b (getfiled "Select Block" "" "dwg" 16))
          (setq b (LM:ForceBlockDefinition b)))
   (progn 
     (while
       (progn
         (setq e (entmakex (list (cons 0 "INSERT") (cons 2 b) (list 10 0. 0. 0.))))
         (setq p (acet-ss-drag-move (ssadd e) '(0. 0. 0.) "\nPick Insertion: "))
       )
       (entmod (subst (cons 10 p) (assoc 10 (entget e)) (entget e)))
     )  
     (entdel e)
   )
 )

 (princ)
)

;;---------------=={ Force Block Definition }==---------------;;
;;                                                            ;;
;;  Ensures, if possible, that a block definition is present  ;;
;;  in a drawing.                                             ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, June 2010                          ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  block - block name or filename                            ;;
;;------------------------------------------------------------;;
;;  Returns:  Block name, else nil                            ;;
;;------------------------------------------------------------;;

(defun LM:ForceBlockDefinition ( block / path ext base )
 ;; © Lee Mac 2010
 (setq path  (vl-filename-directory block)
       ext   (vl-filename-extension block)
       base  (vl-filename-base block))

 (and (eq ""  ext) (setq ext ".dwg"))
 (or  (eq "" path) (setq path (strcat path "\\")))
 
 (cond
   ( (tblsearch "BLOCK" base) base )

   ( (setq block (findfile (strcat path base ext)))

     (command "_.-insert" block) (command) base
   )
 )
)

Link to comment
Share on other sites

I predicted that kind of response - I almost avoided using the term, but I stick by my point however much you may disregard it.

 

I see you have ESP. You must have predicted this.

Link to comment
Share on other sites

I see you have ESP. You must have predicted this.

 

I can see you are on here just to annoy me tonight - well you can entertain yourself, I'm outta here.

Link to comment
Share on other sites

I can see you are on here just to annoy me tonight - well you can entertain yourself, I'm outta here.

 

First of all: I cannot believe that actually annoyed you. It was not my intent and I am sorry if it did. You really need to learn to chill.

 

Second: While I post my efforts and these are some I have learned from others as well and pass them on, I do not rib other peoples efforts although I will take it in stride and make humor out of it when my efforts are ribbed all the same to see the lighter side of it. People receiving help here can make the own choices and judge accordingly.

 

I admire your abilities and I am in no position to poke fun at the help you provide, But I did not do that here. I poked fun at myself. Its too bad you are unable to see that.

Link to comment
Share on other sites

Another to add to the mix, if the user has Express Tools installed:

 

(defun c:MIns ( / *error* b p )

 (setq *error* (lambda ( x ) (and e (entdel e)) (princ x) (princ)))

 (if (and (setq b (getfiled "Select Block" "" "dwg" 16))
          (setq b (LM:ForceBlockDefinition b)))
   (progn 
     (while
       (progn
         (setq e (entmakex (list (cons 0 "INSERT") (cons 2 b) (list 10 0. 0. 0.))))
         (setq p (acet-ss-drag-move (ssadd e) '(0. 0. 0.) "\nPick Insertion: "))
       )
       (entmod (subst (cons 10 p) (assoc 10 (entget e)) (entget e)))
     )  
     (entdel e)
   )
 )

 (princ)
)

;;---------------=={ Force Block Definition }==---------------;;
;;                                                            ;;
;;  Ensures, if possible, that a block definition is present  ;;
;;  in a drawing.                                             ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, June 2010                          ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  block - block name or filename                            ;;
;;------------------------------------------------------------;;
;;  Returns:  Block name, else nil                            ;;
;;------------------------------------------------------------;;

(defun LM:ForceBlockDefinition ( block / path ext base )
 ;; © Lee Mac 2010
 (setq path  (vl-filename-directory block)
       ext   (vl-filename-extension block)
       base  (vl-filename-base block))

 (and (eq ""  ext) (setq ext ".dwg"))
 (or  (eq "" path) (setq path (strcat path "\\")))

 (cond
   ( (tblsearch "BLOCK" base) base )

   ( (setq block (findfile (strcat path base ext)))

     (command "_.-insert" block) (command) base
   )
 )
)

 

By the way.

Please check the last code you posted, It displays the following error.

 

Command: MINS

; error: Exception occurred: 0xC0000005 (Access Violation)

; warning: unwind skipped on exception

; error: Exception occurred: 0xC0000005 (Access Violation)

 

 

Works in 2009, But not 2004

 

 

For your information as well as others, This is just one of the persons I learned that spaghetti coding from.

 

Tony Hotchkiss, Ph.D., P.Eng., is a professor of CAD/CAM/CAE at the State University of New York College at Buffalo and a former Cadalyst contributing editor. He wrote Cadalyst's popular "AutoLISP Solutions" column through December 2008. "AutoLISP Solutions" tutorials have been tested to function with the version of AutoCAD that was current at the time the tutorial was published. Specific LISP routines may or may not function with other versions of AutoCAD, and Cadalyst staff cannot provide technical support in the event a routine does not function. Peer support for AutoLISP-related problems might be available via Cadalyst's Hot Tip Harry Discussion Forum at www.cadalyst.com/forums; users are encouraged to post requests there.

 

Here are a few more:

 

Tony Tanzillo

Organization: www.caddzone.com

 

Additional Information

Times at AU: 1

Professional Information

Membership: None, AA, AAAE, AAG, AATO, ACADIA, ACSM, ADDA, ADN, AGI, AIA, AIChE,

Alias Design Community, Area, ASCE, ASHRAE, ASID, ASLA, ASME, Association of Energy Engineers,

ASTD, ASTTBC, ATC, AUGI, AutoCAD Exchange, autodesk inventor users, Autodesk Student Community,

BOMA, buildingSMARTalliance, CAADRIA, cadforum, CaGBC, Cascadia, CIAT, CSI, GISCI, IESNA, IGDA,

IIDA, IIEE-WRC-SA, ISPLS, kivi, LEED AP, Manufacturing Community, National Institute of Building Sciences (NIBS),

NCARB, NSPE, OAA, OACETT, PEI, PEO, Revit Architecture Customer Council, Revit DC, SEAONC,

SEAW, Smart-mind Network LLC, The Association of Science, Other

Primary Field: Computer Programming

Autodesk Product Used: AutoCAD

Autodesk Product Certification: 3dx Max Design, AutoCAD, AutoCAD Architecture, AutoCAD Civil 3D, Inventor, Revit Architecture

 

Barry Bowen has written more than half a million lines of AutoLISP code.

He owns Barry R. Bowen Associates in Memphis, Tennessee.

He is also a CADALYST contributing editor and an AutoCAD and AutoLISP instructor at the University of Memphis.

 

Make sure you check the wind direction next time before you spit.

Edited by The Buzzard
Link to comment
Share on other sites

I don't give a toss where you learnt to write the code that way, in my opinion it is needlessly complicated and hence I offered my criticism accordingly. As for your other jibing comments, I saw no need for these and will certainly not be offering you any future advice or help.

Link to comment
Share on other sites

One more code.

 

MyBlock3.lsp will preset all the insert inputs such as Block Scale and Block Rotation assuming that they are the same for all inserts.

You can change these values in the code. All you need to supply is an insertion point and the code is ready for the next insert.

Of course you will need to hit escape to break the loop.

 

Thanks Buzzard,

 

I really appreciate your help!

Link to comment
Share on other sites

Thanks Lee,

 

Very nice mate! I've checked it in 2009 and 2010 (german) and it works fine!

I need to modify it slightly for my purpose.

 

The part (second) I don't understand, but never mind, I'll keep it so.

 

Thanks to all the guys who participied this time! I am glad to join this forum!

Bye!

Link to comment
Share on other sites

I don't give a toss where you learnt to write the code that way, in my opinion it is needlessly complicated and hence I offered my criticism accordingly. As for your other jibing comments, I saw no need for these and will certainly not be offering you any future advice or help.

 

I did not see your comment as much as an opinion as it was in insult. When I shrugged it off you got insulted. The scary part of this is while there are experts in their fields helping others to customize AutoCAD, You make yourself a self proclaimed expert as the only source for properly done coding disputing methods that have been taught for many years. The good part of this is there are many sources to learn from all the same.

Link to comment
Share on other sites

I did not view my comment as an insult - I criticised your code for the number of functions that you used whose purpose seemed solely to be calling other functions - as I demonstrated, the whole procedure could be achieved by three lines or so. Hence I questioned your use of so many functions.

 

As for your other comments - I do not proclaim myself to be an expert - I readily accept criticism of my own code and am always looking for ways to do things with more concision and elegance. Why shouldn't I dispute methods that have been done for many years? Does that make them right?

Link to comment
Share on other sites

  • 2 years later...

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