DuanJinHui Posted February 20, 2016 Share Posted February 20, 2016 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]) Thanks Lee, Quote Link to comment Share on other sites More sharing options...
dpenney Posted February 22, 2016 Share Posted February 22, 2016 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]) Perfect. Many thanks for your time. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted February 22, 2016 Share Posted February 22, 2016 You're welcome. Quote Link to comment Share on other sites More sharing options...
AntAle Posted December 17, 2017 Share Posted December 17, 2017 This is great! I've been looking for a lisp to help me generate a table summing the weight of solids sorted by materials/layers using the volume of the items and the layer's description to specify the lb/Lft. Do you think this routine could be modified to do this? Quote Link to comment Share on other sites More sharing options...
maratovich Posted December 17, 2017 Share Posted December 17, 2017 AntAle Attach a sample file, solids and table. I know something that can help you, but you need to check. 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.