Bill Tillman Posted December 21, 2011 Posted December 21, 2011 I did several searches both here and on the web but was not able to find a solution for this. I'm still a newbie at this autolisp routine. Basically, what I want to do is create a lisp routine which will allow me to run MASSPROP and have it dump the results to a file. When I read the .mpr file I see this format and the data I want to store in variables so I can print a small table of values next to the object are highlighted in red: ---------------- REGIONS ---------------- [color=red]Area: 2.7587[/color] [color=red]Perimeter: 45.3718[/color] Bounding box: X: 14.9715 -- 17.4715 Y: 7.6293 -- 15.6293 [color=red]Centroid: X: 16.2215 [/color] [color=red] Y: 11.6468 [/color] Moments of inertia: X: 394.2578 Y: 729.1778 Product of inertia: XY: 521.2024 [color=red]Radii of gyration: X: 11.9546 [/color] [color=red] Y: 16.2578[/color] Principal moments and X-Y directions about centroid: I: 20.0418 along [1.0000 0.0000] J: 3.2549 along [0.0000 1.0000] That will get me started and I'm hoping to take the customization from there. Quote
ReMark Posted December 21, 2011 Posted December 21, 2011 So you don't want all the information contained in the .mpr file just a subsection. What if the object is not a region but a solid? Quote
Lee Mac Posted December 21, 2011 Posted December 21, 2011 Bill, That data can be accessed from the respective Visual LISP ActiveX Properties of the Region Object (use vlax-dump-object to see which properties are available; coupled with the Visual LISP IDE (VLIDE) Help Documentation for information about each property); I would also recommend you use the undocumented vlax-get function over vlax-get-property / vla-* to avoid the necessity of converting the Variants/SafeArrays to native AutoLISP data types (such as Lists). Example: (defun c:test ( / e o f d l ) (if (and (setq e (car (entsel))) (setq o (vlax-ename->vla-object e)) (eq "AcDbRegion" (vla-get-objectname o)) (setq f (vl-filename-mktemp nil (getvar 'dwgprefix) ".txt")) (setq d (open f "w")) ) (progn (princ (strcat "Area: " (rtos (vlax-get o 'area)) "\nPerimeter: " (rtos (vlax-get o 'perimeter)) "\nCentroid: " (progn (setq l (mapcar 'rtos (vlax-get o 'centroid))) (strcat (car l) "," (cadr l)) ) "\nRadii of Gyration: " (progn (setq l (mapcar 'rtos (vlax-get o 'radiiofgyration))) (strcat (car l) "," (cadr l)) ) ) d ) (close d) (startapp "notepad" f) ) ) (princ) ) (vl-load-com) (princ) Quote
Bill Tillman Posted December 21, 2011 Author Posted December 21, 2011 (edited) Lee Mac, you are indeed a master of this code and make it look so easy. I can only hope that I have at least 1/2 of your skills with this. This is just an exercise which I decided to start to teach myself some finer points working with VLISP. I work mainly in the window and door business and we often use and/or design custom aluminum extrusions. The need often arises to have the section properties of these shapes and to present them in a nice format. Years ago, pre Release 14, a PE friend of mine had written a simple LISP routine which would quickly prepare a table like the one I have in the attached file. This is mainly the entire contents of the mpr file which gets created when the MASSPROP command is run on the object. The Wt/Ft entry is a calculation of the Area * 1.18. All the other lines are just the same data as the mpr file. The borders were a nice touch. And oh yes, it would draw an elevation symbol at the Center of Gravity point. If I remember, the old LISP file would prompt for Steel or Aluminum and would make the weight per foot calculation based on that. I know his code was very simple and I wish I had saved a copy of it. The only copy I remember having was on a 5-1/4" floppy disk which was trashed long ago. UPDATE: I got the Wt/Ft part figured out and have that writing into the file, although I need to find a way to format the number to have only two decimal places. "Area: " (rtos (vlax-get o 'area)) " Wt/Ft = " (rtos (* (vlax-get o 'area) 1.18)) I think I can work this out...and will practice more at it tomorrow. Section Properties.dwg Edited December 22, 2011 by Bill Tillman Quote
BIGAL Posted December 22, 2011 Posted December 22, 2011 To qoute Lisp manual (rtos number [mode [precision]]) use 2 for mode & precision Also more the values of LUNITS & LUPREC are used if you omit the arguments as per your code above Hope this helps Quote
Bill Tillman Posted December 22, 2011 Author Posted December 22, 2011 (edited) To qoute Lisp manual (rtos number [mode [precision]]) use 2 for mode & precision Also more the values of LUNITS & LUPREC are used if you omit the arguments as per your code above Hope this helps Yes, indeed that did help quite a bit. I had to try a couple of iterations with the parenthesis but eventually came up with (rtos (vlax-get o 'area)) " Wt/Ft = " (rtos (* (vlax-get o 'area) 1.18) 2 2) and it gave me the desired results. Another piece of the puzzle put into place. I'll keep trying till I get this where I want it. My old friend who had this code long ago for Release 10 I think it was passed away many years ago. I think I can get this and then it will once again be mine. This block was added and I now have the Principal Moments. A few more steps to get the thing to assign the important stuff to variables and I think I have it... Maybe! "\nPrincipal Moments: " (progn (setq l (mapcar 'rtos (vlax-get o 'principalmoments))) (strcat (car l) "," (cadr l)) ) Edited December 22, 2011 by Bill Tillman Quote
bkartal16 Posted October 2, 2018 Posted October 2, 2018 hi all, i've revised above lisp routine as i need, centroid(only y), area and moment of inertia. but i have lots of regions and i need to make a list of this values for each objects. can anyone help me with this? (defun c:mpp ( / e o f d l ) (if (and (setq e (car (entsel))) (setq o (vlax-ename->vla-object e)) (eq "AcDbRegion" (vla-get-objectname o)) (setq f (vl-filename-mktemp nil (getvar 'dwgprefix) ".txt")) (setq d (open f "w")) ) (progn (princ (strcat "Centroid: " (progn (setq l (mapcar 'rtos (vlax-get o 'centroid))) (strcat (cadr l)) ) "\nArea: " (rtos (vlax-get o 'area)) "\nMoments of inertia: " (progn (setq l (mapcar 'rtos (vlax-get o 'momentofinertia))) (strcat (cadr l)) ) ) d ) (close d) (startapp "notepad" f) ) ) (princ) ) (vl-load-com) (princ) fr0.5.dwg list.xlsx Quote
BIGAL Posted October 3, 2018 Posted October 3, 2018 A common post here is I want more than 1, so the answer is very simple you need to replace the entsel with a ssget. You pick objects or all etc and use a repeat to look at each object in the selection set, replacing the entsel with (ssname ss itemnum). The reason I have not posted an answer is I have answered it just look through any of the lisp codes here and you will find 100's of examples of using ssget with repeat. Quote
bkartal16 Posted October 3, 2018 Posted October 3, 2018 using ssget instead of entsel cant work for this case, i think. coz the list should be sorted by regions numbers. i have revised the code that i can do, but still i cant get a list :( (defun c:mpp ( / e o f d l y A I) (while (and (setq e (car (entsel))) (setq o (vlax-ename->vla-object e)) (eq "AcDbRegion" (vla-get-objectname o)) (setq f (vl-filename-mktemp nil (getvar 'dwgprefix) ".txt")) (setq d (open f "w")) ) (progn (princ (progn (setq y (mapcar 'rtos (vlax-get o 'centroid))) (setq A (rtos (vlax-get o 'area))) (setq I (mapcar 'rtos (vlax-get o 'momentofinertia))) (write-line (strcat (cadr y) " " A " " (cadr I)) d) ) ; d ) (close d) ) ) (princ) ) (vl-load-com) (princ) Quote
BIGAL Posted October 3, 2018 Posted October 3, 2018 You need a double list (("region x" entity name)("region x+1" entity name)....) then sort list on region number then get properties of the entity via its name. Quote
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.