Jump to content

Rotating UCS and drawing new objects


Ray1

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

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