hi again ,
i have an attribute block which i copied everywhere in my project and now i need to copy my new block from it`s insertion point to insertion points of those attribute blocks
my attribute block name is "Att.Inf" and new block name which i want to copy is "AR_Value"
i wished copy some codes here for you can modify it but i can not say that i am a good programmer 🙂 can somebody share with me who made it similar lisp before , already ?
i wanna realise with that lisp how to specify insertion point of blocks to lisp routine for to use it in different actions , it would be nice with an explanation about it
thank you
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Solved by hmsilva. Go to Solution.
@E.S.7.9 wrote:
hi again ,
i have an attribute block which i copied everywhere in my project and now i need to copy my new block from it`s insertion point to insertion points of those attribute blocks
my attribute block name is "Att.Inf" and new block name which i want to copy is "AR_Value"
Hi E.S.7.9
if the "Att.Inf" and "AR_Value" are the block names, and those blocks are not dynamic, perhaps something like this:
(defun c:demo ( / blk blk1 pt pt1 ss ss1) ;; first test selctions ;; a single object in a not locked layer "_+.:E:S:L" ;; an insert (0 . "INSERT") ;; with attributes (66 . 1) ;; named (2 . "Att.Inf") (if (and (princ "\nSelect the \"Att.Inf\" to be copied: ") (setq ss (ssget "_+.:E:S:L" ((0 . "INSERT") (66 . 1) (2 . "Att.Inf")))) ;; second test selctions ;; from all database "_X" ;; all inserts (0 . "INSERT") ;; with attributes (66 . 1) ;; named (2 . "AR_Value") ;; in the current layout (cons 410 (getvar 'CTAB)) (setq ss1 (ssget "_X" (list '(0 . "INSERT") '(66 . 1) '(2 . "AR_Value") (cons 410 (getvar 'CTAB))) ) ) ) ;; if the return from the test selctions is True (progn ;; assign the variable blk with the list returned from entget ;;the ename from the only object in selection set ss (setq blk (entget (ssname ss 0))) ;; assign the variable pt with the insertion point from the blk 'dxf 10' (setq pt (cdr (assoc 10 blk))) ;; repeat and assign the variablr 'i', the length of selection set ss1 (repeat (setq i (sslength ss1)) ;; assign the variable 'i' with the the length of selection set ss1 subtracting one ;; assign the enane from the entity in 'ss1' with the index 'i' to the 'blk1' variable (setq blk1 (ssname ss1 (setq i (1- i))) ;; assign to the 'pt1' varable the insertion point from the 'blk1' 'dxf 10' pt1 (cdr (assoc 10 (entget blk1))) ) ;; copy the entity in ss to the insertion point from the current blk1 insert (command "_.copy" ss "" "_NONE" pt "_NONE" pt1) );; repeat );; progn );; if (princ) );; demo
Hope that helps
Henrique
You can try attached MBLOCKREPLACE.vlx.
When it prompts "Delete original blocks? [Yes / No] <Yes>:" enter "N".
thank you for your explanation hmsilva
when i tried your lisp , it gave an error "" error: bad argument type: consp 1"" , do you have an idea why it`s happening?
@E.S.7.9 wrote:
thank you for your explanation hmsilva
when i tried your lisp , it gave an error "" error: bad argument type: consp 1"" , do you have an idea why it`s happening?
A function is expecting an list as argument, has received an incorrect argument type...
If possible, attach the two blocks, so you can test the code with the blocks...
Rereading the code I noticed an error, replace
(setq ss (ssget "_+.:E:S:L" ((0 . "INSERT") (66 . 1) (2 . "Att.Inf"))))
with
(setq ss (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1) (2 . "Att.Inf"))))
Henrique
Hmsilva , now it`s working but there something is not exactly correct , for example there are 20 piece of attribut blocks and routine is copying my block 20 time to PT1 point but its not for each attribut block , so routin is not specify PT1 points for every similar blocks and it s copying to same point ..
so i need your help once again ....
thank you for your help
@E.S.7.9 wrote:
... but there something is not exactly correct , for example there are 20 piece of attribut blocks and routine is copying my block 20 time to PT1 point but its not for each attribut block , so routin is not specify PT1 points for every similar blocks and it s copying to same point ..
Should not...
Post a sample dwg.
Henrique
hi again hmsilva
that was my mistake , somehow it didnt work in my drawing when i tried first time but i tried in another drawings and it`s working perfectly .... thank you again ...
in this routine i gave you spesific block names , but is there any possibility for to change this routin with veriable block names ?
in this case first i will select my base block which i want to copy , and after that i will select to target block in entire drawing ..
if it`s not going to be a big problem , can you revised the routine , please? it will be much usefull for me
thank you for your help
You're welcome, E.S.7.9.
Revised code:
(defun c:demo1 ( / blk blk1 bname pt pt1 ss ss1 ss2) ;; first test selctions ;; a single object in a not locked layer "_+.:E:S:L" ;; an insert (0 . "INSERT") ;; with attributes (66 . 1) ;; named (2 . "Att.Inf") (if (and (princ "\nSelect the block to be copied: ") (setq ss (ssget "_+.:E:S:L" '((0 . "INSERT") (66 . 1)))) ;; second test selctions ;; a single object "_+.:E:S" ;; an insert (0 . "INSERT") ;; with attributes (66 . 1) (princ "\nSelect the block to copie to: ") (setq ss2 (ssget "_+.:E:S" '((0 . "INSERT") (66 . 1)))) ;; get the block name, and assigns the bname with it (setq bname (cdr (assoc 2 (entget (ssname ss2 0))))) ;; third test selctions ;; from all database "_X" ;; all inserts (0 . "INSERT") ;; with attributes (66 . 1) ;; named (cons 2 bname) the name returned from selection ss2 ;; in the current layout (cons 410 (getvar 'CTAB)) (setq ss1 (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 bname) (cons 410 (getvar 'CTAB))) ) ) ) ;; if the return from the test selctions is True (progn ;; assign the variable blk with the list returned from entget ;;the ename from the only object in selection set ss (setq blk (entget (ssname ss 0))) ;; assign the variable pt with the insertion point from the blk 'dxf 10' (setq pt (cdr (assoc 10 blk))) ;; repeat and assign the variablr 'i', the length of selection set ss1 (repeat (setq i (sslength ss1)) ;; assign the variable 'i' with the the length of selection set ss1 subtracting one ;; assign the enane from the entity in 'ss1' with the index 'i' to the 'blk1' variable (setq blk1 (ssname ss1 (setq i (1- i))) ;; assign to the 'pt1' varable the insertion point from the 'blk1' 'dxf 10' pt1 (cdr (assoc 10 (entget blk1))) ) ;; copy the entity in ss to the insertion point from the current blk1 insert (command "_.copy" ss "" "_NONE" pt "_NONE" pt1) );; repeat );; progn );; if (princ) );; demo
I hope that helps
Henrique
hmsilva , hi again ,
about the lisp , i dont understand why ? but sometimes it`s working sometimes it`s not , again the same problem i have ... when i select to object which i need to copy to other blocks in entire drawing , lisp realised that how much it has to copy but not to all target blocks just to one of them ...
i added jpg file , as you can see , lisp copied my blokc A to block B , six times but the same point
would be nice if you could check to lisp once again
thank you
@E.S.7.9 wrote:
hmsilva , hi again ,
about the lisp , i dont understand why ? but sometimes it`s working sometimes it`s not , again the same problem i have ... when i select to object which i need to copy to other blocks in entire drawing , lisp realised that how much it has to copy but not to all target blocks just to one of them ...
i added jpg file , as you can see , lisp copied my blokc A to block B , six times but the same point
Hi, if possible, attach that dwg...
Henrique
henrique , i attached dwg
i copied original blocks which i am going to use in my drawing and i tried with demo1 lisp , i have to same problem
i took your time , sorry about that ... actually , i couldn`t understand this problem is coming from lisp code or my drawing
thanks again
Hi E.S.7.9,
I did test the code with your dwg in AC2010, 2012 and 2014, without error.
Unfortunately, I can't reproduce that behavior, and I have not the slightest clue what could cause that...
Tested with 200 'AR_Value' blocks.
Try with the attached file.
Hope it works as expected...
Henrique
this is strange , i tried to lisp code in 2014 and it wasn`t work , but after your last information about versions i tried it in autocad 2013 and it worked there ..difficult to understand why ? but the problem is not lisp code ...
thank you so much for your help , Henrique