Help req: Pline crossing through geometric center of a sequence of blocks

Help req: Pline crossing through geometric center of a sequence of blocks

info8
Observer Observer
575 Views
5 Replies
Message 1 of 6

Help req: Pline crossing through geometric center of a sequence of blocks

info8
Observer
Observer

Hi guys,

I'm trying to learn VLisp.

I have to write a code that draws a Pline trought the geometric center of few blocks I select, in the same sequence I select blocks.

My code passes to PLINE command alternatively X and Y coordinates instead of passing the couple X,Y.

Where I'm wrong?

Here's my code.

Thanks in advance for any useful comment.

 

(defun C:BlocchiPline ()
(prompt "\nSeleziona i blocchi in sequenza. Premi INVIO quando hai terminato.\n")

;; Lista per memorizzare i centri dei blocchi
(setq blocchiList '())

;; Loop di selezione dei blocchi
(while (setq obj (car (entsel "\nSeleziona un blocco o premi INVIO per terminare: ")))
;; Verifica se l'oggetto selezionato è un blocco (INSERT)
(if (= (cdr (assoc 0 (entget obj))) "INSERT")
(progn
;; Ottieni il punto di inserimento del blocco
(setq insertPt (cdr (assoc 10 (entget obj))))

;; Aggiungi il punto di inserimento alla lista (X e Y)
(setq blocchiList (append blocchiList (list insertPt)))

;; Stampa le coordinate del centro del blocco selezionato
(prompt (strcat "\nCentro del blocco selezionato: X=" (rtos (car insertPt) 2 3)
", Y=" (rtos (cadr insertPt) 2 3)))

;; Visualizza anche nella riga di comando per debug
(print (strcat "Centro del blocco: (" (rtos (car insertPt) 2 3) ", " (rtos (cadr insertPt) 2 3) ")"))
)

;; Caso in cui l'oggetto selezionato non sia un blocco
(prompt "\nL'oggetto selezionato non è un blocco. Riprovare.")
)
)

;; Se ci sono blocchi selezionati, disegna la polilinea
(if blocchiList
(progn
;; Inizia il comando PLINE
(command "_.PLINE")

;; Cicla attraverso i centri memorizzati e traccia la polilinea
(foreach pt blocchiList
;; Passa le coordinate X e Y come coppia al comando PLINE
(command (car pt) (cadr pt)))

;; Termina il comando PLINE senza chiudere
(command "")

(prompt "\nPolilinea creata con successo, non chiusa.\n")
)

;; Caso in cui non siano stati selezionati blocchi
(prompt "\nNon sono stati selezionati blocchi.\n")
)

(princ)
)

0 Likes
Accepted solutions (1)
576 Views
5 Replies
Replies (5)
Message 2 of 6

-didier-
Advisor
Advisor
Accepted solution

Bonjour @info8 

 

Tu sei italiano e io sono francese, noi comunicheremo in inglese, ok?

 

First I want to congratulate you because you respect the learning steps, first understand how the lisp dialogue with AutoCAD, and then we will learn in better ways, but first understand the information exchanges.

 

Your error was on this line : the red line is wrong because you send to AutoCAD, the value of Y and the value of Y separately.
You have to change by the green line : and then you send to AutoCAD the value of the point in one time.

Snag_32a929f5.png

Nota : You type "centro", but this word is not correct, the point extracted is the INSERTION point.

 

Do not hesitate to go on my site, it is in my signature at the bottom of the message.
You can contact me by private message and we will discuss.

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 3 of 6

info8
Observer
Observer

Didier I love you!!!

It's working.

You're also right in the 'center' vs 'insertion point' issue.

Mercì vive la France!!

I was looking for books and resources about visual lisp and Acad customization but it's not to easy to find something.

I'll see you website.

Thanks a lot

 

Alessio

0 Likes
Message 4 of 6

-didier-
Advisor
Advisor

Hi @info8 

You're welcome.

As I said, it's a pleasure to meet new people who want (really) to learn.
No ChatGPT, but Human brain and friends to exchange and learn.

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 5 of 6

Sea-Haven
Mentor
Mentor

There are books online I have some from "KINDLE" by Reinaldo Togores, they were very cheap to purchase, an advantage is that you can copy code from the book. They are in English. Not sure if in other languages.

 

Another is "The Visual LISP Developers Bible".

 

Don't worry if you find something and its say a few years old it is still very useful.

 

Afralisp has some good tutorials.

0 Likes
Message 6 of 6

info8
Observer
Observer

Thanks

0 Likes