lizp Posted May 15, 2009 Author Share Posted May 15, 2009 Now, I'm trying it on the real model, not on the illustration, and I'm having trouble selecting the objects. Is it possible that it's due to the fact that the different objects (base vector, circle, curve) are drawn in different layers? Should these layers be merged in one or maybe the script can be made to select objects independent of what layer they're drawn on? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 15, 2009 Share Posted May 15, 2009 Thanks for your kind words It shouldn't matter which layer the objects are drawn on, just the type of objects they are - what objects are you having trouble selecting? Quote Link to comment Share on other sites More sharing options...
lizp Posted May 15, 2009 Author Share Posted May 15, 2009 Here's an example of the actual file (see attached). Quote Link to comment Share on other sites More sharing options...
lizp Posted May 15, 2009 Author Share Posted May 15, 2009 When I run your code it asks me to select a circle and I do that (either or the inner circle), then it asks me to select the base vector but when I select it it just just brings me back to the Command: The goal is to select that base vector and then select the point on the curve where base vector is applied ahnd have it decomposed accordingly. That happens on the illustration I gave ut not on the actual drawing. Quote Link to comment Share on other sites More sharing options...
lizp Posted May 15, 2009 Author Share Posted May 15, 2009 Sorry, the dxf file I thought I've attached exceeds the forum limits. Will have to see how to compress it. Quote Link to comment Share on other sites More sharing options...
lizp Posted May 15, 2009 Author Share Posted May 15, 2009 Here it is. Hope this time it'll go through. wheel20.zip Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 15, 2009 Share Posted May 15, 2009 Try this: (defun c:vec (/ doc spc Circ cCen lObj lAng lLen grdat cEnt pt tan tanpt norpt ptlst) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc))) (if (and (setq Circ (car (entsel "\nSelect Circle: "))) (eq "CIRCLE" (cdadr (entget Circ))) (setq bVec (car (entsel "\nSelect Base Vector: "))) (member (cdadr (entget bVec)) '("LINE" "LWPOLYLINE" "POLYLINE"))) (progn (setq cCen (cdr (assoc 10 (entget Circ))) lObj (vlax-ename->vla-object bVec) lAng (angle '(0 0 0) (vlax-curve-getFirstDeriv bVec (vlax-curve-getStartParam bVec))) lLen (vla-get-Length lObj)) (princ "\nSelect Curve: ") (while (eq 5 (car (setq grdat (grread t 5 2)))) (if (and (setq cEnt (car (nentselp (cadr grdat)))) (member (cdadr (entget cEnt)) '("LWPOLYLINE" "POLYLINE" "CIRCLE" "ELLIPSE" "ARC" "LINE" "SPLINE")) (not (eq Circ cEnt))) (redraw cEnt 3) (mapcar '(lambda (x) (redraw x 4)) (mapcar 'cadr (ssnamex (ssget "_X")))))) (if cEnt (progn (while (eq 5 (car (setq grdat (grread t 5 0)))) (redraw) (setq cObj (vlax-ename->vla-object cEnt) pt (vlax-curve-getClosestPointto cObj (cadr grdat)) tan (vlax-curve-getFirstDeriv cObj (vlax-curve-getParamatPoint cObj pt)) angdif (abs (- (angle '(0 0 0) tan) lAng)) tandif (abs (- (angle '(0 0 0) tan) (angle pt cCen))) tanpt (polar pt (angle '(0 0 0) tan) (* lLen (cos angdif))) radtan (polar pt (angle pt cCen) (* (distance pt tanpt) (cos tandif))) pertan (polar pt (+ (angle pt cCen) (/ pi 2)) (* (distance pt tanpt) (sin tandif))) norpt (polar pt (+ (/ pi 2) (angle '(0 0 0) tan)) (* lLen (sin angdif))) bsvpt (polar pt lAng lLen)) (grvecs (list 3 pt tanpt 3 pt norpt 8 pt cCen 1 pt bsvpt 4 pt radtan 4 pt pertan))) (if (eq 3 (car grdat)) (progn (setq ptlst (mapcar 'vlax-3d-point (list pt tanpt norpt cCen radtan pertan bsvpt))) (vla-put-color (vla-addline spc (car ptlst) (cadr ptlst)) acGreen) (vla-put-color (vla-addline spc (car ptlst) (caddr ptlst)) acGreen) (vla-put-color (vla-addline spc (car ptlst) (cadddr ptlst)) (vla-put-color (vla-addline spc (car ptlst) (nth 4 ptlst)) acCyan) (vla-put-color (vla-addline spc (car ptlst) (nth 5 ptlst)) acCyan) (vla-put-color (vla-addline spc (car ptlst) (last ptlst)) acRed)))))) (princ "\n<!> No Circle Selected <!>")) (command "_regenall") (princ)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 15, 2009 Share Posted May 15, 2009 If the objects are Blocks - this routine will not work - they will need to be Curve Objects (Polylines, Arcs, Ellipses, Circles, etc etc) for this to function. :wink: PS> Nice wheel! Quote Link to comment Share on other sites More sharing options...
lizp Posted May 15, 2009 Author Share Posted May 15, 2009 If the objects are Blocks - this routine will not work - they will need to be Curve Objects (Polylines, Arcs, Ellipses, Circles, etc etc) for this to function. :wink: PS> Nice wheel! Oh, I see. Can these be unblocked or a completely new wheel has to be drawn? Your last code works perfectly on the illustration. Can now the product of the length of the radial line and the component perpendicular to the radial line appear somewhere on the screen and possibly be imported into an Excel sheet? That would be the ultimate. Wonder if it's possible at all. See, the thing is all eight torques, calculated individually by your code, are to be summed up in the end to get the net torque. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 15, 2009 Share Posted May 15, 2009 Can these be unblocked or a completely new wheel has to be drawn? Well, the objects could be exploded into their individual components, using the EXPLODE command I suppose. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 15, 2009 Share Posted May 15, 2009 Ok give this a shot, it will write the info to a CSV file of the same name as the drawing file (defun c:vec (/ doc spc Circ bVec path cCen lObj lAng lLen grdat cEnt ofile pt tan angdif tandif radtan pertan tanpt norpt ptlst) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc))) (if (and (setq Circ (car (entsel "\nSelect Circle: "))) (eq "CIRCLE" (cdadr (entget Circ))) (setq bVec (car (entsel "\nSelect Base Vector: "))) (member (cdadr (entget bVec)) '("LINE" "LWPOLYLINE" "POLYLINE"))) (progn (setq path (strcat (getvar "DWGPREFIX") (substr (getvar "DWGNAME") 1 (- (strlen (getvar "DWGNAME")) 4)) ".csv") cCen (cdr (assoc 10 (entget Circ))) lObj (vlax-ename->vla-object bVec) lAng (angle '(0 0 0) (vlax-curve-getFirstDeriv bVec (vlax-curve-getStartParam bVec))) lLen (vla-get-Length lObj)) (princ "\nSelect Curve: ") (while (eq 5 (car (setq grdat (grread t 5 2)))) (if (and (setq cEnt (car (nentselp (cadr grdat)))) (member (cdadr (entget cEnt)) '("LWPOLYLINE" "POLYLINE" "CIRCLE" "ELLIPSE" "ARC" "LINE" "SPLINE")) (not (eq Circ cEnt))) (redraw cEnt 3) (mapcar '(lambda (x) (redraw x 4)) (mapcar 'cadr (ssnamex (ssget "_X")))))) (if cEnt (progn (setq ofile (open path "a")) (while (eq 5 (car (setq grdat (grread t 5 0)))) (redraw) (setq cObj (vlax-ename->vla-object cEnt) pt (vlax-curve-getClosestPointto cObj (cadr grdat)) tan (vlax-curve-getFirstDeriv cObj (vlax-curve-getParamatPoint cObj pt)) angdif (abs (- (angle '(0 0 0) tan) lAng)) tandif (abs (- (angle '(0 0 0) tan) (angle pt cCen))) tanpt (polar pt (angle '(0 0 0) tan) (* lLen (cos angdif))) radtan (polar pt (angle pt cCen) (* (distance pt tanpt) (cos tandif))) pertan (polar pt (+ (angle pt cCen) (/ pi 2)) (* (distance pt tanpt) (sin tandif))) norpt (polar pt (+ (/ pi 2) (angle '(0 0 0) tan)) (* lLen (sin angdif))) bsvpt (polar pt lAng lLen)) (grvecs (list 3 pt tanpt 3 pt norpt 8 pt cCen 1 pt bsvpt 4 pt radtan 4 pt pertan))) (if (eq 3 (car grdat)) (progn (setq ptlst (mapcar 'vlax-3d-point (list pt tanpt norpt cCen radtan pertan bsvpt))) (vla-put-color (vla-addline spc (car ptlst) (cadr ptlst)) acGreen) (vla-put-color (vla-addline spc (car ptlst) (caddr ptlst)) acGreen) (vla-put-color (vla-addline spc (car ptlst) (cadddr ptlst)) (vla-put-color (vla-addline spc (car ptlst) (nth 4 ptlst)) acCyan) (vla-put-color (vla-addline spc (car ptlst) (nth 5 ptlst)) acCyan) (vla-put-color (vla-addline spc (car ptlst) (last ptlst)) acRed) (setq torq (* (distance pt cCen) (distance pt pertan))) (princ (strcat "\n<< Calculated Torque: " (rtos torq) " >>\n")) (write-line (rtos torq 2 ofile) (close ofile)))))) (princ "\n<!> No Circle Selected <!>")) (command "_regenall") (princ)) Quote Link to comment Share on other sites More sharing options...
SEANT Posted May 15, 2009 Share Posted May 15, 2009 . . . . See, the thing is all eight torques, calculated individually by your code, are to be summed up in the end to get the net torque. I'd hazard the guess that the Sum of all the torques will be zero. Can’t have something breaking the Second Law of Thermodynamics, now can we. Quote Link to comment Share on other sites More sharing options...
lizp Posted May 15, 2009 Author Share Posted May 15, 2009 I'd hazard the guess that the Sum of all the torques will be zero. Can’t have something breaking the Second Law of Thermodynamics, now can we. @SEANT, I'd love to discuss this with you and with anyone who'd be willing to but let's settle first on the tool. Wonder if this forum would be the best place to carry out such discussion? Quote Link to comment Share on other sites More sharing options...
SEANT Posted May 15, 2009 Share Posted May 15, 2009 Good Point. And, the likely outcome of this particular thread is good CAD. That's the name of the game at this forum. Quote Link to comment Share on other sites More sharing options...
lizp Posted May 15, 2009 Author Share Posted May 15, 2009 Sorry, can't find where the CSV file is saved. Also, can't the value be displayed somewhere on the screen? Quote Link to comment Share on other sites More sharing options...
lizp Posted May 15, 2009 Author Share Posted May 15, 2009 Good Point. And, the likely outcome of this particular thread is good CAD. That's the name of the game at this forum. Indeed. It's unbelievable what Lee is doing. A rare individual. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted May 15, 2009 Share Posted May 15, 2009 I notice the csv is saved to where the drawing file is. Quote Link to comment Share on other sites More sharing options...
lizp Posted May 15, 2009 Author Share Posted May 15, 2009 I notice the csv is saved to where the drawing file is. Yeah, I'm trying to find it there, to no avail, though. Quote Link to comment Share on other sites More sharing options...
lizp Posted May 15, 2009 Author Share Posted May 15, 2009 I got it. All set. I've probably worked with the older version of vec.lsp thinking it's the new one. Would be nice to have the value on the screen too. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 15, 2009 Share Posted May 15, 2009 Indeed. It's unbelievable what Lee is doing. A rare individual. Thanks Sorry, can't find where the CSV file is saved. Also, can't the value be displayed somewhere on the screen? The value is printed to the command line when the function completes I notice the csv is saved to where the drawing file is. This is indeed correct, - it is saved in the same place as where the drawing is saved, under the same name as the drawing. 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.