Author Topic: Copy block from xref  (Read 8516 times)

0 Members and 1 Guest are viewing this topic.

cadman6735

  • Guest
Copy block from xref
« on: December 08, 2015, 08:35:46 AM »
I am looking to see if there is code floating about that will copy a "block" from an "xref"?

I have found numerous code that will copy/Ncopy elements - lines, circles, etc... from the block from the xref but not the actual block itself, does this exist and can someone point me to it?


Thanks

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Copy block from xref
« Reply #1 on: December 08, 2015, 09:07:49 AM »
you can get the blockname with something like..

Code: [Select]
(entget (caar (reverse (nentsel))))
then,..insert it ?
Keep smile...

cadman6735

  • Guest
Re: Copy block from xref
« Reply #2 on: December 08, 2015, 11:46:45 AM »
Thank you Andrea

I can use that

how would I convert the insertion point location from the xref to the current file?  is there a function or method for that?

thanks

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Copy block from xref
« Reply #3 on: December 08, 2015, 03:54:57 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:nrefcopy ( / ns l p )
  2.   (setq l (last (setq ns (nentsel "\nPick nested reference to copy from parent reference"))))
  3.   (setq p (cadr ns))
  4.   (command "_.-REFEDIT" "_non" p)
  5.   (repeat (- (length l) 2)
  6.     (command "_N")
  7.   )
  8.   (command "_O" "_N" "_non" p "" "_Y")
  9.   (command "_.COPY" "_non" p "")
  10.   (while (< 0 (getvar 'cmdactive))
  11.     (command "\\")
  12.   )
  13.   (command "_.REFSET" "_R" (entlast) "")
  14.   (command "_.REFCLOSE" "_D")
  15.   (princ)
  16. )
  17.  

HTH, M.R.
« Last Edit: December 09, 2015, 06:15:25 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

lamarn

  • Swamp Rat
  • Posts: 636
Re: Copy block from xref
« Reply #4 on: December 08, 2015, 04:45:27 PM »
 I find it useful. However, i made up a little adjustement

Code: [Select]
(defun c:nrefcopy ( / ns e p )
(setq e (cadar (reverse (setq ns (nentsel "\nPick nested reference to copy from parent reference")))))
(setq p (cadr ns))
(command "_.-REFEDIT" "_non" p "_O" "_N" "_non" p "" "_Y")
(command "_.COPY" "_non" p "" "0,0" "0,0" "")
;(while (< 0 (getvar 'cmdactive)) (command "\\"))  ..? did not understand what it does..?
(command "_.REFSET" "_R" (entlast) "")
(command "_.REFCLOSE" "d")  ; discard all changes, PICK THE ITEM BUT DO NOT SAVE, POSSIBLE FILE PROP REVISIONS ETC., ITS SAVER 
(command "_.move" p "" pause)  ; HIGHLIGHT IT AND BEGIN A MOVE ACTION
(princ)
)

What do you think?
Design is something you should do with both hands. My 2d hand , my 3d hand ..

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Copy block from xref
« Reply #5 on: December 09, 2015, 02:29:16 AM »
thank you! It will be very useful function because NCOPY function from Express tools can't do it..

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Copy block from xref
« Reply #6 on: December 09, 2015, 06:17:37 AM »
lamarn, I agree only with this intervention :

Code: [Select]
(command "_.REFCLOSE" "d")
BTW. I've updated my code... I think that now it's as it should be - copying references any level deep nesting...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

cadman6735

  • Guest
Re: Copy block from xref
« Reply #7 on: December 09, 2015, 11:28:05 AM »
I'm blown away...


Ribarm, your code gets stuck in refedit, how does it copy from any level deep?


Thanks
« Last Edit: December 09, 2015, 11:32:30 AM by cadman6735 »

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Copy block from xref
« Reply #8 on: December 09, 2015, 12:14:04 PM »
I'm blown away...


Ribarm, your code gets stuck in refedit, how does it copy from any level deep?


Thanks

Well, you just pick 2 points - base point and destination... Everything is automated - couldn't you just understand (while (< 0 (getvar 'cmdactive)) - (until command is active - COPY command) => (command "\\") - (waits with pause for user input - you pick points - or specify them by typing like COPY command) )-parenthesis closed - while loop is finished - you picked 2 points and routine continues with REFSET and so on...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

cadman6735

  • Guest
Re: Copy block from xref
« Reply #9 on: December 09, 2015, 12:36:32 PM »

Quote
couldn't you just understand

Thanks for the explanation,
honestly, I am skilled enough in lisp for very, very simple functions and enough to be dangerous.  I tried your code and it copied the block in the refedit mode, which I was not expecting and assumed it was copying and leaving the block in the reference.  I canceled out of it before finishing the command - reading your post to lamarn's about (command "_.REFCLOSE" "d") discard all changes, I assumed your code was broken.

lamarn's code did more to what I was expecting to happen and there we go, that was my circle of logic.

But Thank you very, very much for your help

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Copy block from xref
« Reply #10 on: December 09, 2015, 01:00:31 PM »
Look lamarn code is doing the same thing but using 2 commands COPY+MOVE and that's needless... It seems that you are avoiding to understand following lines - REFSET "_REMOVE" - after you make copy of block inside of XREF/BLOCK space it's removed from reference space and placed into MODEL BLOCK space... After that it's totally irrelevant weather XREF/BLOCK will be saved or not - my firstly written code had (command "_.REFCLOSE" "") which mean that it'll be saved, but you haven't made no modifications to XREF/BLOCK by copying block and removing it from XREF/BLOCK space (you made modification to MODEL BLOCK space)... But to cut the story, I agreed with lamarn - it's better not to save changes as it may take some time and it really shouldn't do that - and I've made correction to that line - now it's written (command "_.REFCLOSE" "_D") - discard changes... But the real point of my revision was variable "e" which wasn't used anywhere and replacing nesting level of picking to the most deep one - look into -REFEDIT command (- prefix is important) to understand what arguments should be supplied to lisp to make it working properly - you'll see that it'll ask for level of nesting and with "_N" (Next) you choose the correct one after which you are to input "Ok" and that's why I used (repeat (- (length l) 2) (command "_N")) to provide correct level and that's obtained by (nentsel) function and last element return list...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

cadman6735

  • Guest
Re: Copy block from xref
« Reply #11 on: December 09, 2015, 02:49:56 PM »
Ribarm,

you are correct, I did fail to understand, I really like your tool, I can grab any element at any depth, I see this now.  Thank you very much for your time and explanation.

I took what actions I saw on the screen as not what I expected and canceled before fully understanding, I failed to examine and try to understand the code.

you have been a great help to me.

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Copy block from xref
« Reply #12 on: December 14, 2015, 01:34:32 AM »
Thanks Marko Ribar!
Is it possible to make some changes in your program in order to copy more than one block from xref in one session?
Your current version of this program published here:

https://lispbox.wordpress.com/2015/12/14/copy-block-from-xref/

All rights Reserved


ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Copy block from xref
« Reply #13 on: December 14, 2015, 03:10:24 AM »
danglar, thanks for publishing, only this is making confusion :

https://lispbox.wordpress.com/2015/12/09/copy-block-or-other-entities-from-xref/

And to the question :
You can wrap (complete function into (while loop)) - and to make it iterate through sel.set of blocks, I think that that route is dead end...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:nrefcopy ( / ns l p )
  2.   (while (setq ns (nentsel "\nPick nested reference to copy from parent reference"))
  3.     (setq l (last ns))
  4.     (setq p (cadr ns))
  5.     (command "_.-REFEDIT" "_non" p)
  6.     (repeat (- (length l) 2)
  7.       (command "_N")
  8.     )
  9.     (command "_O" "_N" "_non" p "" "_Y")
  10.     (command "_.COPY" "_non" p "")
  11.     (while (< 0 (getvar 'cmdactive))
  12.       (command "\\")
  13.     )
  14.     (command "_.REFSET" "_R" (entlast) "")
  15.     (command "_.REFCLOSE" "_D")
  16.   )
  17.   (princ)
  18. )
  19.  
« Last Edit: December 14, 2015, 04:03:52 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

danglar

  • Newt
  • Posts: 161
  • Read My Li(s)(p)
Re: Copy block from xref
« Reply #14 on: December 14, 2015, 04:54:51 AM »
Sorry about my mistake  :uglystupid2:

Page updated with respect to your rights..

And to the program..

I thought about endless loop, but it can be a real problem when you have "heavy" drawing, because edit in place in this case become too slowly..
Is it possible to make selection set during the one session of refedit function?