Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Insert multiple Instances of same block

12 REPLIES 12
Reply
Message 1 of 13
t.jarrett
1313 Views, 12 Replies

Insert multiple Instances of same block

Does anyone know of a way or a Autolisp routine that allows you to insert multiple instances of the same block at different locations in the same drawing?  I am looking to insert several instances of the same block to the insertion point of all the text obects in a drawing.  I have looked online and only found suggestions of writing a script using the coordintates of the the text exported from the LIST command.  I was hoping there was an easier way.  Ideally it would be nice to have a Autolisp routine that allowed you to select objects and then insert the blocks to those objects insertion points.

Tags (2)
12 REPLIES 12
Message 2 of 13
chauhuh
in reply to: t.jarrett

This can be easily done in a macro. Just prepend the command with *^C^C "commands to insert goes here".

 

Thanks.

Message 3 of 13
t.jarrett
in reply to: chauhuh

Wouldn't this still require me to manually select each text object or
insert every coordinate into this macro? I was looking for a more
automated way if possible.

This email and any files enclosed, contain confidential business information
for use only by the addressed, please note that, in accordance with
Permasteelisa Group Policy, the company could read them. Any views or opinions
presented in this email are solely those of the author and do not necessarily
represent those of the Company. If you have received this email in error,
please delete it from your system. Any use or distribution of the contents of
this email by a not-intended recipient or in violation of the purposes of this
email is strictly prohibited and could be unlawful. Permasteelisa Group accepts
no liability for any damage caused by any virus, worm, trojan program or any
other malicious program transmitted by this email.
Message 4 of 13
chauhuh
in reply to: t.jarrett

Did you even try it?

 

*^C^C-INSERT V:/AutoCAD/blocks/Standard/hatch-patterns/EARTH;\;;;

 

This will insert the block over and over and over until you exit out of the command...

Message 5 of 13
t.jarrett
in reply to: chauhuh

No I didn't try it. Thank you for your responses. I will try it but I'm not
at work now. I believe this will still require me to select each location
to place the block which I would like to try and avoid if possible.

This email and any files enclosed, contain confidential business information
for use only by the addressed, please note that, in accordance with
Permasteelisa Group Policy, the company could read them. Any views or opinions
presented in this email are solely those of the author and do not necessarily
represent those of the Company. If you have received this email in error,
please delete it from your system. Any use or distribution of the contents of
this email by a not-intended recipient or in violation of the purposes of this
email is strictly prohibited and could be unlawful. Permasteelisa Group accepts
no liability for any damage caused by any virus, worm, trojan program or any
other malicious program transmitted by this email.
Message 6 of 13
toolbox2
in reply to: t.jarrett

Can't remember where this came from but I think this will do what you want.

"Copy to Points"

1. Select an object to copy (can be any object)

2. Select all the target objects.

 

 

(defun c:C2PNT ( / ss blk n ent pnt1 pnt2)

  (setq ent (entsel "\nSelect object to copy : "))

  (setq pnt1 (getpoint "\nPick base point: "))

  (princ "\nSelect objects to copy to : ")

  (setq ss (ssget))
  (setq n (1- (sslength ss)))

  (while (>= n 0)
    (setq pnt2 (cdr (assoc 10 (entget (ssname ss n))))
            n (1- n)
    );; setq
   (command "_COPY" ent "" pnt1 pnt2 "")

  );;while


(princ)

);; defun

Message 7 of 13
Kent1Cooper
in reply to: t.jarrett


@t.jarrett wrote:

...  I am looking to insert several instances of the same block to the insertion point of all the text obects in a drawing.  ....


It would not be difficult to make a routine that would find all Text objects for you and Insert the Block at each one.  A question:  Do you have multiple layouts, and if so, do you want the Block added at all Text objects in all layouts?  Or only in the current space, whatever that is?  Also, would the Block be at scale factors of 1, and rotation of 0, or perhaps scaled differently and/or aligned with the direction of each Text object?

Kent Cooper, AIA
Message 8 of 13
t.jarrett
in reply to: toolbox2

Toolbox2,
Thanks for this lisp routine. It is a step in the direction I am looking
to get in order to simplify the process. Thanks!


Message 9 of 13
t.jarrett
in reply to: Kent1Cooper

Kent1Cooper,

I only have one layout but if possible I would want to select or have
selected text that matches the criteria that starts with "!C*". All of
this work would be done in model space. The block would be at a scale
factor of 1 and would be great if it was aligned with the direction of each
text object. Let me know what else I can provide you. Thanks!

Message 10 of 13
Kent1Cooper
in reply to: t.jarrett


@t.jarrett wrote:

.... I would want to select or have selected text that matches the criteria that starts with "!C*". All of this work would be done in model space. The block would be at a scale factor of 1 and would be great if it was aligned with the direction of each text object. ....


This seems to work, in very limited testing:

 

(defun C:BAET ; = Block At Each Text
  (/ textss i textdata)
  (setvar 'ctab "Model"); [just in case...]
  (if (setq textss (ssget "_X" '((0 . "TEXT") (410 . "Model") (1 . "!C*"))))
    (repeat (setq i (sslength textss))
      (setq textdata (entget (ssname textss (setq i (1- i)))))
      (entmake
        (list
          '(0 . "INSERT")
          '(410 . "Model")
          (cons 8 (getvar 'clayer)); Layer <-- uses Current Layer -- EDIT as desired, or:
;;        replace line above with line below to put each Block on Text entity's Layer
;;        (assoc 8 textdata)
          '(2 . "YourBlockName"); Block name <-- EDIT as desired -- MUST BE IN DRAWING already
          (assoc 10 textdata); insertion point [of Left-justified Text, left end of baseline of other justifications]
          (assoc 50 textdata); rotation
          '(41 . 1.0) '(42 . 1.0) '(43 . 1.0); Scale factors
        ); list
      ); entmake
    ); repeat
  ); if
); defun

 

Note that when doing this with (entmake), the Block needs to be defined in the drawing already.  If it might not be, there are ways to test whether it is, and bring it in if needed.  Or it could be done using an Insert command, in which case if the Block is a drawing in some folder in the Support File Search Path list, it will find it, so there's no need to have it in the drawing already, nor to check whether it is.

 

If you might have Text that's other-than-Left-justified, and you want the Blocks' insertion points at the Text's insertion points, rather than at the left end of the baseline, that can be accounted for, but it involves determining what the justification is, and using either (assoc 10) or (assoc 11) depending on what it finds.  If they're always only other-than-Left justication(s), you can simply change the 10 to 11.

Kent Cooper, AIA
Message 11 of 13
t.jarrett
in reply to: Kent1Cooper

Kent1Cooper,

Sorry for not getting back to you sooner.  I was out of the office and wasn't able to give test this out.  I have not been able to get it to work though. When I run BAET it returns:

 

Command: BAET
((0 . "INSERT") (410 . "Model") (8 . "0") (2 . "UNIT-PACK CODE") (10 1688.52
533.72 1594.62) (50 . 2.88808) (41 . 1.0) (42 . 1.0) (43 . 1.0))

 

I have updated the lisp to include the correct block name and I also updated the text association to assoc 11 since none of the text is left justifed.  This block is already defined in the drawing.

 

I am included the file that I am testing with for your reference.  You will see one instance of the block in the drawing and in the correct location.  The inserition point of the block is the same as the insertion point of the text begining with "!CAV...".  This block needs to be copied in the same location for all of the text beginning with the !C.

 

Maybe I am missing something easy but I am not very proficient in ready the lisp code but I try.  Thanks for your help.

 

 

Message 12 of 13
Kent1Cooper
in reply to: t.jarrett


@t.jarrett wrote:

.... 

 

...I also updated the text association to assoc 11 since none of the text is left justifed.  ....


You didn't post the code as adjusted, so I don't see how you did that, but it should be done by replacing this in my routine:

 

(assoc 10 textdata)

 

which is that left-end-of-baseline location of the Text, imported directly as the insertion point of the Block [since those are both (assoc 10) in the two entity types] with this, to turn the (assoc 11) insertion point of the non-Left-justified Text into the (assoc 10) insertion point of the Block:

 

(cons 10 (cdr (assoc 11 textdata)))

 

If you did it that way, maybe seeing the entire adjusted routine would reveal the problem.

Kent Cooper, AIA
Message 13 of 13
t.jarrett
in reply to: Kent1Cooper

I have now updated the routine to replace (assoc 10 textdata) with (cons 10 (cdr (assoc 11 textdata))) and that seems to paste the block correctly.  Before i was just changed the numbers 10 with the nubmers 11.

 

(defun C:BAET ; = Block At Each Text
  (/ textss i textdata)
  (setvar 'ctab "Model"); [just in case...]
  (if (setq textss (ssget "_X" '((0 . "TEXT") (410 . "Model") (1 . "!C*"))))
    (repeat (setq i (sslength textss))
      (setq textdata (entget (ssname textss (setq i (1- i)))))
      (entmake
        (list
          '(0 . "INSERT")
          '(410 . "Model")
          (cons 8 (getvar 'clayer)); Layer <-- uses Current Layer -- EDIT as desired, or:
;;        replace line above with line below to put each Block on Text entity's Layer
;;        (assoc 8 textdata)
          '(2 . "UNIT-PACK CODE"); Block name <-- EDIT as desired -- MUST BE IN DRAWING already
          (cons 10 (cdr (assoc 11 textdata))); insertion point [of Left-justified Text, left end of baseline of other justifications]
          (assoc 50 textdata); rotation
          '(41 . 1.0) '(42 . 1.0) '(43 . 1.0); Scale factors
        ); list
      ); entmake
    ); repeat
  ); if 
 ); defun

 Now I have 2 concerns still after I run the routine:

  1. The blocks are not visible. I know they are there because if I run a quickselect it will recognize them but it isn't until I save, close and reopen the file that I can see the blocks.  I have tried regen but that didn't work.
  2. There are not attributes in the copied blocks.  I have to run ATTSYNC to update the copied blocks.

Can either of these 2 issues be fixed by the routine?

 

Thanks for getting me this far!

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost