Jump to content

Lisp to find Center of Gravity


asos2000

Recommended Posts

Thanks! But I can't as I don't seem to have any messaging privileges or anything. I think a moderator has asked you to post it to them and they'll upload it. That would be fantastic!

 

Thank you very much :)

Nathan

Link to comment
Share on other sites

  • Replies 28
  • Created
  • Last Reply

Top Posters In This Topic

  • asos2000

    6

  • ASMI

    4

  • nathanjh13

    3

  • krpruett

    3

Top Posters In This Topic

Posted Images

  • 5 months later...

Hi

 

If somebody could resolve this, it would be really helpful :)

 

A lisp for c.o.g of several separate solids is easy but I need one that treats all objects as if they were one (as if they were joined by UNION or GROUP) without me having to run UNION first etc

 

thanks

nathan

Link to comment
Share on other sites

  • 3 years later...
Can anyone make changes to this so that you can calculate CG on multiple regions such as a plate with slots cut in it? See attached please

 

Do you know that command "SUBTRACT" is applicable both to 3D SOLIDS and REGIONS?

 

For centroid - CG, take look into this code :

 

(defun c:centroid ( / v^v unit ucs x y ss ent enta n p )

 (vl-load-com)

 (defun v^v ( u v )
   (mapcar '(lambda ( s1 s2 a b ) (+ ((eval s1) (* (nth a u) (nth b v))) ((eval s2) (* (nth a v) (nth b u))))) '(+ - +) '(- + -) '(1 0 0) '(2 2 1))
 )

 (defun unit ( v )
   (mapcar '(lambda ( x ) (/ x (distance '(0.0 0.0 0.0) v))) v)
 )

 (if (/= (getvar 'worlducs) 1)
   (command "_.ucs" "_w")
 )
 (setq ss (ssget "_+.:E:S" '((0 . "3DSOLID,REGION"))))
 (setq ent (ssname ss 0))
 (setq enta (vlax-ename->vla-object ent))
 (if
   (eq (cdr (assoc 0 (entget ent))) "REGION")
   (progn
     (setq n (vlax-safearray->list (vlax-variant-value (vla-get-normal enta))))
     (if (equal (v^v n '(0.0 0.0 1.0)) '(0.0 0.0 0.0) 1e-6)
       (setq x '(1.0 0.0 0.0) y '(0.0 1.0 0.0))
       (setq x (unit (v^v n '(0.0 0.0 1.0))) y (unit (v^v n x)))
     )
     (command "_.explode" ent)
     (while
       (> (getvar 'cmdactive) 0)
       (command "")
     )
     (setq p (vlax-curve-getstartpoint (entlast)))
     (command "_.undo")
     (while
       (> (getvar 'cmdactive) 0)
       (command "")
     )
     (setq ucs (vla-add (vla-get-usercoordinatesystems (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point p) (vlax-3d-point (mapcar '+ p x)) (vlax-3d-point (mapcar '+ p y)) "{ UCS }"))
     (vla-put-activeucs (vla-get-activedocument (vlax-get-acad-object)) ucs)
     (command "_.UCS" "_D" "{ UCS }")
     (vlax-release-object ucs)
     (setq cent (trans (vlax-safearray->list (vlax-variant-value (vla-get-centroid enta))) 1 0))
     (command "_.ucs" "_p")
   )
   (setq cent (vlax-safearray->list (vlax-variant-value (vla-get-centroid enta))))
 )
 (prompt "\nCentroid : ") (princ cent)
 (prompt "\nVariable is called \"cent\" - you call it with !cent")
 (princ)
)

HTH, M.R.

Edited by marko_ribar
code changed
Link to comment
Share on other sites

The LISP doesn't help in my case. Did you see the example? The lisp above works but I can't select multiple objects and get one CG.

 

You don't read what you see... You must use command "SUBTRACT" prior to using lisp routine... After running "SUBTRACT" command you should select firstly the biggest REGION and then cut-out REGIONS... You will get one subtracted REGION on which you should apply the code posted above...

Link to comment
Share on other sites

I want a LISP where I can create the region(s). Then run the LISP and select all of the regions, then it will draw a circle at the CG of all of them. Because the CG of a part is different if it has large slots or cutouts in it. I have a LISP that will do a singular object from user ASMI but I need one that will accommodate multiple regions without the use of other commands that waste time. I will be doing this on hundreds of parts so secondary and tertiary commands make the LISP pointless.

Link to comment
Share on other sites

  • 2 years later...

Hi all,

 

I am new into your community and i am trying to use the lisps but i am missing something so it is not working into my drawings. The main scope is to give me the center of gravity directly from the polyline.

I am creating the lisp file and insert into the autocad files but it is not working.

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...