Automate Block Creation

Automate Block Creation

wgtkna
Observer Observer
1,338 Views
3 Replies
Message 1 of 4

Automate Block Creation

wgtkna
Observer
Observer

Automate Block Creation Macro

Curley question for all you AutoCAD macro masters out there.

I have an issue where I need a macro that automates the repetitive process of making an AutoCAD block.

 

Im often tasked to create cut files for manufacturing processes. These cut files are generally closed polylines that contain a part number in the form of single line text & various other geometries contained within the boundary of the closed polyline.

My normal workflow to create a single part is

  1. Double click on the part number which is AutoCAD single line text to bring up the text editor
  2. Highlight & copy the part number onto the clipboard (ctrl+c)
  3. Escape out of the text editor
  4. Bring up the AutoCAD block pallet (“block” or “b” command)
  5. Paste the copied part number into the block name field
  6. Select a base point
  7. Select the objects
  8. Press Enter and im done with one part

 

I use this workflow for Three reasons,

  1. It groups all the geometries nicely together
  2. It throws up a duplicate part number red flag in the form of the AutoCAD redefine block prompt if I accidently have duplicate part numbers
  3. It allows me to copy all parts elsewhere in model space and nest all the parts / blocks into sheets while still maintaining some order of the original parts. I end up with 2 instances of each part /block. 1 which is where I originally created it and a second instance which is nested in a sheet elsewhere in model space. If I need to go back to modify A part I can do that in the original instance area which is uncluttered and has the surrounding parts adjacent for reference. I find trying to modify parts after they have been nested difficult as they are often orientated at odd angles as a result of the nesting process.  

 

I have made a short screencast of my workflow to illustrate should the above not make sense. You can view it on here https://youtu.be/b__oUKJ9zDQ

 

While some people may not think my process to tedious I tend to go a little crazy when some of my assemblies are getting up to 1000 parts.

It would be great if I hade a Macro that automated steps 1 through 10 above that pauses for user input at steps 1, 6 & 7.

Any help greatly appreciated.       

  

0 Likes
1,339 Views
3 Replies
Replies (3)
Message 2 of 4

3wood
Advisor
Advisor

Welcome to the forum!

I watched your video on YouTube.

Just a couple of questions:

1. If every part has a outline on a special layer and all geometries are within this outline, it will be much easier.

2. If Insertion point of the part is not important, it will be even easier.

If above 2 conditions are true, it only takes a few seconds to automatically complete your task with a lisp function.

Otherwise it still has a simple solution but need manually select contents and insertion point for each part.

0 Likes
Message 3 of 4

wgtkna
Observer
Observer

Hi there and thanks for looking into this for me.

 

Answers below inserted after your question.

 

 

1. If every part has a outline on a special layer and all geometries are within this outline, it will be much easier.

Answer: The part outlines are not always on the same layer. The part outline is on a layer that matches its stock type. so if a part is to be cut from 10mm plywood the layer name the outline is on will be called "10mm Plywood". If the part is to be cut from 20mm plywood then the outline would be on layer "20mm plywood" All geometries are always contained within a closed polyline as you suggest above but there are however sometimes closed polylines within the boundry of the part outline. They could be called nested closed polylines I guess. I jut mention this in case it makes a difference to you.  

 

2. If Insertion point of the part is not important, it will be even easier.

Answer: the insertion point is important and differs on each block. I would need to manually select the insertion point on each block instance.

 

Note

I could if you like make the part number on its own unique layer. perhaps call the layer "Part Number" so when i select all the geometries to make up a block the only item on layer Part Number is the block name?

 

 

If above 2 conditions are true, it only takes a few seconds to automatically complete your task with a lisp function.

Otherwise it still has a simple solution but need manually select contents and insertion point for each part.

 

cool looking forward to see what you come up with.

Cheers

Bob.

 

 

0 Likes
Message 4 of 4

3wood
Advisor
Advisor

This week is quite busy for me.

Here is a very rough lisp which allows you manually making blocks one by one.

You can change all text objects to layer "Part Number first" by selecting them with "SELECTSIMILAR" or "QSELECT" whatever.

Save it as a lsp file, then load it in AutoCAD with command APPLOAD.

 

;;; bmk.lsp by 3wood
;;; 2016.11.07
;;; Create block by picking a text representing its name, then insert block in current layer.

(defun c:bmk (/ bname ins)
  (setq bname (cdr (assoc 1 (entget (car(entsel))))))
  (command "._-block")
  (command bname)
  (command (setq ins (getpoint)))
  (command (ssget) "")
  (command "._-insert" bname ins "" "" "")
  )

When I get some time, I will be back with a solution which automatically create all blocks depending their outlines. The default insertion point is the text insertion point, but you can easily change it with a lsp add-on.

 

 

 

 

0 Likes