Jump to content

Get Mass Properties of a region and update exisitng text box


atr140

Recommended Posts

  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

  • Tharwat

    26

  • Manila Wolf

    21

  • arkizner

    11

  • atr140

    8

Top Posters In This Topic

Posted Images

Hi Tharwat,

 

Nearly there I believe. I tested again and there seems that just one minor correction to the code is needed.

Please see the attached drawing.

 

It concerns the display only of the biggest bounding box values. It appears that the first value in the string rather than the largest value is displaying.

I say the problem is with the display only because the program does appear to select the correct biggest value when calculating the section modulus values.

 

Just thinking out loud, if the whole bounding box string i.e the maximum and minimum values complete with all the hyphens is displayed in the attribute then that is fine.

Is that easier for coding?

It would be fine for me because the section modulus values that use the biggest value are coming out correct.

 

The above for your information.

 

Cheers and Thanks.

MassPropsTest-RevA.dwg

Link to comment
Share on other sites

You totally nailed it Tharwat. :)

 

A marvellous program. Sincere thanks.

 

I will use it extensively.

 

Cheers. :beer:

 

Waw .. Excellent , Happy to hear that and you are most welcome :)

 

I also learned a lot from writing this program programmatically and technically .

 

Good luck .

Link to comment
Share on other sites

  • 2 years later...
_l (mapcar '(lambda (j k) (cons j k))

'("AREA" "PERIMETER" "BOUNDING_BOX_X_MAX"

"BOUNDING_BOX_Y_MAX" "CENTROID_X"

"CENTROID_Y" "MOMENT_OF_INERTIA_X"

"MOMENT_OF_INERTIA_Y" "SECTION_MODULUS_ZX"

"SECTION_MODULUS_ZY"

"RADIUS_OF_GYRATION_X"

"RADIUS_OF_GYRATION_Y" "WEIGHT"

)

srt

may be u should preset the multiplication factor for displayed results:

(setq modKoef 0.001) some were here?

Link to comment
Share on other sites

In a simple way.........

Assuming your profile is drawn using cm in lieu of mm, then you can arrive at the correct kg/m for aluminium extrusions by changing this line:-

 

(rtos (* (read ar) 0.00271) 2 3)

 

To

 

(rtos (* (read ar) 0.271) 2 3)

 

All the other mass property values are generated based on the size of the drawn profile.

So if you have drawn the profile in cm units and with the centroid at position 0,0, then then all the resultant values should be correct.

Link to comment
Share on other sites

the problem is that i need all the parameters leave as is but only the moment of inertia should be calculated in cm4

hence -the mass 0.00271 is fine.

please guide me where to ad the 0.0001?

Link to comment
Share on other sites

the problem is that i need all the parameters leave as is but only the moment of inertia should be calculated in cm4

hence -the mass 0.00271 is fine.

please guide me where to ad the 0.0001?

 

Ah! sorry, I misunderstood. so your profile is drawn in mm units.

Apologies. The coding required is beyond my capabilities.

Hopefully Tharwat will read this and may be able to help.

Link to comment
Share on other sites

the problem is that i need all the parameters leave as is but only the moment of inertia should be calculated in cm4

hence -the mass 0.00271 is fine.

please guide me where to ad the 0.0001?

 

Hi,

 

The Moments of inertia are as follows in my previous posted program:

X = (car p)
Y = (cadr p)

So just multiply the value with any factor that you would like to change to:

eg:

(* (car p) 0.0001)

 

Hope this clear enough to you.

Link to comment
Share on other sites

i understand that the line should be modified in this region:

""""""0.0000"

"0.0000"

(car _l2)

(cadr _l2)

(rtos (/ (read (car _l2))

(max (read (caadr _l1))

(read (cadadr _l1))

)

)

2

3

)

(rtos (/ (read (cadr _l2))

(max (read (caar _l1))

(read (cadar _l1))

)

)

2

3

)

(caddr _l2)

(nth 3 _l2)

(rtos (* (read ar) 0.00271) 2 3)

 

"""

 

please guide me -in what line i should to interrupt?

Link to comment
Share on other sites

  "0.0000"
                     "0.0000"
                     (car _l2)
                     (cadr _l2)
                     (rtos (/ (read (car _l2))
                              (max (read (caadr _l1))
                                   (read (cadadr _l1))
                              )
                           )
                           2
                           3
                     )
                     (rtos (/ (read (cadr _l2))
                              (max (read (caar _l1))
                                   (read (cadar _l1))
                              )
                           )
                           2
                           3
                     )
                     (caddr _l2)
                     (nth 3 _l2)
                     (rtos (* (read ar) 0.00271) 2 3)

 

so this is the part of the code - where i should put the 0.0001?

Link to comment
Share on other sites

please Help me to understand this issue.

 

i need to modernize this lisp.

 

1. I need show moment of inertia I[xx];[yy] but in CM4;

2. I also i need add some parametr:

Wx=Ixx*10/a1 (a1- promt to pic dimention value);

Wy=Iyy*10/b1 (b1- promt to pic other dimention value);

 

please See below the code copied from this topic (Big thanks for Tharwat):

(defun c:WriteMass (/ *error* _get _doc cho f cl o b l _l _l1 _l2 ar srt fnd)
;;; -------------------------------------------------    ;;;
;;;    ---=== { Author : Tharwat Al Shoufi } ===---      ;;;
;;;                                                      ;;;
;;;     Write mass properties to Attributed Block(s)     ;;;
;;; -------------------------------------------------    ;;;
 (setq _doc (vla-get-activedocument (vlax-get-acad-object)))
 (defun *error* (x)
   (if (and f (setq f (findfile f)))
     (vl-file-delete f)
   )
   (if cho
     (setvar 'cmdecho cho)
   )
   (if (and x
            (not (wcmatch (strcase x) "*BREAK*,*EXIT*,*CANCEL*"))
       )
     (princ "Error:" x "...")
   )
 )
;;;                                ;;;
 (defun _get (f / of s lst l)
   (if (and (setq of (open f "r"))
            (while
              (setq s (read-line of))
               (setq lst (cons s lst))
            )
       )
     (progn
       (close of)
       (if (setq lst (reverse lst))
         (mapcar '(lambda (i) (setq l (cons (nth i lst) l)))
                 '(3 4 5 6 9 10 12 13)
         )
       )
       (setq l (reverse l))
     )
   )
   l
 )
;;;                                ;;;
 (cond
   ((or (minusp (cdr (assoc 62
                            (setq cl
                                   (entget
                                     (tblobjname "LAYER" (getvar 'CLAYER))
                                   )
                            )
                     )
                )
        )
        (= 4 (logand 4 (cdr (assoc 70 cl))))
    )
    (alert "<!> Current Layer is either OFF or LOCKED <!>")
   )
   ((and
      (princ
        "\n Select CLOSED Object [REGION,CIRCLE,ELLIPSE,LWpolyline] :"
      )
      (not (setq o (ssget "_+.:S:E:L"
                          '((-4 . "<OR")
                            (0 . "REGION,CIRCLE,ELLIPSE")
                            (-4 . "<AND")
                            (0 . "LWPOLYLINE")
                            (-4 . "&=")
                            (70 . 1)
                            (-4 . "AND>")
                            (-4 . "OR>")
                           )
                   )
           )
      )
    )
    (alert
      "\n << nil or Invalid Object or on Locked Layer !! >>"
    )
   )
   ((and (princ "\n Select Attributed Block(s) :")
         (not (setq b (ssget "_:L" '((0 . "INSERT") (66 . 1)))))
    )
    (alert "Invalid object . Should be Attributed Block(s) !")
   )
 )
 (if (and b
          (if (not (setq f (vl-filename-mktemp nil nil ".mpr")))
            (alert "Can't create the text file !!")
            t
          )
     )
   (progn
     (if (eq (cdr (assoc 0 (entget (ssname o 0)))) "REGION")
       (setq r (list (vlax-ename->vla-object (ssname o 0))))
       (setq r (vl-catch-all-apply
                 'vlax-invoke
                 (list
                   (vla-get-block
                     (vla-get-activelayout
                       (vla-get-ActiveDocument
                         (vlax-get-acad-object)
                       )
                     )
                   )
                   'Addregion
                   (list (vlax-ename->vla-object (ssname o 0)))
                 )
               )
             d t
       )
     )
     (setq cho (getvar 'cmdecho))
     (setvar 'cmdecho 0)
     (command "_.ucs"
              "_Origin"
              (setq p (vlax-get (car r) 'Centroid))
     )
     (command "_.massprop"
              (vlax-vla-object->ename (car r))
              ""
              "y"
              (vl-string-translate "\\" "/" f)
     )
     (command "_.ucs" "w")
     (setvar 'cmdecho cho)
     (if d
       (vla-delete (car r))
     )
     (if (zerop (getvar 'PDMODE))
       (setvar 'PDMODE 34)
     )
     (entmake
       (list '(0 . "POINT")
             (cons 10 p)
       )
     )
     (if (setq l (_get f))
       (progn
         (setq _l1 (mapcar
                     '(lambda (s d / p a b c)
                        (setq p (vl-string-search d s)
                              a (vl-string-trim
                                  " "
                                  (substr s (+ p 3))
                                )
                              p (vl-string-search "--" a)
                              b (substr a 1 p)
                              c (vl-string-trim
                                  " "
                                  (substr a (+ p 3))
                                )
                              b (if (wcmatch b "-*")
                                  (substr b 2)
                                  b
                                )
                              c (if (wcmatch c "-*")
                                  (substr c 2)
                                  c
                                )
                        )
                        (mapcar '(lambda (x) (vl-string-trim " " x))
                                (list b c)
                        )
                      )
                     (list (nth 2 l) (nth 3 l))
                     '("X:" "Y:")
                   )
               _l2 (mapcar '(lambda (s d / p a)
                              (setq p (vl-string-search d s)
                                    a (vl-string-trim
                                        " "
                                        (substr (vl-string-trim
                                                  " "
                                                  (substr s (+ p 3))
                                                )
                                                1
                                                p
                                        )
                                      )
                              )
                              a
                            )
                           (list (nth 4 l)
                                 (nth 5 l)
                                 (nth 6 l)
                                 (nth 7 l)
                           )
                           '("X:" "Y:" "X:" "Y:")
                   )
               ar  (vl-string-trim " " (substr (car l) 6))
               srt (list
                     ar
                     (vl-string-trim " " (substr (cadr l) 12))
                     (rtos (max (read (caar _l1))
                                (read (cadar _l1))
                           )
                           2
                           3
                     )
                     (rtos (max (read (caadr _l1))
                                (read (cadadr _l1))
                           )
                           2
                           3
                     )
                     "0.0000"
                     "0.0000"
                     (car _l2)
                     (cadr _l2)
                     (rtos (/ (read (car _l2))
                              (max (read (caadr _l1))
                                   (read (cadadr _l1))
                              )
                           )
                           2
                           3
                     )
                     (rtos (/ (read (cadr _l2))
                              (max (read (caar _l1))
                                   (read (cadar _l1))
                              )
                           )
                           2
                           3
                     )
                     (caddr _l2)
                     (nth 3 _l2)
                     (rtos (* (read ar) 0.00271) 2 3)
                   )
               _l  (mapcar '(lambda (j k) (cons j k))
                           '("AREA" "PERIMETER" "BOUNDING_BOX_X_MAX"
                             "BOUNDING_BOX_Y_MAX" "CENTROID_X"
                             "CENTROID_Y" "MOMENT_OF_INERTIA_X"
                             "MOMENT_OF_INERTIA_Y" "SECTION_MODULUS_ZX"
                             "SECTION_MODULUS_ZY"
                             "RADIUS_OF_GYRATION_X"
                             "RADIUS_OF_GYRATION_Y" "WEIGHT"
                            )
                           srt
                   )
         )
         (vla-startUndomark _doc)
         ((lambda (n / sn)
            (while (setq sn (ssname b (setq n (1+ n))))
              (mapcar
                '(lambda (x)
                   (if (setq
                         fnd (assoc (vla-get-tagstring x)
                                    _l
                             )
                       )
                     (vla-put-textstring x (cdr fnd))
                   )
                 )
                (vlax-invoke
                  (vlax-ename->vla-object sn)
                  'getattributes
                )
              )
            )
          )
           -1
         )
         (vla-endundomark _doc)
       )
     )
   )
 )
 (terpri)
 (*error* nil)
 (princ "\nThis Program is written by Tharwat Al Shoufi .")
 (princ)
)
(vl-load-com)
(princ
 "\n** Type WriteMass to start.. Author: Tharwat Al Shoufi .*"
)
(princ)

Link to comment
Share on other sites

I think it would help people reading this thread if you were more clear about the units that you require.

 

For example see the attached pic.

A triangle drawn in millimetre units but the listed section properties are based on centimetre units.

Is that what you are looking for?

 

Or something else?

 

Maybe if you use the same size triangle, then list the figures and units that you are hoping to see.

Not sure if I can ultmately help you, but at least it will be more clear to others that may be able to help.

MassPropsReqd.jpg

Link to comment
Share on other sites

thank you Wolf,

 

the calculating is for profile aluminium

 

i use region with islands

 

perimetr out - region (missing)

perimetr total (what is exist in the lisp) is the total out+islands

 

the units are in mm but only the moment of inertia i need in CM

 

please see the pics

 

open?id=1dSQxml3u9EJjasZ4iVzDfzDkQNNrzdrr

 

open?id=1CAE232svePW4KxAdFZECdjINYSxeOGKp

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...