Jump to content

Recommended Posts

Posted

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

Posted

Can you post a before and after drawing?

Posted

That's not a drawing, just images.

 

I don't see a curve.

 

Is the text part of the block?

 

Really need the drawing.

Posted

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

Posted

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

 

  • Thanks 1
Posted

@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

Posted
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
 

Posted
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

 

  • Like 1
Posted
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.

Posted

Your latest works in AutoCAD 2000i on my home computer, though it makes a new line was that intended?

 

I like yours a lot.

Posted
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  

  • Like 1
Posted (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.

image.png.88f65b950ce1c55bda34b6462e7136e0.png

Edited by BIGAL
  • Like 1
Posted

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:

 

 

 

  • Like 1
Posted

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

Posted (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 by BIGAL
Posted
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 👍.

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