HypnoS Posted July 22 Posted July 22 Hi all, I was wondering if someone could help me with a lisp modyfication. I need to modify CopyBlockStoCurve lisp so I don't need to select each block individually co copy it to the curve. I thought why not copy a function from numpol, which numbers blocks according to a polyline. So I need the new CopyBlockStoCurve to arrange blocks on a curve, but in accordance with how the blocks are positioned on another polyline basiclly. Can anyone help? numpol.lspCopyBlocksToCurve.lsp Quote
SLW210 Posted July 22 Posted July 22 That's not a drawing, just images. I don't see a curve. Is the text part of the block? Really need the drawing. Quote
HypnoS Posted July 22 Author Posted July 22 okay so these are dynamic blocks with attributes, thats why i use numpol to change attribute values acording to polyline i drew over them. Now I want to use something like copyblockstocurve (wich works also with polylines) to align my blocks to new straight line in the same order numpol did the numering. So that I could use them to draw a scheme. Example.dwg Quote
BIGAL Posted July 23 Posted July 23 Another give it a try. ; https://www.cadtutor.net/forum/topic/98615-copy-blocks-to-curve-according-to-another-curve/ ; get blocks along a pline at any XY then redo as a straight line. ; By AlanH July 2025 (defun c:wow ( / bname co-ord ent obj plent pt spac ss x) (setq oldsnap (getvar 'osmode)) (setvar 'osmode 0) (setq plent (car (entsel "\pick pline joining blocks "))) (setq obj (vlax-ename->vla-object (car (entsel "\nPick block object ")))) (setq pt (getpoint "\nPick left point ")) (setq spac (getreal "\Enter spacing ")) (setq bname (vlax-get obj 'effectivename)) (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget plent)))) (setq ss (ssget "F" co-ord '((0 . "INSERT")))) (command "line" pt (mapcar '+ pt (list (* (- (sslength ss) 1) spac) 0.0 0.0)) "") (repeat (setq x (sslength ss)) (setq ent (ssname ss (setq x (- x 1)))) (setq obj (vlax-ename->vla-object ent)) (if (= (vlax-get obj 'effectivename) bname) (progn (command "copy" ent "" (vlax-get obj 'Insertionpoint) pt) (setq pt (mapcar '+ pt (list spac 0.0 0.0))) ) ) ) (princ) ) 1 Quote
HypnoS Posted July 23 Author Posted July 23 @devitg Yours seams to not work for me at all @BIGAL I can't quite go through this routine to see final result. nothing happens after i daw a line. Also I already have a polyline that goes though all blocks that I need, so the part in lisp that tells me to draw line over blocks is unnecessary To be more precise. Lisp CopyBlockstocurve works great, the only part i want to change is that I dont want to click on each block to copy it to straight line. I want them to be copied automaticlly acording to pline that is existing Quote
devitg Posted July 23 Posted July 23 @HypnoS Please show the command line text or error message. Quote
SLW210 Posted July 23 Posted July 23 3 hours ago, devitg said: @HypnoS Please show the command line text or error message. I get Command: CPY-BLK-2-POLY Select objects: ; error: bad argument type: lselsetp nil Quote
devitg Posted July 23 Posted July 23 48 minutes ago, SLW210 said: I get Command: CPY-BLK-2-POLY Select objects: ; error: bad argument type: lselsetp nil @SLW210 please upload sample dwg , where yo did apply the lisp 1 Quote
SLW210 Posted July 23 Posted July 23 On 7/22/2025 at 6:46 AM, HypnoS said: okay so these are dynamic blocks with attributes, thats why i use numpol to change attribute values acording to polyline i drew over them. Now I want to use something like copyblockstocurve (wich works also with polylines) to align my blocks to new straight line in the same order numpol did the numering. So that I could use them to draw a scheme. Example.dwg 40.24 kB · 6 downloads I used the one supplied by the OP. Quote
SLW210 Posted July 23 Posted July 23 Your latest works in AutoCAD 2000i on my home computer, though it makes a new line was that intended? I like yours a lot. Quote
devitg Posted July 23 Posted July 23 15 minutes ago, SLW210 said: Your latest works in AutoCAD 2000i on my home computer, though it makes a new line was that intended? I like yours a lot. @SLW210 it ask for the polyline where the blocks are inserted, then get the coordinates from such polyline , and use it to get all blocks as selectionset . It draw a polyline straight long enough to receive the new block at a given distance, 1000 units in this cas Then it copy each one and move to the new line 1 Quote
BIGAL Posted July 24 Posted July 24 (edited) You don't draw a line read the questions asked, pick the pline, pick the block, pick a point to draw the line & blocks and enter a gap distance between them say 1000. The line with copied blocks is automatically drawn. The line will be as long as there is blocks. Edited July 24 by BIGAL 1 Quote
Saxlle Posted July 24 Posted July 24 My contribution, you can try it: (prompt "\nTo run a LISP type: CPBLK") (princ) (defun c:CPBLK ( / old_osmode old_attdia ent ptlist spt ept delta num_offset npt ss len i val data block_name data tag_value num ct) (setq old_osmode (getvar 'osmode)) (setq old_attdia (getvar 'attdia)) (setvar 'attdia 0) (setq ent (car (entsel "\nPick the LINE:\n")) ptlist (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget ent))) spt (vlax-curve-getStartPoint (vlax-ename->vla-object ent)) ept (vlax-curve-getEndPoint (vlax-ename->vla-object ent)) delta (- (car ept) (car spt)) num_offset (/ delta (length ptlist)) npt (getpoint "\Pick insertation point for new LINE:") ) (setvar 'osmode 0) (command-s "_LINE" npt (strcat "@" (rtos delta) "<" (itoa 0)) "") (setq ss (ssget "_F" ptlist (list (cons 0 "INSERT"))) len (sslength ss) i 0 val (list) ) (while (< i len) (setq data (entget (ssname ss i)) block_name (cdr (assoc 2 data)) ) (while (/= (cdr (assoc 0 data)) "SEQEND") (setq data (entget (entnext (cdr (assoc -1 data)))) tag_value (cdr (assoc 1 data)) val (append val (list (list tag_value block_name))) ) ) (setq i (1+ i)) ) (setq val (vl-remove-if-not '(lambda (x) (/= (car x) nil)) val) num 0 ct 0 ) (repeat (length val) (command-s "-insert" block_name (list (+ (car npt) num) (cadr npt)) 1 0 (car (nth ct val))) (setq num (+ num num_offset) ct (1+ ct) ) ) (setvar 'osmode old_osmode) (setvar 'attdia old_attdia) (prompt (strcat "\nCopied " (itoa (length val)) " blocks along path.")) (princ) ) and it looks like on the .mp4: Recording2025-07-24at08.56.33-ezgif.com-gif-to-mp4-converter.mp4 1 Quote
HypnoS Posted July 24 Author Posted July 24 @devitg Yours works great. the only thing I would like to add is to set a distance between blocks on the line, just like the copyblockstocurve has. @Saxlle Yours also works, but if block doesn't have scale uniformly set to 1, it asks to type scale, rotation and attribute value, and it goes block by block. Its unnessery. Quote
BIGAL Posted July 24 Posted July 24 (edited) @Saxlle I realised should check which way line is drawn. So it will order based on end selected. A reverse of the block list where applicable. The "-insert" not sure if your missing, 1 1 0 the extra one, you can imply "S" 1 gets around the scale problem. command "-INSERT" blkname "s" 1 pt 0.0) I used copy so that the block is copied then don't need to worry about attributes. Edited July 24 by BIGAL Quote
Saxlle Posted July 25 Posted July 25 15 hours ago, HypnoS said: but if block doesn't have scale uniformly set to 1, it asks to type scale, rotation and attribute value, and it goes block by block. Its unnessery. This can be easily done, but, for that I need another example drawing from you or you can just play with that inside this part of code: (while (/= (cdr (assoc 0 data)) "SEQEND") (setq data (entget (entnext (cdr (assoc -1 data)))) tag_value (cdr (assoc 1 data)) val (append val (list (list tag_value block_name))) ) ) where you can add in variable "val" scale factor, rotation, etc. and implement inside this part of code: (command-s "-insert" block_name (list (+ (car npt) num) (cadr npt)) 1 0 (car (nth ct val))) instend of "1" and "0" (scale and rotation). 8 hours ago, BIGAL said: I realised should check which way line is drawn. So it will order based on end selected. A reverse of the block list where applicable. Yes @BIGAL, I know for that and also thinked about that, but for that, the user need to clarify direction of drawed polyline and eventualy reverse the polyline to get right orded of the blocks. It is a task that takes 5 seconds. 8 hours ago, BIGAL said: command "-INSERT" blkname "s" 1 pt 0.0) The "-insert" command are executed with the appropriate queries on my AutoCAD, so I can't say does it good or not. But, as always, thank you @BIGAL . Quote
Recommended Posts
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.