Bill Tillman Posted December 23, 2011 Posted December 23, 2011 Can someone tell me why this sometimes draws the crosshairs with .125 long lines and sometimes it draws them at .25 long. (command "circle" ip ".125" "") (command "line" ip "@.25<90" "") (command "line" ip "@.25<270" "") (command "line" ip "@.25<0" "") (command "line" ip "@.25<180" "") This happened when I first tried it then I had to adjust the first line of the code and it seemed to work well. But now it's drawing the lines at .125 instead of .25. Quote
Lee Mac Posted December 23, 2011 Posted December 23, 2011 See my revisions to your code: (command "_.circle" "_non" ip "0.125") (command "_.line" "_non" ip "@0.25<90" "") (command "_.line" "_non" ip "@0.25<270" "") (command "_.line" "_non" ip "@0.25<0" "") (command "_.line" "_non" ip "@0.25<180" "") Ask if you have questions about my modifications. Quote
Bill Tillman Posted December 23, 2011 Author Posted December 23, 2011 (edited) Lee, Thanks very much. I hate to be so naive about such things but I'm really making an effort to create a certain LISP routine and rather than just plagerize others codes (I may have to resort to that) I am trying to build this one item at a time. So far I have a good understanding of the MASSPROP extraction you showed me. Notice I said "good" not complete. But I really seem to have hit a road block with this simple task of drawing a elevation symbol at the Center of Gravity for these extrusions. I copied and pasted your code in but it's still giving me lines of only .125 in lieu of .25 which is what I'm after. That said, I am using the VLISP editor environment to do this and after I make the corrections I simply click on the "Load Active Edit Window" which I assume is taking into account the changes that I make to the code. Whatever the case, when I run this I still get lines of the incorrect length. Any advice would be appreciated. UPDATE: And now it's working....after I did and it's working now. Again, sorry to be so naive on this but it's steeper learning curve than I imagined. NEW UPDATE: Dirty OSNAP....was grabbing the quadrant apparently. Rat's it's alwasy something simple. And that's why .5 would get the job done and .25 was just too close to the quadrant point of the circle. Edited December 23, 2011 by Bill Tillman Quote
Lee Mac Posted December 23, 2011 Posted December 23, 2011 Sorry Bill, I missed a second "_non", the code should be: (command "_.circle" "_non" ip "0.125") (command "_.line" "_non" ip "_non" "@0.25<90" "") (command "_.line" "_non" ip "_non" "@0.25<270" "") (command "_.line" "_non" ip "_non" "@0.25<0" "") (command "_.line" "_non" ip "_non" "@0.25<180" "") Thanks very much. I hate to be so naive about such things but I'm really making an effort to create a certain LISP routine and rather than just plagerize others codes (I may have to resort to that) I am trying to build this one item at a time. So far I have a good understanding of the MASSPROP extraction you showed me. Notice I said "good" not complete. But I really seem to have hit a road block with this simple task of drawing a elevation symbol at the Center of Gravity for these extrusions. I really admire your decision to learn to write the code from scratch rather than merely copy/paste from other's routines without a proper understanding, like so many others do on here. As always, if you have any questions about anything I have posted, please don't hesitate to ask - there is no such thing as a stupid question. Quote
Bill Tillman Posted December 24, 2011 Author Posted December 24, 2011 As sloppy as this may be I almost have it where it will be. The text is not an easy thing to do. I have about 50 LISP programs in my collection and it wasn't until I started looking for some text examples that I realized I don't have any. I guess it makes sense that LISP is not really the correct tool for entering text. But this routine is an exception to that rule. Here is what I have so far. You will need a shape like an extrusion of some kind to run this on. I don't think I have the weight thing right just yet and I'm still seeing about a 2% discrpency between the Ix figures I get and the published ones for steel shapes in the AISC manual. (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)) " Wt/Ft = " (rtos (* (vlax-get o 'area) 1.18) 2 2) "\nPerimeter: " (rtos (vlax-get o 'perimeter)) "\nCentroid: " (progn (setq l (mapcar 'rtos (vlax-get o 'centroid))) (strcat (car l) "," (cadr l)) (setq ip (strcat (car l) "," (cadr l))) ) "\nRadii of Gyration: " (progn (setq l (mapcar 'rtos (vlax-get o 'radiiofgyration))) (strcat (car l) "," (cadr l)) ) "\nPrincipal Moments: " (progn (setq l (mapcar 'rtos (vlax-get o 'principalmoments))) (strcat (car l) "," (cadr l)) ) ) ; d ) ;(close d) (setq l1 (strcat "Area: " (rtos (vlax-get o 'area) 2 4) " Sq In")) (setq l2 (strcat "Wt/Ft: " (rtos (* (vlax-get o 'area) 1.18) 2 2) " lbs")) (setq l3 (strcat "Perimeter: " (rtos (vlax-get o 'perimeter) 2 2) " In")) (setq l4 (strcat "Ix: " (cadr l))) (setq l5 (strcat "Iy: " (car l))) (princ l) ; Draw the Center of Gravity Point (command "_.circle" "_non" ip "0.125" "") (command "_.line" "_non" ip "@0.25<90" "") (command "_.line" "_non" ip "@0.25<270" "") (command "_.line" "_non" ip "@0.25<0" "") (command "_.line" "_non" ip "@0.25<180" "") ; Get Insertion Point for Summary Table (setq ip (getpoint "\nSelect Insertion Point for Table : ")) (setq p1 (polar ip (dtr 0.0) 5)) (setq p2 (polar p1 (dtr 270.0) 4)) (setq p3 (polar p2 (dtr 180.0) 5)) (command "line" ip p1 p2 p3 "c") ;(command "Text" ip "0.25" "0.00" l1) (setq p1 (polar ip (dtr 315.0) 0.5)) (command "_.mtext" p1 p2 l1 "") (setq p3 (polar p1 (dtr 270.0) 0.5)) (command "_.mtext" p3 p2 l2 "") (setq p4 (polar p3 (dtr 270.0) 0.5)) (command "_.mtext" p4 p2 l3 "") (setq p5 (polar p4 (dtr 270.0) 0.5)) (command "_.mtext" p5 p2 l4 "") (setq p6 (polar p5 (dtr 270.0) 0.5)) (command "_.mtext" p6 p2 l5 "") ;(startapp "notepad" f) ) ) ;Convert Degrees to Radians (princ) ) (defun dtr (x) (* pi (/ x 180.0)) ) (vl-load-com) (princ) Quote
fixo Posted December 24, 2011 Posted December 24, 2011 Just on the quick glance any command do not require double quotes at the end of expression, e.g: (command "_.circle" "_non" ip "0.125" );<-- double quotes removed And also you may want to use rectangle around the mtext The actual dimensions of mtext that records in entity list: width as dxf 42 code and height as dxf 43 So after creating your mtext you could be able to draw frame calculating 2 points only Just a snip (setq thgt (getvar 'textsize)) (setvar 'textsize 0.27);<-- set to suit your needs (setq strtext (strcat "Area: " (rtos (vlax-get o 'area) 2 4) " Sq In\\P" "Wt/Ft: " (rtos (* (vlax-get o 'area) 1.18) 2 2) " lbs\\P" "Perimeter: " (rtos (vlax-get o 'perimeter) 2 2) " In\\P" "Ix: " (cadr l)"[url="file://p/"]\\P[/url]" "Iy: " (car l))) (setvar 'textsize 0.27) (command "mtext" ip "w" 0 strtext "") (setvar 'textsize thgt);<--restore (setq mtxt (entlast) elist (entget mtxt) width (cdr (assoc 42 elist)) height (cdr (assoc 43 elist))) (setq pt2 (list (+ (car ip) width)(- (cadr ip) height))) (command "_.rectang" "_non" ip "_non" pt2) ~'J'~ Quote
Stefan BMR Posted December 24, 2011 Posted December 24, 2011 Hi Bill About 2% differences, is the shape double symmetric? If it's not (and you can see that next to Principal Moments, if directions are different than [1.00 0.00]) then you need another method to get the correct values. I know two methods: 1) First, run _massprop and collect the centroid coordinates; then set UCS to centroid. Run _massprop once again and compare Moments Of Inertia (and not Principal moments) with AISC manual. 2) Second method required to run _massprop once and no UCS settings: - read area A - read centroid from _massprop - (xg, yg) - read Moments of Inertia - (Ix, Iy) The moments around centroid an parallel to x and y axis: Ixg = Ix - A*yg^2 Iyg = Iy - A*xg^2 Radii of gyration: rxg = sqrt (Ixg / A) ryg = sqrt (Iyg / A) See the picture. First results are around WCS axis and second around Center of gravity. Quote
Bill Tillman Posted December 24, 2011 Author Posted December 24, 2011 Many thanks for these insightful replies. Fixo, I will certainly incoporate that method for mtext using \\ P. I knew there had to be a better way but many searches on the net proved that LISP and text are not that common of a thread. Stephan MBR - I am using another lisp routine called stl.lsp. It's great for steel detailing, although the main reason I'm working on this project is for working with aluminum. I will eventually place a prompt in the code which asks the user whether the shape is steel or aluminum and it will calculate weight/foot and others based on that input. Stl.lsp draws up the profiles quite accurately, at least what I've been able to check. I have to turn the shape into a REGION but then I run MASSPROP and get lots of information which I'm cross-checking against the AISC manual. I'm sure something like SolidWorks does this automatically and with greater accuracy, but I don't have a license for SolidWorks and will not in the forseeable future. 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.