Author Topic: block change error  (Read 3022 times)

0 Members and 1 Guest are viewing this topic.

dussla

  • Bull Frog
  • Posts: 291
block change error
« on: May 09, 2018, 05:10:06 AM »
Hello seniors
I have come a long time, but I will have to ask you again
I'm really sorry
As a beginner, I can not lift my face except for help,
I'm really sorry
I try to change the block, not the difference.
There is  yellow and red block
I would like to change   red block  with yellow block
so i tested many block change lisp

Could you tell me how?
i attched cad file ~
« Last Edit: May 09, 2018, 09:02:58 AM by dussla »

ChrisCarlson

  • Guest
Re: block change error
« Reply #1 on: May 09, 2018, 07:57:28 AM »
I'm sure there is a language barrier but I cannot tell what your problem / question is.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: block change error
« Reply #2 on: May 09, 2018, 09:28:58 AM »
Here's a simple example assuming that your blocks are already the same size like in your example drawing.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ a b b1 b2 c d)
  2.   (cond ((and (setq b1 (car (entsel "\nPick block to replace: ")))
  3.               (setq b2 (car (entsel "\nPick block to copy: ")))
  4.               (vl-every '(lambda (x) (= "INSERT" (cdr (assoc 0 (entget x))))) (list b1 b2))
  5.               (setq b1 (vlax-ename->vla-object b1))
  6.               (setq b2 (vlax-ename->vla-object b2))
  7.               (vl-every '(lambda (x) (vlax-write-enabled-p x)) (list b1 b2))
  8.          )
  9.          (vla-put-rotation b2 (vla-get-rotation b1))
  10.          (vla-getboundingbox b1 'a 'b)
  11.          (vla-getboundingbox b2 'c 'd)
  12.          (vla-move b2 c a)
  13.         )
  14.   )
  15.   (princ)
  16. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dussla

  • Bull Frog
  • Posts: 291
Re: block change error
« Reply #3 on: May 09, 2018, 09:44:47 AM »
I really appreciate it.
It's perfect.
I do not know why other Lisps do not work
I do not know if the blocks are missing.

I am trying to modify the code of those who have excellent programming skills
It's really difficult

May I ask you one more thing?
I want to exchange lots of blocks

With one yellow block
If you have a lot of code to fix if you have a lot of red blocks to replace
Thank you so much

Once again, outstanding talent is a compliment.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: block change error
« Reply #4 on: May 09, 2018, 10:11:27 AM »
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ b co s w x y z)
  2.   (cond ((and (setq b (car (entsel "\nPick block to copy: ")))
  3.               (= "INSERT" (cdr (assoc 0 (entget b))))
  4.               (setq b (vlax-ename->vla-object b))
  5.               (vlax-write-enabled-p b)
  6.               (print "Pick blocks to replace: ")
  7.               (setq s (ssget ":L" '((0 . "INSERT"))))
  8.               (setq s (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
  9.          )
  10.          (foreach b2 (vl-remove b (mapcar 'vlax-ename->vla-object s))
  11.            (vla-put-rotation b (vla-get-rotation b2))
  12.            (setq co (vla-copy b))
  13.            (vla-getboundingbox b 'w 'x)
  14.            (vla-getboundingbox b2 'y 'z)
  15.            (vla-move co w y)
  16.            (vla-delete b2)
  17.          )
  18.         )
  19.   )
  20.   (princ)
  21. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dussla

  • Bull Frog
  • Posts: 291
Re: block change error
« Reply #5 on: May 09, 2018, 10:40:36 AM »
really thank you   for   your effort~

pls can you check   errro
there is error
 error: bad argument type: numberp: nil

sorry ~~~

ronjonp

  • Needs a day job
  • Posts: 7529
Re: block change error
« Reply #6 on: May 09, 2018, 10:42:13 AM »
Post a sample drawing.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dussla

  • Bull Frog
  • Posts: 291
Re: block change error
« Reply #7 on: May 09, 2018, 10:44:55 AM »
Post a sample drawing.

this dwg file ~~
thank you for helping ~~

ronjonp

  • Needs a day job
  • Posts: 7529
Re: block change error
« Reply #8 on: May 09, 2018, 10:47:37 AM »
Post a sample drawing.

this dwg file ~~
thank you for helping ~~
Works here .. not sure what is going on.


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dussla

  • Bull Frog
  • Posts: 291
Re: block change error
« Reply #9 on: May 09, 2018, 10:59:03 AM »

Solved
My notepad++ sometimes has an error.
Thank you very much
I always envy your great ability.
This is the time to sleep.
I do not know what time it is in your country.
I really hope you have a comfortable and lucky day. :smitten:

ronjonp

  • Needs a day job
  • Posts: 7529
Re: block change error
« Reply #10 on: May 09, 2018, 11:14:52 AM »

Solved
My notepad++ sometimes has an error.
Thank you very much
I always envy your great ability.
This is the time to sleep.
I do not know what time it is in your country.
I really hope you have a comfortable and lucky day. :smitten:
Glad to help :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ahsattarian

  • Newt
  • Posts: 112
Re: block change error
« Reply #11 on: January 25, 2021, 04:35:01 AM »
Check AutoCAD Command    :    BLOCKREPLACE