Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Snapping to the centroid of a regular polygon 3

Status
Not open for further replies.

Binary

Mechanical
May 16, 2003
247
Does anybody know of a means to snap to the centroid of a regular polygon (squares, rectangles, & hexagons)?

I do a lot of work with these shapes and regularly draw construction lines to find the centroids so that I can reference other entities to them.

I think that if I knew Lisp or VBA for ACAD it couldn't be too hard to program.
 
Replies continue below

Recommended for you

point filters?

or

(defun midpt ()
(if (= cal nil)
(arxload "geomcal")
)
(setq pt1 (getpoint "\n Select First Point for Midway Calculation")
pt2 (getpoint "\n Select Second Point for Midway Calculation"))
(cal "(pt1+pt2)/2")
)
 
Hi...

With this routine you will be able to obtain the centroid of any figure of type LWPOLYLINE...

Code:
(defun c:centroide ()
  (setvar "cmdecho" 0)
  (while (not (setq lwpol (car (entsel "\nSeleccione polilinea: "))))
  )
  (while (/= "LWPOLYLINE" (cdr (assoc 0 (entget lwpol))))
    (prompt
      "\n*** La entidad seleccionada no es una LWPOLYLINE ***"
    )
    (while (not (setq lwpol (car (entsel "\nSeleccione polilinea: "))))
    )
  )
  (setq lwpol-vl (vlax-ename->vla-object lwpol))
  (setq coordenadas (vlax-get lwpol-vl "coordinates"))
  (setq xl 0)
  (setq yl 0)
  (setq zl 0)
  (setq xyz 2)
  (setq ind 0)
  (repeat (length coordenadas)
    (cond
      ((= (rem ind xyz) 0)
       (setq xl (+ xl (nth ind coordenadas)))
      )
      ((= (rem ind xyz) 1)
       (setq yl (+ yl (nth ind coordenadas)))
      )
      ((= (rem ind xyz) 2)
       (setq zl (+ zl (nth ind coordenadas)))
      )
    )
    (setq ind (1+ ind))
  )
  (setq x (/ xl (/ (length coordenadas) xyz)))
  (setq y (/ yl (/ (length coordenadas) xyz)))
  (setq coor (list x y 0))
  (command "_.circle" coor 5)
  (setvar "cmdecho" 1)
  (prin1)
) ;_defun

In the example I made him to draw an circle, but you can see the coordinates in the line of commands of AutoCAD with the following thing: !coor

I hope it serves him, Any modification warns me...

Un saludo de SpeedCAD... :)
CHILE
 
Hi binary,

snap the center between two points:
Build a button
_non;'cal;(cur+cur)/2;

Lothar

Win NT4.0(SP6),2000(SP3)
AC 2000i(SP2), ADT 3.0(SP3),
AC 2002, ADT 3.3,
AC 2004, ADT 2004
 
Hola SpeedCAD.

Thank you very much for the code; it sounds like it's just the thing I'm looking for.

I have a problem when I run it, though. I get the message "error: no function definition: VLAX-ENAME->VLA-OBJECT"

All I did was cut and paste into a .lsp file which I placed in my \support directory. I executed the program from the command line.

If it matters, I'm using ACAD 2k2 on XP

Saludos,

Binary

 
Lothar & CADaver, thanks, too. Those are both nice routines, too.
 
Hi Binary...

Ok, I lacked to put vl-load-com

(defun c:centroide ()
(vl-load-com)
(setvar "cmdecho" 0)
(while (not (setq lwpol (car (entsel "\nSeleccione polilinea: "))))
)
(while (/= "LWPOLYLINE" (cdr (assoc 0 (entget lwpol))))
(prompt
"\n*** La entidad seleccionada no es una LWPOLYLINE ***"
)
(while (not (setq lwpol (car (entsel "\nSeleccione polilinea: "))))
)
)
(setq lwpol-vl (vlax-ename->vla-object lwpol))
(setq coordenadas (vlax-get lwpol-vl "coordinates"))
(setq xl 0)
(setq yl 0)
(setq zl 0)
(setq xyz 2)
(setq ind 0)
(repeat (length coordenadas)
(cond
((= (rem ind xyz) 0)
(setq xl (+ xl (nth ind coordenadas)))
)
((= (rem ind xyz) 1)
(setq yl (+ yl (nth ind coordenadas)))
)
((= (rem ind xyz) 2)
(setq zl (+ zl (nth ind coordenadas)))
)
)
(setq ind (1+ ind))
)
(setq x (/ xl (/ (length coordenadas) xyz)))
(setq y (/ yl (/ (length coordenadas) xyz)))
(setq coor (list x y 0))
(command "_.circle" coor 5)
(setvar "cmdecho" 1)
(prin1)
) ;_defun

Now you should not have problems...

Un saludo de SpeedCAD... :)
CHILE
 
SpeedCAD...

¡Qué Bueno! Es utilidad muy útil. Mil gracias por compartidolo. ¡¡Ud. es el hombre!! (No se si lo conoce pero la frase "you the man" es un elogio fuerte en los estados unidos).

Tengo una pregunta...

¿Es posible hacer el círculo escalado proporcional al polígono?

La cosa mejor para mí sería recibir una [hint] porque estoy tratando de aprender programar [lisp].

Una vez más, mil gracias.
 
Hello...

I see that you speak Spanish. Then you speak to me Spanish and Me English, and we understand better :D

What proportion do you want to give to the circle?. The proportion you can calculate by means of the variable of system viewsize, give me more information to help him.

What is a HINT?

Un saludo de SpeedCAD... :)
CHILE
 
I know your original question is already solved, but similar to Exit's button macro that uses the geometry calculator:

'cal;mee;

(Which is middle of endpoint to endpoint)

Flores

 
Hola SpeedCAD.

La verdad es que no hablo espanol con mucho fuerte...simplenente suficiente para que pueda decir mucho que quiero decir, por lo menos bastante para hacerme entendido.

However, it is much easier for me to write in English than Spanish (aunque practicar es bueno) and it's probably better in English most people who might be interested in this thread probably speak English.

What I'd like to do is scale the circle so that its diameter is 10% of the diameter around which the polygon would be circumscribed - so that the circle can be snapped to in the future but so that it is relatively unnoticed.

ps - Una "hint" es palabra o frase que ayuda una persona encontrar la respuesta sin simplemente dandolo la respuesta. Mi diccionario traduzca "hint" como "pista" o "indirecta" pero no conozco estos palabras.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor