TunzaGibbo Posted December 19, 2018 Share Posted December 19, 2018 I'm trying to write a small lisp file to do the following: I have a line which has comes from the command _xline. I don't believe this type of line has end points because I think it goes to infinity. I want to be able to touch on this xline and be able to get the angle of this xline. The reason for this is so that when I touch the line I will automatically get an xline rotated 90 degrees and ready to place somewhere in the drawing. Any help would be appreciated Regards tony Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 19, 2018 Share Posted December 19, 2018 (edited) Hi, Try it like this: (angle '(0. 0. 0.) (cdr (assoc 11 (entget <entity-name>)))) Edited December 19, 2018 by Tharwat Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted December 19, 2018 Author Share Posted December 19, 2018 Tharwat Thanks for that. Can you explain how this works And what command would you use to select the xline Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 19, 2018 Share Posted December 19, 2018 5 minutes ago, TunzaGibbo said: Tharwat Thanks for that. Can you explain how this works And what command would you use to select the xline Like this. (if (and (princ "\nSelect Xline :") (setq sel (ssget "_+.:E:S" '((0 . "XLINE")))) ) (angle '(0. 0. 0.) (cdr (assoc 11 (entget (ssname sel 0))))) ) Be informed is that the angle value would be in Radians. Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted December 20, 2018 Author Share Posted December 20, 2018 Thanks again. you are obviously good at Lisp unlike me who is learning. Which leaves me at a bit of a loss about your code. I understand up to "ssget" and are not sure what the rest of the line is saying. On the next line I understand "angle" but have never used it in this way. Is there a variable created for the angle of the line Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 20, 2018 Share Posted December 20, 2018 (edited) 2 hours ago, TunzaGibbo said: Thanks again. you are obviously good at Lisp unlike me who is learning. Which leaves me at a bit of a loss about your code. I understand up to "ssget" and are not sure what the rest of the line is saying. On the next line I understand "angle" but have never used it in this way. Is there a variable created for the angle of the line You're welcome. You can a variable to the return value of angle as follows: (setq ang (angle '(0. 0. 0.) (cdr (assoc 11 (entget (ssname sel 0)))))) Edited December 20, 2018 by Tharwat Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted December 20, 2018 Author Share Posted December 20, 2018 Hi Tharwat I've gotten this far but can't get the entry for the angle (where the ??? are) (defun c:qqq () ;(/ sel ang) (savevartoold) (constructionlayer) (if (and (princ "\nSelect Xline :") (setq sel (ssget "_+.:E:S" '((0 . "XLINE"))))) (setq ang (angle '(0. 0. 0.) (cdr (assoc 11 (entget (ssname sel 0))))))) (command "_xline" "A" ?????? pause "") (restoldvar) (princ) ) Thanks for your help tony Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 20, 2018 Share Posted December 20, 2018 Give this a shot and be sure is that your added sub-functions are working as well. (defun c:qqq (/ sel ang) (savevartoold) (constructionlayer) (if (and (princ "\nSelect Xline :") (setq sel (ssget "_+.:E:S" '((0 . "XLINE")))) (setq ang (angle '(0. 0. 0.) (cdr (assoc 11 (entget (ssname sel 0 ) ) ) ) ) ) ) (command "_xline" "A" (/ (* ang 180.0) pi)) ) (restoldvar) (princ) ) Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted December 20, 2018 Author Share Posted December 20, 2018 I'm getting this with that code Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 20, 2018 Share Posted December 20, 2018 Remove your functions from my posted codes above then try again. Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted December 20, 2018 Author Share Posted December 20, 2018 I got rid of the 3 sub functions and the program ran. Why won't it work with them?? Unfortunately the program doesn't correctly. As an example I have a construction line (XLINE) in my drawing which is at lets say 45 deg. The idea behind this lisp is to select the 45 deg line and have the program produce another construction line (XLINE) at 90 degrees to the selected line. So I would end up with a 90 degree cross. Sorry to be a pain Regards Tony Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 20, 2018 Share Posted December 20, 2018 That means is that your functions or one of them is reducing that error message which caused the program to exit with error so you need to correct them in prior. If you would like to add 90 Deg. to the angle of the selected Xline then just add it like this: (setq ang (+ (* pi 0.5) (angle '(0. 0. 0.) (cdr (assoc 11 (entget (ssname sel 0))))))) Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted December 20, 2018 Author Share Posted December 20, 2018 I'm just not getting this. This is "Getting too many arguments" (defun c:qqq (/ sel ang) ;(savevartoold) ;(constructionlayer) (if (and (princ "\nSelect Xline :") (setq sel (ssget "_+.:E:S" '((0 . "XLINE")))) (setq ang (+ (* pi 0.5) (angle '(0. 0. 0.) (cdr (assoc 11 (entget (ssname sel 0))))))))) (command "_xline" "A" (/ (* ang 180.0) pi)) ; (restoldvar) (princ) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 20, 2018 Share Posted December 20, 2018 Hope you can get it from the following demo. Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted December 20, 2018 Author Share Posted December 20, 2018 yes I have got now I have included the command line in the if statement and it works. Just have to get the subroutines fixed now what would change if I wanted the to select a line or a xline Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 20, 2018 Share Posted December 20, 2018 (defun c:qqq (/ sel ang lst) (if (and (princ "\nSelect Xline or LINE :") (setq sel (ssget "_+.:E:S" '((0 . "XLINE,LINE")))) (setq ang (+ (* pi 0.5) (angle (if (= (cdr (assoc 0 (setq lst (entget (ssname sel 0))))) "XLINE") '(0. 0. 0.) (cdr (assoc 10 lst)) ) (cdr (assoc 11 lst)) ) ) ) ) (command "_xline" "A" (/ (* ang 180.0) pi)) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted December 20, 2018 Author Share Posted December 20, 2018 All works good Thank you very much for your help I really appreciate that. I wish I could help you but I don't think you need it. All the best Tony Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 20, 2018 Share Posted December 20, 2018 You're welcome anytime Tony. Quote Link to comment Share on other sites More sharing options...
TunzaGibbo Posted December 21, 2018 Author Share Posted December 21, 2018 Hi Tharwat Is there a line of code that I can use to get the the following info by just touching an entity. The entity is a line and I need: The length The start & end point The angle Regards Tony Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 21, 2018 Share Posted December 21, 2018 Hi, (setq ent (car (entsel "\nSelect line :"))) (setq lst (entget ent)) (setq startpoint (cdr (assoc 10 lst))) (setq end (cdr (assoc 11 lst))) (setq len (distance startpoint end)) ;; length (setq ang (angle startpoint end)) 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.