Ray1 Posted January 16, 2011 Share Posted January 16, 2011 Hello, I would like to draw a 3D cylinder with a circle and an ellipse at one end of the cylinder but rotated so the circle and ellipse are 90 degrees to the length of the cylinder. How do you rotate UCS and keep the points in the right places? (setq Spt (getpoint "\nStart point") Ept (getpoint "\nEnd point") Cpt (polar Ipt (angle Ept Ipt) 0.75) ) ; shaft (command "cylinder" Spt "D" 0.75 "A" Ept) ; head - ; need to get current UCS so it can be set back. ; need to rotate UCS here (command "Polygon" 6 Spt "C" (polar Spt 0 0.75) "extrude" "L" "" (polar Spt (angle Ept Ipt) 0.75) ) (command "circle" Cpt "D" 0.75 "extrude" "L" "" "T" -45 Spt ) ; need to put UCS back to original UCS here Thanks Ray1 Quote Link to comment Share on other sites More sharing options...
irneb Posted January 17, 2011 Share Posted January 17, 2011 You can convert the points between WCS and UCS using the trans function. I'd just use the UCS command itself with its Prev option. And to be able to set the UCS, use the UCS command's ZAxis option with the 2 points you have - which would set your XY plane on the bottom of the cylinder. Quote Link to comment Share on other sites More sharing options...
Ray1 Posted January 17, 2011 Author Share Posted January 17, 2011 Ok, I need more help because I am just not converting the points right. I need someone to write the code for me, in lisp, because I just can't get it working. Start with two random points, neither of which are in the WCS or UCS. Create a third point inline with the two points but to the right of the point on the right. Draw a cylinder, or line, between the two outside points. Draw a circle with the center at the left point but rotated 90 degrees to the axis of the cylinder, or line. Thanks Quote Link to comment Share on other sites More sharing options...
Ray1 Posted January 17, 2011 Author Share Posted January 17, 2011 Here is what I have so far. It works as long as Spt and Ept are in the WCS. What I need is for it to work regardless of where Spt and Ept are in relation to WCS or UCS. (setq Spt (getpoint "\nStart point") Ept (getpoint "\nEnd point") Cpt (polar Spt (angle Ept Spt) 0.75) ) (setq orthomode (getvar "orthomode")) (setvar "orthomode" 0) (command "cylinder" Spt "D" 0.75 "A" Ept) (setq cylss (ssget "L")) (command "UCS" "Y" 90) (setq Sptucs (trans Spt 0 1) Cptucs (trans Cpt 0 1) ) (command "circle" Cptucs "D" 1.5) (setq cirss (ssget "L")) (command "Polygon" 6 Sptucs "C" 0.75 "UCS" "previous" "extrude" "L" "" "D" Spt Cpt ) (setq headss (ssget "L")) (command "extrude" cirss "" "T" -45 "D" Cpt Spt "intersect" "L" headss "" "union" "L" cylss "" ) (setvar "orthomode" orthomode) Quote Link to comment Share on other sites More sharing options...
irneb Posted January 18, 2011 Share Posted January 18, 2011 Something like this: (defun c:Test1 (/ Spt Ept Cpt orthomode cylss Sptucs Cptucs cirss headss) ;; Save current UCS to be restored later - by Irné (command "_UCS" "_Named" "_Save" "DrawBoltRestore") (while (> (getvar "CMDACTIVE") 0) (command "_Yes")) ;Overwrite if existing (command "_UCS" "_World") ;Ensure WCS is current (setq Spt (getpoint "\nStart point") Ept (getpoint Spt "\nEnd point") ;Added by Irné so rubber banding works ;; Cpt (polar Spt (angle Ept Spt) 0.75) ;Omitted by Irné ) (setq orthomode (getvar "orthomode")) (setvar "orthomode" 0) (command "cylinder" Spt "D" 0.75 "A" Ept) ;; Set the UCS with origin at Spt and Z axis along towards Ept (command "_UCS" "_ZAxis" Spt Ept) (setq cylss (ssget "L")) ;| Not needed (command "UCS" "Y" 90) (setq Sptucs (trans Spt 0 1) Cptucs (trans Cpt 0 1) ) |; (command "circle" '(0.0 0.0 0.0) "D" 1.5) ;The current UCS's origin is exactly on Spt (setq cirss (ssget "L")) (command "Polygon" 6 '(0.0 0.0 0.0) "C" 0.75) ;Split command call to read better & edit easier ;; No need to change the UCS again (command "extrude" "L" "" 0.75) ;Don't need direction as current UCS is correct (setq headss (ssget "L")) (command "extrude" cirss "" "T" -45 0.75) ;Don't need direction as current UCS is correct (command "intersect" "L" headss "" "union" "L" cylss "") (setvar "orthomode" orthomode) (command "_UCS" "_Named" "Restore" "DrawBoltRestore") (while (> (getvar "CMDACTIVE") 0) (command "")) (princ) ) Quote Link to comment Share on other sites More sharing options...
Ray1 Posted January 18, 2011 Author Share Posted January 18, 2011 Thanks. It's working now. 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.