Author Topic: Combining multiple blocks and renaming group block  (Read 6914 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
Combining multiple blocks and renaming group block
« on: April 16, 2008, 10:41:31 AM »
Hey guys,

I am having to take existing blocks and combine them to form an assembly block. The name of the assembly block will be sort of a combination of the 2 blocks and I'm trying to see if I can automate this process to eliminate typing errors. I have attached a sample drawing which goes into more detail about the process involved. I have about 300 blocks I currently need to do this for and this is a main part of my job so I'd like to streamline it if at all possible. Take a look and tell me if it's feasible. Thanks

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Combining multiple blocks and renaming group block
« Reply #1 on: April 16, 2008, 01:23:34 PM »
Dan, The side blocks PK-07.62B3_L do not have the text as part of the block but the combined block does.
Was that you intent to select the mtext objects as well?

Pseudo Code
Code: [Select]
Select main block
Selection: Select blocks & text, should include main block
Create name
Verify block name
Select insert point
Make new combo block
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Re: Combining multiple blocks and renaming group block
« Reply #2 on: April 16, 2008, 01:40:25 PM »
Yes CAB the text is intentionally not a part of the nested block in order to not have to have a left and right block with different labels so I would need to select the text as well.

ELOQUINTET

  • Guest
Re: Combining multiple blocks and renaming group block
« Reply #3 on: April 16, 2008, 01:56:37 PM »
Hey CAB another thing I discovered after I posted this is that the middle case will have a suffix (_M) that will need to be stripped off as was the case with the _LR

ELOQUINTET

  • Guest
Re: Combining multiple blocks and renaming group block
« Reply #4 on: April 16, 2008, 02:53:16 PM »
CAB how much harder would it be to allow the user to specify what part of string they need to strip off or replace. I haven't been doing this job that long but I think the block naming strategy and could vary slightly depending on how many options we have so it would be nice to eventually be able to input whatever info i need to strip or replace.

ELOQUINTET

  • Guest
Re: Combining multiple blocks and renaming group block
« Reply #5 on: April 18, 2008, 09:07:12 AM »
I'm guessing I will have to do this manually, for now at least as it is time to actually do it. This is going to be a long day  :|

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Combining multiple blocks and renaming group block
« Reply #6 on: April 18, 2008, 10:03:01 AM »
Dan,

I looked at your example but could not follow exactly what you wanted.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ELOQUINTET

  • Guest
Re: Combining multiple blocks and renaming group block
« Reply #7 on: April 18, 2008, 01:30:50 PM »
Hmmm what part didn't you understand. I know it's not real straight forward but I thought I explained it pretty well. Basically I need to combine all three blocks into a group block and this group blocks name will consist of the mentioned parts from each of it's nested block names. Let me know what doesn't make sense and I'll try to spell it out better. Attached are a couple of files which may paint the bigger picture of what I'm doing.


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Combining multiple blocks and renaming group block
« Reply #8 on: April 18, 2008, 04:13:03 PM »
Per the pseudo code and No error checking.
Code: [Select]
;;  Combo Block.lsp
(defun c:cblock (/ bent bname bname2  pos pt ss)
  (setvar "clayer" "0")
  (if
    (and
      (setq bent (entsel "\nSelect main block for name."))
      (setq bname (cdr (assoc 2 (entget (car bent))))
            bname (strcase bname)
            bname (vl-string-subst "GROUP_" "_" bname)
      )
      (setq bent2 (entsel "\nSelect sub block for name."))
      (setq bname2 (cdr (assoc 2 (entget (car bent2))))
            bname2 (strcase bname2)
            pos    (vl-string-position (ascii ".") bname2)
            bname2 (substr bname2 (+ pos 2))
            pos    (vl-string-position (ascii "_") bname2)
            bname2 (substr bname2 1 pos)
            bname  (strcat bname "_" bname2)
      )
      (princ "\nSelect objects to makup the new block.")
      (setq ss (ssget))
      (setq pt (getpoint "\nPick Insert point."))
    )
     (command "-block" bname "non" pt ss "" "-insert" bname "non" pt "" "" ""
             )
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Re: Combining multiple blocks and renaming group block
« Reply #9 on: April 18, 2008, 05:26:22 PM »
Oh CAB you are OOOO so close and probably would have nailed it right on the head if I would have conveyed some info I forgot I needed after I posted the example. The only 2 problems I have is that the prefix ELEVGROUP needs to be lowercase as it is in the example. The second part is what I forgot to mention and that is that the first block will now have an _M at the end of the name but I assume it can be stripped in a similar way that the _LR was. Oh CAB did I ever tell you that you amaze me, I'm sure I have but I'll say it again. You have made my week, Virtual Beer on me.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Combining multiple blocks and renaming group block
« Reply #10 on: April 18, 2008, 05:39:49 PM »
How's this?
Code: [Select]
(defun c:cblock (/ bent bname bname2  pos pt ss)
  (setvar "clayer" "0")
  (if
    (and
      (setq bent (entsel "\nSelect main block for name."))
      (setq bname (cdr (assoc 2 (entget (car bent))))
            ;; bname (strcase bname)
            bname (vl-string-subst "elevgroup_" "elev_" bname)
            bname (vl-string-subst "" "_M" bname)
      )
      (setq bent2 (entsel "\nSelect sub block for name."))
      (setq bname2 (cdr (assoc 2 (entget (car bent2))))
            bname2 (strcase bname2)
            pos    (vl-string-position (ascii ".") bname2)
            bname2 (substr bname2 (+ pos 2))
            pos    (vl-string-position (ascii "_") bname2)
            bname2 (substr bname2 1 pos)
            bname  (strcat bname "_" bname2)
      )
      (princ "\nSelect objects to makup the new block.")
      (setq ss (ssget))
      (setq pt (getpoint "\nPick Insert point."))
    )
     (command "-block" bname "non" pt ss ""
              "-insert" bname "non" pt "" "" "")
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Re: Combining multiple blocks and renaming group block
« Reply #11 on: April 19, 2008, 09:13:28 AM »
I'll have to test it on Monday CAB but will let you know. Thanks again for your help.

ELOQUINTET

  • Guest
Re: Combining multiple blocks and renaming group block
« Reply #12 on: April 21, 2008, 09:25:41 AM »
CAB this works perfectly thank you so much this saves me alot of time and will cut down alot of errors.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Combining multiple blocks and renaming group block
« Reply #13 on: April 21, 2008, 10:14:58 AM »
You're welcome.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ELOQUINTET

  • Guest
Re: Combining multiple blocks and renaming group block
« Reply #14 on: April 21, 2008, 11:42:53 AM »
CAB sorry about this but I found something and again this is probably my fault for not clarifying. I was just reviewing my notes from the meeting with my boss and the format is missing something. It turns out I also need to replace the dot from the first block with an underscore so from the example I gave you the code should read:

elevgroup_PK-07_60BBB3_62B3

not

elevgroup_PK-07.60BBB3_62B3

I was trying to figure it out but there's alot of substitution going on in there. Gimme a hint  :ugly: