Author Topic: Insert New Block above existing Block in Layout tabs  (Read 2108 times)

0 Members and 1 Guest are viewing this topic.

Fett2oo5

  • Guest
Insert New Block above existing Block in Layout tabs
« on: January 04, 2016, 05:53:21 PM »
I'm just a beginner but have big wishes and goals.  I'm looking for a way to add revision blocks to multiple layout tabs (single .dwg file) at one time.

Per project, we design our product in 2D, in one .dwg file.  AutoCAD 2013.
We use the layout tabs for multiple views of the objects that are in modelspace, (each layout tab has the project titleblock on it, but each layout tab has its own set of revision blocks.)
We "stack" the revision blocks in the Y direction, please see first screenshot)

There are times in the project when ALL layout tabs need the same revision description. For example, Issue for Construction, P.E. comments, As Built... etc.  This was previously done by inserting the revision block, editing attributes, Copy-Basepoint, switching to each layout tab, and pasting above the existing RevBlk.

So we would like to be able to insert a revision block into each layout tab using a dialog box or excel.

Explained simply (hopefully): The routine would find the revision block (RevBlk) with the largest Y value (because we "stack" the revision blocks in the Y direction, please see example) and insert a new revision block (RevBlk) above it.  The height (in Y direction) of the block is .1271, so the new RevBlk would need it's insertion point @0,.1271,0 in relation to the existing RevBlk with the highest Y value.  Please see first screenshot:




Our Layout Tab labels follow this sequence:


Following that numbering sequence these are possible but not so frequent:




It would be nice if we could control the insertion of new revisions from a dialog box:
(the routine would need to detect what tabs were available?)
I'm sorry for the way it looks, the only way I know how to make one is in Excel's VBA




This routine would be a sub-part of other sequences, but I need to start here before it gets bigger.
So I'm hoping this smaller task will help me along with the larger endeavor.

***
I've reached out for help in a few places but to no avail.

Is this too ambitious?
Perhaps I could piece this together?

1. Find the insertion points of a particular block across all layout tabs. (block name will never change: RevBlk)

2. Prompt user for new attribute values, preferably in a dialog box as shown above.

3.Insert the same block (RevBlk, it will already be loaded into drawing) at the largest Y value of another RevBlk +.1271, across all layout tabs.

The part that is tripping me up is the "across all layout tabs"

If no code solution is available; links to examples, tutorials, similar situations, anything will help.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Insert New Block above existing Block in Layout tabs
« Reply #1 on: January 05, 2016, 10:24:31 AM »
Welcome to TheSwamp! .. Here's a quick example without user input how to copy & increment the revision block value on each layout tab. I've added comments so you can learn from it :).


Code - Auto/Visual Lisp: [Select]
  1. (defun c:revs ;; Localized variables & functions
  2.               (/ _dxf _copy _getattval _setattval blks co o rev ss)
  3.   ;; < / Helper functions
  4.   (defun _dxf (code ename)
  5.     (if (and ename (= (type ename) 'ename))
  6.       (cdr (assoc code (entget ename '("*"))))
  7.     )
  8.   )
  9.   (defun _getattval (block tag / att out)
  10.     (foreach att (vlax-invoke block 'getattributes)
  11.       (if (eq (strcase tag) (strcase (vla-get-tagstring att)))
  12.         (setq out (vla-get-textstring att))
  13.       )
  14.     )
  15.     out
  16.   )
  17.   (defun _setattval (block tag value / att out)
  18.     (foreach att (vlax-invoke block 'getattributes)
  19.       (if (eq (strcase tag) (strcase (vla-get-tagstring att)))
  20.         (setq out (vla-put-textstring att value))
  21.       )
  22.     )
  23.     out
  24.   )
  25.   (defun _copy (obj from to / out)
  26.     (cond ((setq out (vlax-invoke obj 'copy)) (vlax-invoke out 'move from to) (vla-update out) out))
  27.   )
  28.   ;; Helper functions \ >
  29.   ;;
  30.   ;; Foreach paperspace tab
  31.     ;; If we find 'revblk'(s) on that tab
  32.     (if (and (setq ss (ssget "_X" (list '(0 . "insert") (cons 410 tab) '(2 . "RevBlk"))))
  33.              ;; Convert the selection set to a list
  34.              (setq ss (mapcar 'cadr (ssnamex ss)))
  35.              ;; Sort the blocks by greatest Y value & grab the first item
  36.              (setq ss (car (vl-sort ss '(lambda (a b) (> (caddr (_dxf 10 a)) (caddr (_dxf 10 a)))))))
  37.              ;; Add the first item ( greatest Y ) to a 'blks' list
  38.              (setq blks (cons ss blks))
  39.         )
  40.       ;; Iterate the 'blks' list
  41.       (foreach blk blks
  42.         (if (and ;; Convert block from 'ename' to vla-object
  43.                  (setq o (vlax-ename->vla-object blk))
  44.                  ;; Make a copy + 0.127148 in the Y
  45.                  (setq co (_copy o '(0.0 0.0 0.0) '(0.0 0.127148 0.0)))
  46.             )
  47.           (progn ;; Check that the att value is a number
  48.                  (or (and (setq rev (_getattval o "R#"))
  49.                           (numberp (read rev))
  50.                           ;; Increment the value by 1
  51.                           (setq rev (itoa (1+ (atoi rev))))
  52.                      )
  53.                      ;; Or set it to 0
  54.                      (setq rev "0")
  55.                  )
  56.                  ;; Set new attribute values in the copied block
  57.                  (_setattval co "R#" rev)
  58.                  (_setattval co "REVl1" (strcat "DESCRIPTION FOR REV - " rev))
  59.                  (_setattval co "REVB" "YODA")
  60.                  (_setattval co "REVD" (menucmd "M=$(edtime,$(getvar,date),M\"/\"YY)"))
  61.           )
  62.         )
  63.       )
  64.     )
  65.   )
  66.   (princ)
  67. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Fett2oo5

  • Guest
Re: Insert New Block above existing Block in Layout tabs
« Reply #2 on: January 06, 2016, 05:45:59 PM »
Wow, Ron that is very nice!  And works wonderfully!

That is a big head-start to get this thing rolling.

Thank you very much!

Ron, when I run it:  It will place a new block (RevBlk) above the existing one, but it will also place #.  # being the amount of layout tabs there are.
So if there are 6 Layout tabs, a quantity of 6 blocks will be inserted.  I'm learning/sifting through it to find where this is happening.


And thank you for the welcome, I've been a lurker here for a while now, and it was time I became more involved.  I'm excited about learning as much as I can.
« Last Edit: January 06, 2016, 06:09:20 PM by Fett2oo5 »

BlackBox

  • King Gator
  • Posts: 3770
Re: Insert New Block above existing Block in Layout tabs
« Reply #3 on: January 06, 2016, 11:39:05 PM »
Forgive what might be a silly question, but have you considered simply using Sheet Set Manager (SSM) custom Properties, to populate your attributed title block(s), etc with FIELDs?

Cheers
"How we think determines what we do, and what we do determines what we get."

Fett2oo5

  • Guest
Re: Insert New Block above existing Block in Layout tabs
« Reply #4 on: January 07, 2016, 02:24:46 PM »
Well my new friends, I've got some bad news.

I was told I am going to be laid off.  I'm to finish my current design/engineering projects and after about 2 weeks I'll need to find a new employer.

So I won't be able to put much attention (if any) on this project for a little bit. If you are interested in this project please subscribe to it.

As for this project thread, I'm going to make the DCL that I was referencing in the OP, and then we could go from there?

Thank you for the help so far.  I'm not going to give up on this project thread, but I can not devote the time to it in the next few weeks as I hoped I could.
Know that I will be coming back to this project I feel it is to versatile and useful to let it die.

I hope to be back posting soon.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Insert New Block above existing Block in Layout tabs
« Reply #5 on: January 07, 2016, 02:48:07 PM »
Well my new friends, I've got some bad news.

I was told I am going to be laid off.  I'm to finish my current design/engineering projects and after about 2 weeks I'll need to find a new employer.

So I won't be able to put much attention (if any) on this project for a little bit. If you are interested in this project please subscribe to it.

As for this project thread, I'm going to make the DCL that I was referencing in the OP, and then we could go from there?

Thank you for the help so far.  I'm not going to give up on this project thread, but I can not devote the time to it in the next few weeks as I hoped I could.
Know that I will be coming back to this project I feel it is to versatile and useful to let it die.

I hope to be back posting soon.
Sorry to hear that  :(

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3770
Re: Insert New Block above existing Block in Layout tabs
« Reply #6 on: January 07, 2016, 03:00:02 PM »
That is most unfortunate; good luck on your job search.
"How we think determines what we do, and what we do determines what we get."