TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: FELIX on March 19, 2024, 02:56:13 PM
-
I think my question doesn't need a program but rather a simple formula.
Having any polygon with a certain area, for example 50mē, you need to have another proportional polygon with a certain area, for example 80mē. It can be with the AutoCAD scale command. What is the formula to obtain the scale factor. Is this possible?
-
https://www.theswamp.org/index.php?topic=56558.msg603460#msg603460
the formula is in the last function
-
With Vovka's help in:
(sqrt (/ a (vk_GetArea lst)))
I managed to do:
(DEFUN C:XSCPOLI() ;by felixjm
(SETQ ENT (CAR (ENTSEL "\nSSelect Polygon: ")))
(SETQ AR1 (VLAX-CURVE-GETAREA ENT))
(SETQ AR2 (GETREAL (STRCAT "\nNew Area value " (RTOS AR1 2 3) " >>>: ")))
(SETQ PTC (FPTC ENT))
(SETQ XSF (/ 1.0 (SQRT (/ AR1 AR2)))) ;with help vovka
(COMMAND "_COPY" ENT "" PTC "@" "")
(COMMAND "_SCALE" ENT "" PTC XSF)
(PRINC)
)
;
(defun FPTC (OBJ / spc rgn pt) ;by ronjonp
(setq spc (vlax-ename->vla-object (cdr (assoc 330 (entget obj)))))
(setq obj (vlax-ename->vla-object obj))
(= 'list (type (setq rgn (vl-catch-all-apply 'vlax-invoke (list spc 'addregion (list obj))))))
(setq pt (vlax-get (setq rgn (car rgn)) 'centroid))
(vl-catch-all-apply 'vla-delete (list rgn))
pt
)
-
Little improvements to your code FELIX...
Next time don't forget to localize used variables...
(defun c:xscpoli
( / vl
-load fptc ent ar1 ar2 ptc xsf
)
)
( t
)
)
)
)
(defun fptc
( obj
/ spc rgn pt
) pt
)
(setq ent
(car (entsel "\nSelect closed polygonal LWPOLYLINE..."))) ent
)
)
(prompt "\nMissed, or picked entity not closed polygonal LWPOLYLINE...") )
)
M.R.
-
Excellent Ribamar. I tested it and it worked perfect.
I was just curious about function (vl-load)
can you comment?
-
(vl-load) is my function for enabling vl, vla, vlax extension functions through (vl-load-com) that is provided inside (vl-load) function, now as parent... It makes global variables assigned vla-objects such as : cad, doc, alo, spc... If they are nil (vl-load) function is called and they are loaded :
When loaded once in session next time they exist, so (or) will read (and cad doc alo spc) as T and not proceed to (vl-load) - it will stop further execution...
So : cad, doc, alo, spc are global variables and (vl-load) function serves for loading them just once in session... User just have to be avare they are loaded as vla-objects and use them where and when ever is needed... Especially cad, doc, and spc globals...
-
With Vovka's help in:
(/ 1.0 (SQRT (/ AR1 AR2))) can be shortened to (SQRT (/ AR2 AR1))