understand where and what I'm doing wrong

understand where and what I'm doing wrong

roccogo
Observer Observer
408 Views
6 Replies
Message 1 of 7

understand where and what I'm doing wrong

roccogo
Observer
Observer

I have to make a routine to duplicate a series of blocks that need to be selected to make a copy of them. in this case, it is an electrical diagram, where the work is carried out on a series of blocks in a row on the X axis. In practice, the drawing that will be obtained is a row of drawn sheets where the main block is called "foglio_schema_dinamico". the insertion point of the first block (the foglio_schema_dinamico) is x=0 and Y=0. the pitch for the other blocks (the same as the first one) is 294 on the X axis so the second sheet will have the insertion point X=294 and Y=0, the third will have x= 588 and Y=0 and so on. The routine, when activated by a command or button, must:

- select the block insertion point "foglio_schema_dinamico" with the highest X value (i.e. the last in the row;

- ask to select any other objects;

- finish the selection with a send command;

- ask how many lengths (the 294) the second point (where the selected objects will be glued) should be

- exit the command.

Be careful, you must not make multiple copies, but only paste at X distances multiples of 294. In practice I must:

- copy other objects beyond the "foglio_schema_dinamico" block;

- being able to enter the number that must be multiplied by 294 which defines the glue point, therefore, 294, 588, 882 and so on;

- exit the command

 

I wrote this but it goes into error and I can't fix it, it always reports the error

 

AGGIUNGI_FOGLIO

Select the insertion point for the new block:

Selected insertion point: X=3016.56, Y=448.07; Error: Incorrect Dot Argument

Command:

 

(defun C:AGGIUNGI_FOGLIO ()
(setq insertion-point (getpoint "\nSeleziona il punto di inserzione per il nuovo blocco: "))
(if (and insertion-point (listp insertion-point))
(progn
(setq x-last (car insertion-point))
(setq y-last (cadr insertion-point))
(princ (strcat "\nPunto di inserzione selezionato: X=" (rtos x-last 2 2) ", Y=" (rtos y-last 2 2)))

(setq objects (ssget "\nSeleziona gli oggetti da copiare: "))

(if objects
(progn
(princ "\nOggetti selezionati correttamente.")

(setq num-lengths (getint "\nInserisci il numero di lunghezze (multipli di 294): "))
(setq x-offset (* num-lengths 294))

(princ (strcat "\nOffset calcolato: " (rtos x-offset 2 2)))

(setq new-point (list (+ x-last x-offset) y-last))
(princ (strcat "\nNuovo punto di inserzione: X=" (rtos (car new-point) 2 2) ", Y=" (rtos (cadr new-point) 2 2)))

;; Utilizza il comando "_COPY" per evitare problemi di localizzazione
(command "_COPY" objects "" (list x-last y-last) (list (+ x-last x-offset) y-last))

(princ "\nOperazione completata.")
)
(princ "\nNessun oggetto selezionato.")
)
)
(princ "\nErrore: selezione del punto di inserzione non valida.")
)
(princ)

)

 

 

I'm starting now with autolisp, can someone help me please? Thank you all

 

0 Likes
Accepted solutions (1)
409 Views
6 Replies
Replies (6)
Message 2 of 7

Kent1Cooper
Consultant
Consultant

Does a simple ARRAY command, using one row and a column spacing of 294, not do what you want?

Kent Cooper, AIA
0 Likes
Message 3 of 7

ec-cad
Collaborator
Collaborator
Accepted solution

Try this modification.

ssget line was incorrectly formatted.

ECCAD

 

0 Likes
Message 4 of 7

paullimapa
Mentor
Mentor

As @Kent1Cooper referenced & if you would like a graphic interface try the CLASSICARRAY command

https://help.autodesk.com/view/ACD/2025/ENU/?guid=GUID-01258C43-66E4-457E-BBD3-F7A670BC5F54


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 7

komondormrex
Mentor
Mentor

yet another one

(defun C:AGGIUNGI_FOGLIO ()
  (setq insertion-point (getpoint "\nSelect the insertion point for the new block: "))
  (if (and insertion-point (listp insertion-point))
    (progn
      (setq x-last (car insertion-point))
      (setq y-last (cadr insertion-point))
      (princ (strcat "\nInsertion point selected: X=" (rtos x-last 2 2) ", Y=" (rtos y-last 2 2)))
      (prompt "\nSelect the objects to copy...")
      (setq objects (ssget))
      
      (if objects
        (progn
          (princ "\nObjects selected correctly.")
          (setq num-lengths (getint "\nEnter the number of lengths (multiples of 294): ")
		index 1
	  )
	  (repeat num-lengths
		(foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex objects)))
			(vla-move (vla-copy (vlax-ename->vla-object ename)) 
				  (vlax-3d-point insertion-point) 
				  (vlax-3d-point (polar insertion-point 0 (* 294 index)))
			) 
		)
		(setq index (1+ index))
	 )
         (princ "\nOperation completed.")
        )
        (princ "\nNo items selected.")
      )
    )
    (princ "\nError: Invalid insertion point selection.")
  )
  (princ)
)
0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant

@paullimapa wrote:

.... try the CLASSICARRAY command


[That's ARRAYCLASSIC, as you will find if you take the link.  There are several other command names for "classic" versions of things that do start with "CLASSIC," but this one has that part after.]

Kent Cooper, AIA
0 Likes
Message 7 of 7

paullimapa
Mentor
Mentor

Thanks for the heads up. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes