DB007 Posted September 5, 2010 Posted September 5, 2010 Hi, Please can some one help me with the code below, I have (probably badly) butchered this from a tutorial I found online and modified it to my needs. I thought I understood most of it but Im getting some strange results. Im very new to this so please be gentle, even if its not the best way to do it, can you bear with me and not change it completely, atleast yet until I have a better understanding anyway My problem is I was hoping it would draw a circle not at the end of the line but at an offset of 2.8284 at 45 degrees. (2mm at 90 degrees) But it seems to create the centre of the circle at the end of the line instead. Is this something im doing wrong with the polar command? Although if i print new_pt variable it seems to be correct, so im confused. Ive added the lengthen commmand myself to it so that might also be where its going wrong. Should probably say once I have this working I want to amend it to drawing a line from end of the original line to the point new_pt, but if I can crack why this isnt working that part hopefully should be easy(ish)! Thanks in advance. [left]; Draw Circle at fixed offset from end of line function (defun c:Crc1 (/ aks pp aks_hand aks_pt1 aks_pt2 aks_ang dist1 dist2 st_pt new_pt) ;Let's select the end of the axis where we will place the bubble ;and the selection point. (setq aks (entsel "\nPick Line close to end circle is required:")) ;;;Shorten the line by 6mm (command "_.lengthen" "de" "-6" aks "")[/left] [left](Setq pp (cadr aks) ; Selection point (PICKPOINT) aks_hand (entget (car aks)) ; List of axis member ) [/left] [left];Calculate the start and end points of axis and angle (setq aks_pt1 (cdr (assoc 10 aks_hand)) aks_pt2 (cdr (assoc 11 aks_hand))) (setq aks_ang (angle aks_pt1 aks_pt2)) ;Let's find which end of axis the selection ;point is more close to (setq dist1 (distance pp aks_pt1) dist2 (distance pp aks_pt2) ) ;Then set which end of the line to start circle (if (< dist1 dist2) (setq st_pt aks_pt1) (setq st_pt aks_pt2) )[/left] [left];find offset centre of circle (if (< dist1 dist2) (setq new_pt (polar st_pt (- aks_ang (/ pi 4.0)) 2.8284)) (setq new_pt (polar st_pt aks_ang 2.8284)) ) [/left] [left];Draw Circle (command "_.circle" new_pt 40) (princ) )[/left] Quote
JohnM Posted September 5, 2010 Posted September 5, 2010 You just need to turn off your snaps when the circle is made. 2 ways to do it: add “_non” after the “circle” (command "_.circle" "_non" new_pt 40) or use these before the circle command (setq osm (getvar “osmode”) to get settings (setvar “osmode” 0) sets snaps to none after the circle command set them back (setvar “osmode” osm) Quote
DB007 Posted September 5, 2010 Author Posted September 5, 2010 Thanks so much!! I have been trying to work that out for hours and so simple!! Is there an advantage using the system variable instead of "_non" just seems more code? Unless of course if you have multiple commmand you want to perform. Thanks again Quote
JohnM Posted September 5, 2010 Posted September 5, 2010 You’re exactly correct. If you have a lot of things being it’s better to use the getvat/setvar method, if it a little thing the non works well. The draw back is that when you start using getvar/setvar you will need to get into error trapping because if your program crashes you will need to set the variables back to original settings Quote
DB007 Posted September 6, 2010 Author Posted September 6, 2010 My code is progressing really well. I have tweaked it quite a lot but I've become quickly confused with probably another very simple problem.. I have replaced the circle command with line and using st_pt and end_pt I have drawn a line. The line is drawn fine but im getting error messages along the way (even though the code continues without a problem) saying unknown command. Ive done some experimenting and have found that the variables st_pt and end_pt are 3 dimensional X Y and Z. If I substitute the variables with a 2D point X and Y I dont get an error message. Do I need to remove the Z value from my variables? If so which command will do it? car is first value, cadr is second, cdr all but the 1st element. I cant find one for the 1st and 2nd element only or am I on the wrong track? I could leave it as it is but im just trying to tidy it up a bit. Many Thanks Quote
David Bethel Posted September 6, 2010 Posted September 6, 2010 Are you issuing a terminating enter? (command "_.LINE" pt1 pt2 "") The line command will takes 3d values. -David Quote
Sweety Posted September 6, 2010 Posted September 6, 2010 Can you please show the changes that you made with Line command ? We may try to help you as best as we could . Thank you. Quote
DB007 Posted September 6, 2010 Author Posted September 6, 2010 Opps... I cut and paste the code into a smaller function to post here and found I couldnt replicate the problem (even though im sure i tried that earlier.) So I started breaking it down again and found the problem was on an Arc command I added. I put "" at the end like shown:- (command "_.arc" "C" arcmid_pt arcst_pt nxt_pt "") but of course the arc command doesnt require the final enter like line does. So it had nothing to do with the line command i mentioned above. My mistake, sorry to bother you all. Quote
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.