Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

draw a composite c.g. point and report massprop

Status
Not open for further replies.

Andylaug

Industrial
Apr 16, 2002
13
0
0
US
We are upgrading from AutoCAD r14 to 2002 and we have found that some of our lisp routines won't work. here is a lisp that draws a node at the centroid of a solid or region and reports the weight in Carbon steel, Stainless steel, & Aluminum.

Does anyone know what is causing it to fail at the open file command.

;This program draws a point at the centroid of a
;region or solid. The point is drawn on the current
;layer at the current settings. It creates a file
;called deleteme.mpr in c:\temp directory that can
;be deleted if wanted, otherwise the program will
;just overwrite it everytime it runs.

(defun c:CG2002 (/ ss mprfile title c-steel s-steel alumn UHMW)

(setq c-steel 0.2833
s-steel 0.286
alum 0.098
UHMW 0.0347)
(setvar "filedia" 0)
(setvar "cmdecho" 0)
(print "Select solids or regions")
(setq ss (ssget))
(command "massprop" ss "" "y" "c:/temp/deleteme")
(setvar "filedia" 1)

(setq mprfile (open "c:/temp/deleteme.mpr" "r"))
(read-line mprfile)
(setq title (read-line mprfile))
(close mprfile)
(if (= nil (wcmatch title "*REGION*")) (CG-SOLID) (CG-REGION))
)
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

(defun CG-REGION (/ mprfile area-line x-line y-line x-coord
area-size y-coord point-coord old-osnap
weight-cs weight-ss weight-al weights)

(setq mprfile (open "c:/temp/deleteme.mpr" "r"))
(repeat 3 (read-line mprfile))
(setq area-line (read-line mprfile))
(repeat 3 (read-line mprfile))
(setq x-line (read-line mprfile))
(setq y-line (read-line mprfile))
(close mprfile)

(setq area-size (atof(substr area-line 25))
weight-cs (* area-size c-steel)
weight-ss (* area-size s-steel)
weight-al (* area-size alum)
weight-UHMW (* area-size UHMW)
x-coord (atof(substr x-line 25))
y-coord (atof(substr y-line 25))
point-coord (list x-coord y-coord)
old-osnap (getvar "osmode")
)

(setvar "osmode" 0)
(command "point" point-coord)
(setvar "osmode" old-osnap)
(setq weights (strcat "Weights at 1 inch thick: " (rtos weight-cs 2 1) "# cs, "
(rtos weight-ss 2 1) "# ss, " (rtos weight-al 2 1) "# al"), " (rtos weight-UHMW 2 1) "# UHMW"))
(alert weights)
(print weights)
(princ)
)
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

(defun CG-SOLID (/ mprfile vol-line x-line y-line z-line x-coord
y-coord z-coord vol-size point-coord old-osnap
weight-cs weight-ss weight-al weights)

(setq mprfile (open "c:/temp/deleteme.mpr" "r"))
(repeat 4 (read-line mprfile))
(setq vol-line (read-line mprfile))
(repeat 3 (read-line mprfile))
(setq x-line (read-line mprfile))
(setq y-line (read-line mprfile))
(setq z-line (read-line mprfile))
(close mprfile)

(setq vol-size (atof(substr vol-line 25))
weight-cs (* vol-size c-steel)
weight-ss (* vol-size s-steel)
weight-al (* vol-size alum)
weight-UHMW (* vol-size UHMW)
x-coord (atof(substr x-line 25))
y-coord (atof(substr y-line 25))
z-coord (atof(substr z-line 25))
point-coord (list x-coord y-coord z-coord)
old-osnap (getvar "osmode")
)

(setvar "osmode" 0)
(command "point" point-coord)
(setvar "osmode" old-osnap)
(setq weights (strcat "Weights: " (rtos weight-cs 2 1) "# cs, " (rtos weight-ss 2 1)
"# ss, " (rtos weight-al 2 1) "# al"), " (rtos weight-UHMW 2 1) "# UHMW"))
(alert weights)
(print weights)
(princ)
 
Replies continue below

Recommended for you

we have solved the problem and I've included the correct code for everyone. However, since we use an alert box instead of a dialog box, we are limited to 4 outputs. Any revision to this code to use a dialog box is greatly appreciated.

(defun c:CG (/ ss mprfile title c-steel s-steel alumn UHMW )

(setq c-steel 0.2833
s-steel 0.286
alum 0.098
UHMW 0.0347
(setvar "filedia" 0)
(setvar "cmdecho" 0)
(print "Select solids or regions")
(setq ss (ssget))
(command "massprop" ss "" "y" "c:/temp/deleteme")
(setvar "filedia" 1)

(setq mprfile (open "c:/temp/deleteme.mpr" "r"))
(read-line mprfile)
(setq title (read-line mprfile))
(close mprfile)
(if (= nil (wcmatch title "*REGION*")) (CG-SOLID) (CG-REGION))
)
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

(defun CG-REGION (/ mprfile area-line x-line y-line x-coord
area-size y-coord point-coord old-osnap
weight-cs weight-ss weight-al weights)

(setq mprfile (open "c:/temp/deleteme.mpr" "r"))
(repeat 3 (read-line mprfile))
(setq area-line (read-line mprfile))
(repeat 3 (read-line mprfile))
(setq x-line (read-line mprfile))
(setq y-line (read-line mprfile))
(close mprfile)

(setq area-size (atof(substr area-line 25))
weight-cs (* area-size c-steel)
weight-ss (* area-size s-steel)
weight-al (* area-size alum)
weight-UHMW (* area-size UHMW)
x-coord (atof(substr x-line 25))
y-coord (atof(substr y-line 25))
point-coord (list x-coord y-coord)
old-osnap (getvar "osmode")
)

(setvar "osmode" 0)
(command "point" point-coord)
(setvar "osmode" old-osnap)
(setq weights (strcat "Weights at 1 inch thick: " (rtos weight-cs 2 1) "# cs, "
(rtos weight-ss 2 1) "# ss, " (rtos weight-al 2 1) "# al " (rtos weight-UHMW 2 1) "# UHMW "))
(alert weights)
(print weights)
(princ)
)
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

(defun CG-SOLID (/ mprfile vol-line x-line y-line z-line x-coord
y-coord z-coord vol-size point-coord old-osnap
weight-cs weight-ss weight-al weights)

(setq mprfile (open "c:/temp/deleteme.mpr" "r"))
(repeat 4 (read-line mprfile))
(setq vol-line (read-line mprfile))
(repeat 3 (read-line mprfile))
(setq x-line (read-line mprfile))
(setq y-line (read-line mprfile))
(setq z-line (read-line mprfile))
(close mprfile)

(setq vol-size (atof(substr vol-line 25))
weight-cs (* vol-size c-steel)
weight-ss (* vol-size s-steel)
weight-al (* vol-size alum)
weight-UHMW (* vol-size UHMW)
x-coord (atof(substr x-line 25))
y-coord (atof(substr y-line 25))
z-coord (atof(substr z-line 25))
point-coord (list x-coord y-coord z-coord)
old-osnap (getvar "osmode")
)

(setvar "osmode" 0)
(command "point" point-coord)
(setvar "osmode" old-osnap)
(setq weights (strcat "Weights: " (rtos weight-cs 2 1) "# cs, " (rtos weight-ss 2 1)
"# ss, " (rtos weight-al 2 1) "# al " (rtos weight-UHMW 2 1) "# UHMW "))
(alert weights)
(print weights)
(princ)
 
Status
Not open for further replies.
Back
Top