Author Topic: Scale area with reference  (Read 377 times)

0 Members and 1 Guest are viewing this topic.

FELIX

  • Bull Frog
  • Posts: 242
Scale area with reference
« 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?
OK.

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Scale area with reference
« Reply #1 on: March 19, 2024, 03:06:50 PM »

FELIX

  • Bull Frog
  • Posts: 242
Re: Scale area with reference
« Reply #2 on: March 19, 2024, 10:07:46 PM »
With Vovka's help in:
Code: [Select]
(sqrt (/ a (vk_GetArea lst)))
I managed to do:
Code: [Select]
(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
)
OK.

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Scale area with reference
« Reply #3 on: March 20, 2024, 12:04:29 PM »
Little improvements to your code FELIX...
Next time don't forget to localize used variables...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:xscpoli ( / vl-load fptc ent ar1 ar2 ptc xsf )
  2.  
  3.   (defun vl-load nil
  4.     (or cad
  5.       (cond
  6.         ( (not (vl-catch-all-error-p (vl-catch-all-apply (function vlax-get-acad-object) nil)))
  7.           (setq cad (vlax-get-acad-object))
  8.         )
  9.         ( t
  10.           (vl-load-com)
  11.           (setq cad (vlax-get-acad-object))
  12.         )
  13.       )
  14.     )
  15.     (or doc (setq doc (vla-get-activedocument cad)))
  16.     (or alo (setq alo (vla-get-activelayout doc)))
  17.     (or spc (setq spc (vla-get-block alo)))
  18.   )
  19.  
  20.   (defun fptc ( obj / spc rgn pt )
  21.     (setq spc (vlax-ename->vla-object (cdr (assoc 330 (entget obj)))))
  22.     (setq obj (vlax-ename->vla-object obj))
  23.     (= (quote list) (type (setq rgn (vl-catch-all-apply (function vlax-invoke) (list spc (quote addregion) (list obj))))))
  24.     (setq pt (vlax-get (setq rgn (car rgn)) (quote centroid)))
  25.     (vl-catch-all-apply (function vla-delete) (list rgn))
  26.     pt
  27.   )
  28.  
  29.   (or (and cad doc alo spc) (vl-load))
  30.   (setq ent (car (entsel "\nSelect closed polygonal LWPOLYLINE...")))
  31.   (if
  32.     (and
  33.       ent
  34.       (vlax-curve-getendparam ent)
  35.       (vlax-curve-isclosed ent)
  36.       (= (cdr (assoc 0 (setq ex (entget ent)))) "LWPOLYLINE")
  37.       (vl-every (function (lambda ( x ) (= (cdr x) 0.0))) (vl-remove-if (function (lambda ( x ) (/= (car x) 42))) ex))
  38.     )
  39.     (progn
  40.       (setq ar1 (vlax-curve-getarea ent))
  41.       (setq ar2 (getreal (strcat "\nNew area value " (rtos ar1 2 3) " >>> : ")))
  42.       (setq ptc (fptc ent))
  43.       (setq xsf (/ 1.0 (sqrt (/ ar1 ar2))))
  44.       (vla-copy (vlax-ename->vla-object ent))
  45.       (vla-scaleentity (vlax-ename->vla-object (entlast)) (vlax-3d-point ptc) xsf)
  46.     )
  47.     (prompt "\nMissed, or picked entity not closed polygonal LWPOLYLINE...")
  48.   )
  49.   (princ)
  50. )
  51.  

M.R.
« Last Edit: March 22, 2024, 02:55:52 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

FELIX

  • Bull Frog
  • Posts: 242
Re: Scale area with reference
« Reply #4 on: March 20, 2024, 10:53:41 PM »
Excellent Ribamar. I tested it and it worked perfect.
I was just curious about function
Code: [Select]
(vl-load) can you comment?
OK.

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Scale area with reference
« Reply #5 on: March 21, 2024, 03:40:26 AM »
(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 :

Code - Auto/Visual Lisp: [Select]
  1. (or (and cad doc alo spc) (vl-load))
  2.  

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...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Scale area with reference
« Reply #6 on: March 21, 2024, 05:54:32 AM »
With Vovka's help in:
(/ 1.0 (SQRT (/ AR1 AR2))) can be shortened to (SQRT (/ AR2 AR1))