Jump to content

LISP program that automatically put a copied nested block into a new generated subsequent Layer


Recommended Posts

Posted

Hello guys,

 

hope someone can help me with this

 

Is there a LISP where if you copy a nested dynamic block the new copied block will be on a new automatically subsequent generated layer and all inside sub blocks as well?

 

Lets say a nested dynamic block and all its nested block inside are on "M1" layer and if you make a copy of it, the copied block will be on "M2" layer and all its nested block 

 

Thank you

Test.dwg

Posted

That's not how blocks work. you can have a dynamic block that changes shape or attributes that can change. but once you start changing the layer or other core proprieties that affect goes to all blocks sharing that name.  you would essentially have to explode and remake the block and all nested blocks under a different name and then join them back in the same order.

  • Like 1
Posted
35 minutes ago, mhupp said:

That's not how blocks work. you can have a dynamic block that changes shape or attributes that can change. but once you start changing the layer or other core proprieties that affect goes to all blocks sharing that name.  you would essentially have to explode and remake the block and all nested blocks under a different name and then join them back in the same order.

Precisely .. quick example for OP:

(if (setq e (car (nentsel)))
  (progn (vla-put-color (vlax-ename->vla-object e) 3) (command "_.regen"))
)

 

  • Like 1
Posted (edited)

This is not a normal route, so I don't know if it's possible

I just simply thought about it.

 

how about to make routine like this

1. copy block

2. create a new empty drawing

3. paste block

4. rename their layers

5. rename blocks

6. copy and paste them back into the original drawing.

 

generally lisp only works in one drawing, 

so you'll have to divide it in half to write a routine, or find another way.

nested blocks and dynamic blocks are beyond my learning scope, so I am not sure.

Edited by exceed
  • Like 2
Posted (edited)

@exceed It has to be a completely different name. If you insert a block from another drawing by copy and paste even tho it has different layers/colors/entity's if their is already a block with that name in the block library then AutoCAD uses the defined block.

 

--edit--oops missed step 5

 

Ask me how I know that? about 4-5 years ago we would just make quick blocks named block-1, block-2, block-3... everything was fine for about 2 months then someone was like "ill take a block from this drawing and put it into this drawing". messed up about a weeks worth of work because the profiles were different enough that the material we were cutting was unusable. but not so different that when you pasted the block you noticed a difference.

 

Why I use this in my quick block lisp

;;;========================================================================
;;;                    *** AUTO-BLOCK.LSP ***                              
;;;     BLOCK CREATION ON THE FLY : "Just select your objects"             
;;;               By Raymond RIZKALLAH, October/2004                       
;;;========================================================================

(defun Set_BlkName ()
  (setq o-dmzn (getvar "dimzin"))
  (setvar "dimzin" 0)
  (setq c-date (getvar "cdate"))
  (setq w-all (rtos c-date 2 20))         ;; >> "20041022.11423489"
  (setq w-yr (substr w-all 3 2))          ;; ["01" to "99"] >> "04"
  (setq w-mn (substr w-all 5 2)           ;; ["A" to "L"] >> "J"
        w-mn (chr (+ 64 (read w-mn)))     ;;
  )
  (setq w-dy (substr w-all 7 2))          ;; ["A" to "Z" + "1" to "5"] >> "V"
  (if (<= (read w-dy) 26)                 ;;
    (setq w-dy (chr (+ 64 (read w-dy))))  ;;
    (setq w-dy (rtos (- (read w-dy) 26) 2 0))  ;;
  )
  (setq w-hr (substr w-all 10 2)       ;; ["A" to "S"] >> "K"
        w-hr (chr (+ 64 (read w-hr)))  ;;
  )
  (setq w-mt (strcat (substr w-all 12 1) "-" (substr w-all 13 1)))  ;; ["00" to "59"] >> "4-2"
  (setq w-sc (substr w-all 14 2))  ;; ["00" to "59"] >> "34"
  (setq w-mm (substr w-all 16 2))  ;; ["00" to "59"] >> "89"
  (setq blkname (strcat "$" w-mn w-sc w-hr w-mt w-dy w-yr w-mm))  ;; >> "$J34K4-2V0489"
  (setvar "dimzin" o-dmzn)
  (princ)
)

 

Edited by mhupp
  • Like 2
Posted
5 hours ago, mhupp said:

@exceed It has to be a completely different name. If you insert a block from another drawing by copy and paste even tho it has different layers/colors/entity's if their is already a block with that name in the block library then AutoCAD uses the defined block.

 

--edit--oops missed step 5

 

Ask me how I know that? about 4-5 years ago we would just make quick blocks named block-1, block-2, block-3... everything was fine for about 2 months then someone was like "ill take a block from this drawing and put it into this drawing". messed up about a weeks worth of work because the profiles were different enough that the material we were cutting was unusable. but not so different that when you pasted the block you noticed a difference.

 

Why I use this in my quick block lisp

;;;========================================================================
;;;                    *** AUTO-BLOCK.LSP ***                              
;;;     BLOCK CREATION ON THE FLY : "Just select your objects"             
;;;               By Raymond RIZKALLAH, October/2004                       
;;;========================================================================

(defun Set_BlkName ()
  (setq o-dmzn (getvar "dimzin"))
  (setvar "dimzin" 0)
  (setq c-date (getvar "cdate"))
  (setq w-all (rtos c-date 2 20))         ;; >> "20041022.11423489"
  (setq w-yr (substr w-all 3 2))          ;; ["01" to "99"] >> "04"
  (setq w-mn (substr w-all 5 2)           ;; ["A" to "L"] >> "J"
        w-mn (chr (+ 64 (read w-mn)))     ;;
  )
  (setq w-dy (substr w-all 7 2))          ;; ["A" to "Z" + "1" to "5"] >> "V"
  (if (<= (read w-dy) 26)                 ;;
    (setq w-dy (chr (+ 64 (read w-dy))))  ;;
    (setq w-dy (rtos (- (read w-dy) 26) 2 0))  ;;
  )
  (setq w-hr (substr w-all 10 2)       ;; ["A" to "S"] >> "K"
        w-hr (chr (+ 64 (read w-hr)))  ;;
  )
  (setq w-mt (strcat (substr w-all 12 1) "-" (substr w-all 13 1)))  ;; ["00" to "59"] >> "4-2"
  (setq w-sc (substr w-all 14 2))  ;; ["00" to "59"] >> "34"
  (setq w-mm (substr w-all 16 2))  ;; ["00" to "59"] >> "89"
  (setq blkname (strcat "$" w-mn w-sc w-hr w-mt w-dy w-yr w-mm))  ;; >> "$J34K4-2V0489"
  (setvar "dimzin" o-dmzn)
  (princ)
)

 

 

 

It is interesting as it is like generating a serial code number.

or looks like a temporary number is created in PASTEBLOCK with ctrl+shifth+v. 

 

Tharwat has made a simple way to find unused block names in links using tblsearch.

 

replace 1~3 with wblock, then write the name of the unused block in the dwg file name in same directory.

and then process then import it again. 

 

perhaps in this case i should think about how to apply this to nested blocks.

like BLOCK1_SUB1, BLOCK1_SUB2...

or your method may be better. 

 

  • Like 1
Posted
5 hours ago, mhupp said:

@exceed It has to be a completely different name. If you insert a block from another drawing by copy and paste even tho it has different layers/colors/entity's if their is already a block with that name in the block library then AutoCAD uses the defined block.

 

--edit--oops missed step 5

 

Ask me how I know that? about 4-5 years ago we would just make quick blocks named block-1, block-2, block-3... everything was fine for about 2 months then someone was like "ill take a block from this drawing and put it into this drawing". messed up about a weeks worth of work because the profiles were different enough that the material we were cutting was unusable. but not so different that when you pasted the block you noticed a difference.

 

Why I use this in my quick block lisp

;;;========================================================================
;;;                    *** AUTO-BLOCK.LSP ***                              
;;;     BLOCK CREATION ON THE FLY : "Just select your objects"             
;;;               By Raymond RIZKALLAH, October/2004                       
;;;========================================================================

(defun Set_BlkName ()
  (setq o-dmzn (getvar "dimzin"))
  (setvar "dimzin" 0)
  (setq c-date (getvar "cdate"))
  (setq w-all (rtos c-date 2 20))         ;; >> "20041022.11423489"
  (setq w-yr (substr w-all 3 2))          ;; ["01" to "99"] >> "04"
  (setq w-mn (substr w-all 5 2)           ;; ["A" to "L"] >> "J"
        w-mn (chr (+ 64 (read w-mn)))     ;;
  )
  (setq w-dy (substr w-all 7 2))          ;; ["A" to "Z" + "1" to "5"] >> "V"
  (if (<= (read w-dy) 26)                 ;;
    (setq w-dy (chr (+ 64 (read w-dy))))  ;;
    (setq w-dy (rtos (- (read w-dy) 26) 2 0))  ;;
  )
  (setq w-hr (substr w-all 10 2)       ;; ["A" to "S"] >> "K"
        w-hr (chr (+ 64 (read w-hr)))  ;;
  )
  (setq w-mt (strcat (substr w-all 12 1) "-" (substr w-all 13 1)))  ;; ["00" to "59"] >> "4-2"
  (setq w-sc (substr w-all 14 2))  ;; ["00" to "59"] >> "34"
  (setq w-mm (substr w-all 16 2))  ;; ["00" to "59"] >> "89"
  (setq blkname (strcat "$" w-mn w-sc w-hr w-mt w-dy w-yr w-mm))  ;; >> "$J34K4-2V0489"
  (setvar "dimzin" o-dmzn)
  (princ)
)

 

This is interesting

 

Thank you for your replies @mhupp @ronjonp @exceed

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