naserrishehri@yahoo.com Posted July 29, 2010 Share Posted July 29, 2010 dear friends i need a lisp which can calculate mass of a 3d solid input=density and 3d solid object output= mass Quote Link to comment Share on other sites More sharing options...
MSasu Posted July 29, 2010 Share Posted July 29, 2010 This can get you started: (if (vlax-property-available-p MyVLAEntity "VOLUME") (vlax-get (vlax-ename->vla-object MyVLAEntity) "VOLUME") ) Regards, Quote Link to comment Share on other sites More sharing options...
naserrishehri@yahoo.com Posted July 29, 2010 Author Share Posted July 29, 2010 dear froend please explain more about your code.how can i use it? kind regards Quote Link to comment Share on other sites More sharing options...
MSasu Posted July 29, 2010 Share Posted July 29, 2010 That code will return the volume in current units of a VLA entity - it is intended to be added to your already writhed code. Regards, Quote Link to comment Share on other sites More sharing options...
Small Fish Posted July 30, 2010 Share Posted July 30, 2010 Is this what you wanted? ;by Small Fish (defun c:Solid_Prop(/ OldCmd PDen enaPline vname SolidVol SolidWgt) (vl-load-com);load vla (setq OldCmd (getvar "CMDDIA")) (setvar "CMDECHO" 0) (setq PDen (getreal "\nDensity of object : ") enaPline(car(entsel"\nSelect any edge of solid object : ")) vname (vlax-ename->vla-object enaPline ) SolidVol (/(vla-get-volume vname)1e9);volume SolidWgt (* SolidVol PDen );weight );setq (alert (strcat "Properties for a solid object at " (rtos PDen 2 2)" t/m³ : " "\n" "\nVolume = " (setq VolTxt (rtos SolidVol 2 2)) " m³" "\t\tWeight = " (setq WgtTxt (rtos SolidWgt 2 2)) " t" );strcat );alert (setvar "CMDECHO" OldCmd); (princ) );defun Quote Link to comment Share on other sites More sharing options...
naserrishehri@yahoo.com Posted July 31, 2010 Author Share Posted July 31, 2010 dear friend thanks a lot for your help. kind regards Quote Link to comment Share on other sites More sharing options...
dpenney Posted September 19, 2014 Share Posted September 19, 2014 Is this what you wanted? ;by Small Fish (defun c:Solid_Prop(/ OldCmd PDen enaPline vname SolidVol SolidWgt) (vl-load-com);load vla (setq OldCmd (getvar "CMDDIA")) (setvar "CMDECHO" 0) (setq PDen (getreal "\nDensity of object : ") enaPline(car(entsel"\nSelect any edge of solid object : ")) vname (vlax-ename->vla-object enaPline ) SolidVol (/(vla-get-volume vname)1e9);volume SolidWgt (* SolidVol PDen );weight );setq (alert (strcat "Properties for a solid object at " (rtos PDen 2 2)" t/m³ : " "\n" "\nVolume = " (setq VolTxt (rtos SolidVol 2 2)) " m³" "\t\tWeight = " (setq WgtTxt (rtos SolidWgt 2 2)) " t" );strcat );alert (setvar "CMDECHO" OldCmd); (princ) );defun What would change to give answers of kg/m3 Quote Link to comment Share on other sites More sharing options...
wimal Posted September 19, 2014 Share Posted September 19, 2014 Can we find out the center of gravity also. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted September 19, 2014 Share Posted September 19, 2014 MASSPROP just give it a try its possible to retrive the properties by writing to file then re-reading. Quote Link to comment Share on other sites More sharing options...
wimal Posted September 19, 2014 Share Posted September 19, 2014 Yes MASSPROP write it to the file. But how can absorb that coordinates to lisp Quote Link to comment Share on other sites More sharing options...
xces Posted February 18, 2016 Share Posted February 18, 2016 Is this what you wanted? ;by Small Fish (defun c:Solid_Prop(/ OldCmd PDen enaPline vname SolidVol SolidWgt) (vl-load-com);load vla (setq OldCmd (getvar "CMDDIA")) (setvar "CMDECHO" 0) (setq PDen (getreal "\nDensity of object : ") enaPline(car(entsel"\nSelect any edge of solid object : ")) vname (vlax-ename->vla-object enaPline ) SolidVol (/(vla-get-volume vname)1e9);volume SolidWgt (* SolidVol PDen );weight );setq (alert (strcat "Properties for a solid object at " (rtos PDen 2 2)" t/m³ : " "\n" "\nVolume = " (setq VolTxt (rtos SolidVol 2 2)) " m³" "\t\tWeight = " (setq WgtTxt (rtos SolidWgt 2 2)) " t" );strcat );alert (setvar "CMDECHO" OldCmd); (princ) );defun This is awesome. Could you possibly expand this so that after the program is run for the first time, the density doesn't have to be input every time. Something like the offset comand which remembers the last input. I'm trying to set up a prompt using your code which would give something like this: Select any edge of solid object or [[b][size="4"]D[/size][/b]ensity] <7850.00>: 7850.00 being for example the value that was input the previous time. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 18, 2016 Share Posted February 18, 2016 Try the following instead: ([color=BLUE]defun[/color] c:sp ( [color=BLUE]/[/color] den key obj sel ) ([color=BLUE]setq[/color] key [color=MAROON]"LMac\\solprop-density"[/color]) ([color=BLUE]if[/color] ([color=BLUE]or[/color] ([color=BLUE]setq[/color] den (getdensity key)) ([color=BLUE]setq[/color] den (setdensity key)) ) ([color=BLUE]while[/color] ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]initget[/color] [color=MAROON]"Density Exit"[/color]) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nCurrent density: "[/color] ([color=BLUE]rtos[/color] den 2))) ([color=BLUE]setq[/color] sel ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect edge of solid object [Density/Exit]: "[/color])) ([color=BLUE]cond[/color] ( ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno)) ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color]) ) ( ([color=BLUE]or[/color] ([color=BLUE]null[/color] sel) ([color=BLUE]=[/color] [color=MAROON]"Exit"[/color] sel)) [color=BLUE]nil[/color] ) ( ([color=BLUE]=[/color] [color=MAROON]"Density"[/color] sel) ([color=BLUE]setq[/color] den (setdensity key)) ) ( ([color=BLUE]not[/color] ([color=BLUE]vlax-property-available-p[/color] ([color=BLUE]setq[/color] obj ([color=BLUE]vlax-ename->vla-object[/color] ([color=BLUE]car[/color] sel))) 'volume)) ([color=BLUE]princ[/color] [color=MAROON]"\nSelected object does not have Volume property."[/color]) ) ( ([color=BLUE]alert[/color] ([color=BLUE]strcat[/color] [color=MAROON]"Properties for a solid object at "[/color] ([color=BLUE]rtos[/color] den 2 2) [color=MAROON]" t/m³ : \n\n"[/color] [color=MAROON]"Volume = "[/color] ([color=BLUE]rtos[/color] ([color=BLUE]/[/color] ([color=BLUE]vla-get-volume[/color] obj) 1e9) 2 2) [color=MAROON]" m³\t\t"[/color] [color=MAROON]"Weight = "[/color] ([color=BLUE]rtos[/color] ([color=BLUE]*[/color] den ([color=BLUE]/[/color] ([color=BLUE]vla-get-volume[/color] obj) 1e9)) 2 2) [color=MAROON]" t"[/color] ) ) ) ) ) ) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] getdensity ( key [color=BLUE]/[/color] den ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]setq[/color] den ([color=BLUE]getenv[/color] key)) ([color=BLUE]setq[/color] den ([color=BLUE]distof[/color] den 2)) ([color=BLUE]<[/color] 0 den) ) den ) ) ([color=BLUE]defun[/color] setdensity ( key [color=BLUE]/[/color] def tmp ) ([color=BLUE]initget[/color] 6) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] def (getdensity key) tmp ([color=BLUE]cond[/color] (([color=BLUE]getreal[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nSpecify density"[/color] ([color=BLUE]if[/color] def ([color=BLUE]strcat[/color] [color=MAROON]" <"[/color] ([color=BLUE]rtos[/color] def 2) [color=MAROON]">: "[/color]) [color=MAROON]": "[/color])))) (def)) ) ([color=BLUE]setenv[/color] key ([color=BLUE]rtos[/color] tmp 2)) ) tmp ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Quote Link to comment Share on other sites More sharing options...
dpenney Posted February 19, 2016 Share Posted February 19, 2016 Try the following instead: ([color=BLUE]defun[/color] c:sp ( [color=BLUE]/[/color] den key obj sel ) ([color=BLUE]setq[/color] key [color=MAROON]"LMac\\solprop-density"[/color]) ([color=BLUE]if[/color] ([color=BLUE]or[/color] ([color=BLUE]setq[/color] den (getdensity key)) ([color=BLUE]setq[/color] den (setdensity key)) ) ([color=BLUE]while[/color] ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]initget[/color] [color=MAROON]"Density Exit"[/color]) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nCurrent density: "[/color] ([color=BLUE]rtos[/color] den 2))) ([color=BLUE]setq[/color] sel ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect edge of solid object [Density/Exit]: "[/color])) ([color=BLUE]cond[/color] ( ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno)) ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color]) ) ( ([color=BLUE]or[/color] ([color=BLUE]null[/color] sel) ([color=BLUE]=[/color] [color=MAROON]"Exit"[/color] sel)) [color=BLUE]nil[/color] ) ( ([color=BLUE]=[/color] [color=MAROON]"Density"[/color] sel) ([color=BLUE]setq[/color] den (setdensity key)) ) ( ([color=BLUE]not[/color] ([color=BLUE]vlax-property-available-p[/color] ([color=BLUE]setq[/color] obj ([color=BLUE]vlax-ename->vla-object[/color] ([color=BLUE]car[/color] sel))) 'volume)) ([color=BLUE]princ[/color] [color=MAROON]"\nSelected object does not have Volume property."[/color]) ) ( ([color=BLUE]alert[/color] ([color=BLUE]strcat[/color] [color=MAROON]"Properties for a solid object at "[/color] ([color=BLUE]rtos[/color] den 2 2) [color=MAROON]" t/m³ : \n\n"[/color] [color=MAROON]"Volume = "[/color] ([color=BLUE]rtos[/color] ([color=BLUE]/[/color] ([color=BLUE]vla-get-volume[/color] obj) 1e9) 2 2) [color=MAROON]" m³\t\t"[/color] [color=MAROON]"Weight = "[/color] ([color=BLUE]rtos[/color] ([color=BLUE]*[/color] den ([color=BLUE]/[/color] ([color=BLUE]vla-get-volume[/color] obj) 1e9)) 2 2) [color=MAROON]" t"[/color] ) ) ) ) ) ) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] getdensity ( key [color=BLUE]/[/color] den ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]setq[/color] den ([color=BLUE]getenv[/color] key)) ([color=BLUE]setq[/color] den ([color=BLUE]distof[/color] den 2)) ([color=BLUE]<[/color] 0 den) ) den ) ) ([color=BLUE]defun[/color] setdensity ( key [color=BLUE]/[/color] def tmp ) ([color=BLUE]initget[/color] 6) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] def (getdensity key) tmp ([color=BLUE]cond[/color] (([color=BLUE]getreal[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nSpecify density"[/color] ([color=BLUE]if[/color] def ([color=BLUE]strcat[/color] [color=MAROON]" <"[/color] ([color=BLUE]rtos[/color] def 2) [color=MAROON]">: "[/color]) [color=MAROON]": "[/color])))) (def)) ) ([color=BLUE]setenv[/color] key ([color=BLUE]rtos[/color] tmp 2)) ) tmp ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Hi, As per my original question, what would have to change to have the units as kg/m3 - instead of t/m3? Also, can multiple items be picked or are we just tied to pick individual entities? It would be really great if we could window and select multiple items with the same density in one go - such as a bolt, nut and washer assemblies for example, etc. Cheers. Quote Link to comment Share on other sites More sharing options...
DuanJinHui Posted February 19, 2016 Share Posted February 19, 2016 Hi, As per my original question, what would have to change to have the units as kg/m3 - instead of t/m3? Also, can multiple items be picked or are we just tied to pick individual entities? It would be really great if we could window and select multiple items with the same density in one go - such as a bolt, nut and washer assemblies for example, etc. Cheers. +1 , Hello , Lee, Can modify to Density unit: kg/m³ , Output mass unit :kg ? Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 19, 2016 Share Posted February 19, 2016 As you have done 118 posts you should be able to work out how to adjust the lisp for Kg/m3 Its all in these 3 lines the density is 1000 ? [color=#800000]"Properties for a solid object at "[/color] ([color=blue]rtos[/color] den 2 2) [color=maroon]" t/m³ : \n\n"[/color] [color=maroon]"Volume = "[/color] ([color=blue]rtos[/color] ([color=blue]/[/color] ([color=blue]vla-get-volume[/color] obj) 1e9) 2 2) [color=maroon]" m³\t\t"[/color] [color=maroon]"Weight = "[/color] ([color=blue]rtos[/color] ([color=blue]*[/color] den ([color=blue]/[/color] ([color=blue]vla-get-volume[/color] obj) 1e9)) 2 2) [color=maroon]" t"[/color] Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 19, 2016 Share Posted February 19, 2016 As per my original question, what would have to change to have the units as kg/m3 - instead of t/m3? +1 , Hello , Lee, Can modify to Density unit: kg/m³ , Output mass unit :kg ?Since the user is specifying the density value, simply enter a value in kg/m3 (i.e. 1000x larger) and change the t/m3 text accordingly - the calculation will be identical. Try the following: ([color=BLUE]defun[/color] c:sp ( [color=BLUE]/[/color] den idx key obj sel vol ) ([color=BLUE]setq[/color] key [color=MAROON]"LMac\\solprop-density"[/color]) ([color=BLUE]if[/color] ([color=BLUE]or[/color] ([color=BLUE]setq[/color] den (getdensity key)) ([color=BLUE]setq[/color] den (setdensity key)) ) ([color=BLUE]while[/color] ([color=BLUE]progn[/color] ([color=BLUE]setvar[/color] 'errno 0) ([color=BLUE]initget[/color] [color=MAROON]"Multiple Density Exit"[/color]) ([color=BLUE]princ[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nCurrent density: "[/color] ([color=BLUE]rtos[/color] den 2) [color=MAROON]" kg/m³"[/color])) ([color=BLUE]setq[/color] sel ([color=BLUE]entsel[/color] [color=MAROON]"\nSelect edge of solid object [Multiple/Density/Exit]: "[/color])) ([color=BLUE]cond[/color] ( ([color=BLUE]=[/color] 7 ([color=BLUE]getvar[/color] 'errno)) ([color=BLUE]princ[/color] [color=MAROON]"\nMissed, try again."[/color]) ) ( ([color=BLUE]or[/color] ([color=BLUE]null[/color] sel) ([color=BLUE]=[/color] [color=MAROON]"Exit"[/color] sel)) [color=BLUE]nil[/color] ) ( ([color=BLUE]=[/color] [color=MAROON]"Density"[/color] sel) ([color=BLUE]setq[/color] den (setdensity key)) ) ( ([color=BLUE]=[/color] [color=MAROON]"Multiple"[/color] sel) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] sel ([color=BLUE]ssget[/color] '((0 . [color=MAROON]"3DSOLID"[/color])))) (showdensity den ([color=BLUE]repeat[/color] ([color=BLUE]setq[/color] idx ([color=BLUE]sslength[/color] sel)) ([color=BLUE]setq[/color] vol ([color=BLUE]+[/color] ([color=BLUE]cond[/color] (vol) (0.0)) ([color=BLUE]vla-get-volume[/color] ([color=BLUE]vlax-ename->vla-object[/color] ([color=BLUE]ssname[/color] sel ([color=BLUE]setq[/color] idx ([color=BLUE]1-[/color] idx))))) ) ) ) ) ) ) ( ([color=BLUE]not[/color] ([color=BLUE]vlax-property-available-p[/color] ([color=BLUE]setq[/color] obj ([color=BLUE]vlax-ename->vla-object[/color] ([color=BLUE]car[/color] sel))) 'volume)) ([color=BLUE]princ[/color] [color=MAROON]"\nSelected object does not have Volume property."[/color]) ) ( (showdensity den ([color=BLUE]vla-get-volume[/color] obj))) ) ) ) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] showdensity ( den vol ) ([color=BLUE]setq[/color] vol ([color=BLUE]/[/color] vol 1e9)) ([color=BLUE]alert[/color] ([color=BLUE]strcat[/color] [color=MAROON]"Properties for a solid object at "[/color] ([color=BLUE]rtos[/color] den 2 2) [color=MAROON]" kg/m³ : \n\n"[/color] [color=MAROON]"Volume = "[/color] ([color=BLUE]rtos[/color] vol 2 2) [color=MAROON]" m³\t\t"[/color] [color=MAROON]"Weight = "[/color] ([color=BLUE]rtos[/color] ([color=BLUE]*[/color] den vol) 2 2) [color=MAROON]" kg"[/color] ) ) ) ([color=BLUE]defun[/color] getdensity ( key [color=BLUE]/[/color] den ) ([color=BLUE]if[/color] ([color=BLUE]and[/color] ([color=BLUE]setq[/color] den ([color=BLUE]getenv[/color] key)) ([color=BLUE]setq[/color] den ([color=BLUE]distof[/color] den 2)) ([color=BLUE]<[/color] 0 den) ) den ) ) ([color=BLUE]defun[/color] setdensity ( key [color=BLUE]/[/color] def tmp ) ([color=BLUE]initget[/color] 6) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] def (getdensity key) tmp ([color=BLUE]cond[/color] (([color=BLUE]getreal[/color] ([color=BLUE]strcat[/color] [color=MAROON]"\nSpecify density (kg/m³)"[/color] ([color=BLUE]if[/color] def ([color=BLUE]strcat[/color] [color=MAROON]" <"[/color] ([color=BLUE]rtos[/color] def 2) [color=MAROON]">: "[/color]) [color=MAROON]": "[/color])))) (def)) ) ([color=BLUE]setenv[/color] key ([color=BLUE]rtos[/color] tmp 2)) ) tmp ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Quote Link to comment Share on other sites More sharing options...
xces Posted February 19, 2016 Share Posted February 19, 2016 this is great.. however I was trying to eliminate the message box displaying the results by changing it with print function to display the results in the command line which is more convenient for me but the new function won't break after it does the calculation so it displays the results but still keeps asking me to select new solid(s). On another note, the meter cubed is not recognized by Acad so i changed it to Unicode \U+00B3 . here is a copy so you can test it directly. Thank you in advance. (defun c:dmass ( / den idx key obj sel vol ) (setq key "LMac\\solprop-density") (if (or (setq den (getdensity key)) (setq den (setdensity key)) ) (while (progn (setvar 'errno 0) (initget "Multiple Density Exit") (princ (strcat "\nCurrent density: " (rtos den 2) " kg/m\U+00B3")) (setq sel (entsel "\nSelect edge of solid object [Multiple/Density/Exit]: ")) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (or (null sel) (= "Exit" sel)) nil ) ( (= "Density" sel) (setq den (setdensity key)) ) ( (= "Multiple" sel) (if (setq sel (ssget '((0 . "3DSOLID")))) (showdensity den (repeat (setq idx (sslength sel)) (setq vol (+ (cond (vol) (0.0)) (vla-get-volume (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))) ) ) ) ) ) ) ( (not (vlax-property-available-p (setq obj (vlax-ename->vla-object (car sel))) 'volume)) (princ "\nSelected object does not have Volume property.") ) ( (showdensity den (vla-get-volume obj))) ) ) ) ) (princ) ) (defun showdensity ( den vol ) (setq vol (/ vol 1e9)) (print (strcat "Properties for a solid object at " (rtos den 2 2) " kg/m\U+00B3 :" "Volume = " (rtos vol 2 2) " m\U+00B3" "Weight = " (rtos (* den vol) 2 2) " kg" ) ) ) (defun getdensity ( key / den ) (if (and (setq den (getenv key)) (setq den (distof den 2)) (< 0 den) ) den ) ) (defun setdensity ( key / def tmp ) (initget 6) (if (setq def (getdensity key) tmp (cond ((getreal (strcat "\nSpecify density (kg/m\U+00B3)" (if def (strcat " <" (rtos def 2) ">: ") ": ")))) (def)) ) (setenv key (rtos tmp 2)) ) tmp ) (vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 19, 2016 Share Posted February 19, 2016 Change print to prompt and add \n before Properties, Volume & Weight. Quote Link to comment Share on other sites More sharing options...
xces Posted February 19, 2016 Share Posted February 19, 2016 works like a charm.. thank you Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 20, 2016 Share Posted February 20, 2016 You're welcome. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.