Jump to content

slice in a script


drazzilb531

Recommended Posts

I'm new to AutoCAD and Lisp. I'm trying to use Lisp as a script to generate 3d objects in AutoCAD. What I'd like to do:

Create a cylinder to use as the base for my object

Slice it up a number of times

 

Sounds simple, but I've been having some problems. I've included some of my code below:

(defun c:rb ()
   (command "cylinder" "0.000000,0.000000,-4.000000" "1" "8")
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.000000,1.000000,0.000000" "1.000000,-1.000000,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "1"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.923880,-2.031530,0.000000" "-0.076120,2.796897,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "2"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.707107,-0.292893,0.000000" "-0.292893,1.707107,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "3"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.382683,0.509666,0.000000" "-0.617317,1.338093,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "4"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.000000,1.000000,0.000000" "-1.000000,1.000000,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "5"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "0.617317,1.338093,0.000000" "-1.382683,0.509666,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "6"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "0.292893,1.707107,0.000000" "-1.707107,-0.292893,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "7"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "0.076120,2.796897,0.000000" "-1.923880,-2.031530,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "8"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "-1.000000,1.000000,0.000000" "-1.000000,-1.000000,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "9"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "0.076120,-2.796897,0.000000" "-1.923880,2.031530,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "10"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "0.292893,-1.707107,0.000000" "-1.707107,0.292893,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "11"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "0.617317,-1.338093,0.000000" "-1.382683,-0.509666,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "12"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.000000,-1.000000,0.000000" "-1.000000,-1.000000,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "13"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.382683,-0.509666,0.000000" "-0.617317,-1.338093,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "14"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.707107,0.292893,0.000000" "-0.292893,-1.707107,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "15"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.923880,2.031530,0.000000" "-0.076120,-2.796897,0.000000" "0.000000,0.000000,0.000000")
   (princ (getint "16"))
   (princ)
)

 

This should create a tip to the cylinder that makes it look something like a pencil. However, I can run it several times back to back (deleting the remaining object in between each run) and get different results. For example, sometimes it will return an error like "The point should not be on the slicing plane" - describing the point when you choose which of the 2 new objects you want to keep. Another time, it will complete, but the object isn't sliced the way I expected. This seems odd to me. I'm not familiar with the ins and outs of lisp or autocad, but I'm having a hard time imagining what I could be doing wrong with such a simple program.

 

Any advice?

Link to comment
Share on other sites

Yes, it creates something like a pencil... It works fine on my netbook, I only commented out lines I think are sufficient... You can achieve almost the same with cylinder and cone, or extruded n sided polygon with n sided pyramid at the top...

 

(defun c:rb ()
   (command "cylinder" "0.000000,0.000000,-4.000000" "1" "8")
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.000000,1.000000,0.000000" "1.000000,-1.000000,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "1"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.923880,-2.031530,0.000000" "-0.076120,2.796897,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "2"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.707107,-0.292893,0.000000" "-0.292893,1.707107,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "3"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.382683,0.509666,0.000000" "-0.617317,1.338093,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "4"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.000000,1.000000,0.000000" "-1.000000,1.000000,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "5"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "0.617317,1.338093,0.000000" "-1.382683,0.509666,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "6"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "0.292893,1.707107,0.000000" "-1.707107,-0.292893,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "7"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "0.076120,2.796897,0.000000" "-1.923880,-2.031530,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "8"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "-1.000000,1.000000,0.000000" "-1.000000,-1.000000,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "9"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "0.076120,-2.796897,0.000000" "-1.923880,2.031530,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "10"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "0.292893,-1.707107,0.000000" "-1.707107,0.292893,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "11"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "0.617317,-1.338093,0.000000" "-1.382683,-0.509666,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "12"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.000000,-1.000000,0.000000" "-1.000000,-1.000000,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "13"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.382683,-0.509666,0.000000" "-0.617317,-1.338093,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "14"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.707107,0.292893,0.000000" "-0.292893,-1.707107,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "15"))
   (command "slice" "all" "" "3" "0.000000,0.000000,0.869287" "1.923880,2.031530,0.000000" "-0.076120,-2.796897,0.000000" "0.000000,0.000000,0.000000")
   ;(princ (getint "16"))
   (princ)
)

Link to comment
Share on other sites

Thanks for testing it out on your computer. It seems then that there is a problem with my setup. I don't think I've changed any of the default settings; maybe something got screwed up during the install.

Link to comment
Share on other sites

I tried turning off object snaps and the code ran fine. Thank you for thinking of that! The script still seems to have problems when I'm too zoomed in; I have to be able to see the whole cylinder on the screen or it is really slow and sometimes has issues. I'm thinking this is due to the fence command (maybe it switches to relative coordinates when off the screen), but this is not a big deal since I can just start zoomed way out.

 

Thanks again.

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