Jump to content

Routine for Decomposition of Vectors


lizp

Recommended Posts

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?

Link to comment
Share on other sites

  • Replies 231
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    107

  • lizp

    99

  • SEANT

    24

  • The Buzzard

    2

Top Posters In This Topic

Posted Images

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

. . . . 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. o:)

Link to comment
Share on other sites

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. o:)

 

@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?

Link to comment
Share on other sites

Good Point. And, the likely outcome of this particular thread is good CAD. That's the name of the game at this forum.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...