Mugna101 Posted November 5, 2020 Posted November 5, 2020 Sup fellas!! Im here calling for your aid again! just cuz you guys are so pro maybe you will have a quick fix (defun C:NA (/ REAL1 REAL2 ARROW ANGF1 ANGF2 ANGT NORTH ) (setq REAL1 (getpoint "\nFirst point on background")) ; Real angle point 1 (setq REAL2 (getpoint "\nSecond point on background")) ; Real angle point 2 (setq ARROW (getpoint "\nPick arrow basepoint")) (setq ANGF1 (angle REAL1 REAL2)) ; extracting angle - in radians (setq ANGF2 (Angtos ANGF1 0 2)) ; converting to degrees (setq ANGT (strcat "-" ANGF )) ; attempting to reverse the angle in order to get a mirror image of the angle (setq NORTH (ssget I)) (command "Rotate" NORTH "" ARROW ANGT) (princ)) This lisp is used to get the degrees of object based on 2 points as u can see what i need to do then is to rotate the object i select in the same angle but in the opposite direction (it will be the mirror image of the original angle. my best guess for why it isnt working is because im mixing degrees with angles in my brain so i cant figure out a way to express it correctly. I trust u now plz. my head aches after 2 days of trying to solve this alone. ALSO: In order to make this lisp even greater, instead of rotating an object, i would like it to insert a block named NORTHARROW in the angle that im struggling to get. is that possible without making this lisp too advanced? (i like keeping stuff simple) Quote
Jonathan Handojo Posted November 5, 2020 Posted November 5, 2020 You mean you want to mirror an object? Then why use rotate instead of mirror? 1 Quote
Mugna101 Posted November 5, 2020 Author Posted November 5, 2020 12 minutes ago, Jonathan Handojo said: You mean you want to mirror an object? Then why use rotate instead of mirror? i dont want to mirror it.. I want to get the angle of the object, mirror the angle (my attempt in the code was getting the angle and putting a minus sign infront of it) and then with the new angle i want to rotate a different object to it. if the 1st object's angle is 90 degrees from north i want it to take the number 90, put a minus sign infront of it, so it will be -90. then i want to apply the new angle (-90) on a different object (which is a north arrow) so it will turn to it's true position relevant to a reference of the first object but when its on 0degrees from north. Quote
Jonathan Handojo Posted November 5, 2020 Posted November 5, 2020 4 minutes ago, Mugna101 said: I want to get the angle of the object What object? Blocks? 5 minutes ago, Mugna101 said: mirror the angle Along what axis? By putting a minus sign, you're mirroring that angle along the x axis. If your object is a block, you can get its rotation by selecting the block and using: (cdr (assoc 50 (entget (car (entsel "\nSelect block: "))))) To me, it sounds like you're trying to draw a north arrow on the direction of the rotation of the original object itself. Still a bit unclear though. Maybe you can post a sample drawing detailing what is original, and what it is you want at the end result. 1 Quote
Tharwat Posted November 5, 2020 Posted November 5, 2020 Something like this? (defun C:NA (/ REAL1 REAL2 ARROW ANGF1 ANGF2 NORTH) (if (and (setq REAL1 (getpoint "\nFirst point on background")) ; Real angle point 1 (setq REAL2 (getpoint "\nSecond point on background" REAL1)) ; Real angle point 2 (setq ARROW (getpoint "\nPick arrow basepoint")) (setq ANGF1 (angle REAL1 REAL2)) ; extracting angle - in radians (setq ANGF2 (Angtos (+ ANGF1 pi) 0 2)) ; converting to degrees ;; (setq ANGT (strcat "-" ANGF)) ; attempting to reverse the angle in order to get a mirror image of the angle (setq NORTH (ssget "_:L")) ) (command "Rotate" NORTH "" "_non" ARROW ANGF2) ) (princ) ) 1 Quote
Mugna101 Posted November 5, 2020 Author Posted November 5, 2020 14 minutes ago, Tharwat said: Something like this? (defun C:NA (/ REAL1 REAL2 ARROW ANGF1 ANGF2 NORTH) (if (and (setq REAL1 (getpoint "\nFirst point on background")) ; Real angle point 1 (setq REAL2 (getpoint "\nSecond point on background" REAL1)) ; Real angle point 2 (setq ARROW (getpoint "\nPick arrow basepoint")) (setq ANGF1 (angle REAL1 REAL2)) ; extracting angle - in radians (setq ANGF2 (Angtos (+ ANGF1 pi) 0 2)) ; converting to degrees ;; (setq ANGT (strcat "-" ANGF)) ; attempting to reverse the angle in order to get a mirror image of the angle (setq NORTH (ssget "_:L")) ) (command "Rotate" NORTH "" "_non" ARROW ANGF2) ) (princ) ) Ive tried it in vlide and it still replies with a nil on the strcat part. also i didnt understand what you did if u can explain Quote
Tharwat Posted November 5, 2020 Posted November 5, 2020 I commented the strcat function so its not required and the variable 'ANGF2' is the one that obtains the angle plus ( pi = 180 Degrees ) added to the collected angle. 1 Quote
Mugna101 Posted November 5, 2020 Author Posted November 5, 2020 34 minutes ago, Jonathan Handojo said: What object? Blocks? Along what axis? By putting a minus sign, you're mirroring that angle along the x axis. If your object is a block, you can get its rotation by selecting the block and using: (cdr (assoc 50 (entget (car (entsel "\nSelect block: "))))) To me, it sounds like you're trying to draw a north arrow on the direction of the rotation of the original object itself. Still a bit unclear though. Maybe you can post a sample drawing detailing what is original, and what it is you want at the end result. the object im getting an angle from is not a block. it could be random stuff. all i need to understand really is how to turn the angle i got from these 2 points to the opposite angle. ex; 0degrees is north. the object is rotated 50 degrees clockwise to north. the lisp takes the 50 degrees info and makes it either 310 degrees or -50 degrees clockwise to north or 50 degrees counter clockwise to north. it needs to work with every angle i draw from every 2 points i choose. and also if its possible that instead of rotating the selected arrow, it will insert a block named NORTHARROW in the angle that is required. Quote
Mugna101 Posted November 5, 2020 Author Posted November 5, 2020 5 minutes ago, Tharwat said: I commented the strcat function so its not required and the variable 'ANGF2' is the one that obtains the angle plus ( pi = 180 Degrees ) added to the collected angle. adding 180 degrees give me the desired angle, if the angle is 30, the desired angle will be -30 or 330 if the angle is 93, the desired angle will be -93 or 267 Quote
Jonathan Handojo Posted November 5, 2020 Posted November 5, 2020 So you basically want to insert a block at the direction of the angle mirrored along a vertical axis as the 0 degrees is to the north. When you click two points, the angle is returned counterclockwise from x-axis. (for instance, if the angle resulting from (angle p1 p2) is 15°, then you want the arrow to be pointing at 165° if I'm understanding it right. If angle supplied is 240°, then arrow points to 300°). Is that right? 1 Quote
Mugna101 Posted November 5, 2020 Author Posted November 5, 2020 46 minutes ago, Jonathan Handojo said: So you basically want to insert a block at the direction of the angle mirrored along a vertical axis as the 0 degrees is to the north. When you click two points, the angle is returned counterclockwise from x-axis. (for instance, if the angle resulting from (angle p1 p2) is 15°, then you want the arrow to be pointing at 165° if I'm understanding it right. If angle supplied is 240°, then arrow points to 300°). Is that right? if the angle is 15 i need it to result angle 345 which is 360-15. if the angle is 240 then i need the result of 360-240 which is 120 I need it to show where is the north relative to the object, Where i take the points, north is 0. where i put the arrow in the angle the lisp calculated then north isnt at 0 but the object will be turned to 0degrees (so north must be at same angle relatively) Quote
eldon Posted November 5, 2020 Posted November 5, 2020 Whatever the angle is, multiply it by minus one (-1) 1 Quote
Mugna101 Posted November 5, 2020 Author Posted November 5, 2020 (edited) 38 minutes ago, eldon said: Whatever the angle is, multiply it by minus one (-1) smart! but in what command should i do it? is it possible youll show me? Ive tested it this way: (defun C:NA (/ REAL1 REAL2 ARROW ANGF1 ANGF2 ANGT NORTH ) (setq REAL1 (getpoint "\nFirst point on background")) ; Real angle point 1 (setq REAL2 (getpoint "\nSecond point on background")) ; Real angle point 2 (setq ARROW (getpoint "\nPick arrow location")) (setq ANGF1 (angle REAL1 REAL2)) ; extracting angle - in radians (setq ANGF2 (Angtos ANGF1 0 2)) ; converting to degrees (setq ANGT (* -1 ANGF )) ; attempting to reverse the angle in order to get a mirror image of the angle (setq NORTH (ssget I)) (command "Insert" "ARROWNORTH" NORTH ARROW ANGT "" ) (princ)) got numberp : nil Edited November 5, 2020 by Mugna101 Testing Quote
BIGAL Posted November 5, 2020 Posted November 5, 2020 (edited) Look at this line carefully the angle is in opposite direction. (setq ANGF1 (Angtos (angle REAL2 REAL1) 2 0)) ; extracting angle - in degrees and opposite direction (command "-Insert" "ARROWNORTH" NORTH ARROW ANGF1 "" ) Edited November 5, 2020 by BIGAL 1 Quote
eldon Posted November 6, 2020 Posted November 6, 2020 17 hours ago, Mugna101 said: smart! but in what command should i do it? is it possible you'll show me?.......... I was merely advising you that to use an angle in the other direction, one only has to put a negative sign in front of it. I do not do lisp nowadays! 1 Quote
pkenewell Posted November 6, 2020 Posted November 6, 2020 (edited) On 11/5/2020 at 8:57 AM, Mugna101 said: got numberp : nil You are trying to multiply the -1 by a string. ANGTOS outputs a string. you have to do the math before you convert the number to a string. The negative 1 will work with radians too so just apply it to the radians angle. Edited November 6, 2020 by pkenewell 1 Quote
Jonathan Handojo Posted November 7, 2020 Posted November 7, 2020 It's the variable that's wrong. There's no variable ANGF. So when you tried (* -1 angf), it returns the error you described. (defun c:test ( / ang blkname bpt) (setq blkname "ARROWNORTH") (and (setq ang (getangle "\nSpecify angle or click two points <exit>: ")) (setq bpt (getpoint "\nSpecify arrow location <exit>: ")) (entmake (list '(0 . "INSERT") (cons 2 blkname) (cons 10 bpt) '(41 . 1.0) '(42 . 1.0) '(43 . 1.0) (cons 50 (- ang)) ) ) ) (princ) ) 1 Quote
Mugna101 Posted November 8, 2020 Author Posted November 8, 2020 (edited) imma try that right now thx all!!! sometimes i do stupid mistakes.. still learning how to write codes On 11/7/2020 at 6:40 AM, Jonathan Handojo said: It's the variable that's wrong. There's no variable ANGF. So when you tried (* -1 angf), it returns the error you described. (defun c:test ( / ang blkname bpt) (setq blkname "ARROWNORTH") (and (setq ang (getangle "\nSpecify angle or click two points <exit>: ")) ; ok thats the angle (setq bpt (getpoint "\nSpecify arrow location <exit>: ")) ; thats the arrow basepoint (entmake (list '(0 . "INSERT") (cons 2 blkname) (cons 10 bpt) '(41 . 1.0) '(42 . 1.0) '(43 . 1.0) (cons 50 (- ang)) ) ) ) (princ) ) Ive tried that. if i use the mouse to pick points its like it is deducting 90 degrees out of it. If i pick one in the middle and the 2nd to the left the arrow will point south instead of to the right side. if i type an angle it works correctly. any clues? anyways ive wrote it this way now after listening to all of you guys, (defun C:NA (/ REAL1 REAL2 ARROW ANGF1 ANGF2 ANGT ) (setq REAL1 (getpoint "\nFirst point on background")) ; Real angle point 1 (setq REAL2 (getpoint "\nSecond point on background")) ; Real angle point 2 (setq ARROW (getpoint "\nPick arrow location")) (setq ANGF1 (angle REAL1 REAL2)) ; extracting angle - in radians (setq ANGF2 (* -1 ANGF1 )) ; attempting to reverse the angle in order to get a mirror image of the angle (setq ANGFT (Angtos ANGF2 0 2)) ; converting to degrees (command "Insert" "NORTHARROW" ARROW ANGT "" ) ; not sure how to use that command correctly (princ)) now it comes up with an error of unknown command "NA" press f1 something something.. i think now i wrote the insert command wrong. is it possible to explain what input i need after using "insert" command? i changed stuff, i dunno really what im doing. im so close to finishing this thnx to you all! Edited November 8, 2020 by Mugna101 Ive tried your suggestions. still running into some issues as described in the comment :D Quote
Jonathan Handojo Posted November 8, 2020 Posted November 8, 2020 (edited) 6 hours ago, Mugna101 said: if i use the mouse to pick points its like it is deducting 90 degrees out of it. That's what I mean. To you, 0° means North, but to AutoCAD, 0° means the direction of the x-axis (in other words, "East"), not North. And it increases as you go counterclockwise. So it's like a bearing (if you're familiar), except that the bearing's "North" is towards the east and goes counterclockwise. That's how it works in AutoCAD. For your reference, try: Turn Dynamic Input On Start a LINE command Click a point Move your mouse around, and you'll notice how the angle behaves. It's referenced to the positive x-axis of the UCS. That's why I was trying to confirm from my post earlier: "So you basically want to insert a block at the direction of the angle mirrored along a vertical axis as the 0 degrees is to the north. When you click two points, the angle is returned counterclockwise from x-axis. (for instance, if the angle resulting from (angle p1 p2) is 15°, then you want the arrow to be pointing at 165° if I'm understanding it right. If angle supplied is 240°, then arrow points to 300°). Is that right?" I potentially never use (command) because it tends to be at least six times slower, but in your case, you're only inserting one block. And your error is, once again, caused by a spelling mistake ANGT, as opposed to ANGFT Your line (setq ANGF1 (angle REAL1 REAL2)) would return the same thing as getangle either way, so using getangle is shorter, quicker, and easier to use, which is why I used that instead. You probably want to use this then: (defun c:test ( / ang blkname bpt) (setq blkname "ARROWNORTH") (and (setq ang (getangle "\nSpecify angle or click two points <exit>: ")) ; ok thats the angle (setq bpt (getpoint "\nSpecify arrow location <exit>: ")) ; thats the arrow basepoint (entmake (list '(0 . "INSERT") (cons 2 blkname) (cons 10 bpt) '(41 . 1.0) '(42 . 1.0) '(43 . 1.0) (cons 50 (if (< ang pi) (- pi ang) (- (* 3 pi) ang))) ) ) ) (princ) ) Edited November 8, 2020 by Jonathan Handojo 1 Quote
Mugna101 Posted November 8, 2020 Author Posted November 8, 2020 1 hour ago, Jonathan Handojo said: That's what I mean. To you, 0° means North, but to AutoCAD, 0° means the direction of the x-axis (in other words, "East"), not North. And it increases as you go counterclockwise. So it's like a bearing (if you're familiar), except that the bearing's "North" is towards the east and goes counterclockwise. That's how it works in AutoCAD. For your reference, try: Turn Dynamic Input On Start a LINE command Click a point Move your mouse around, and you'll notice how the angle behaves. It's referenced to the positive x-axis of the UCS. That's why I was trying to confirm from my post earlier: "So you basically want to insert a block at the direction of the angle mirrored along a vertical axis as the 0 degrees is to the north. When you click two points, the angle is returned counterclockwise from x-axis. (for instance, if the angle resulting from (angle p1 p2) is 15°, then you want the arrow to be pointing at 165° if I'm understanding it right. If angle supplied is 240°, then arrow points to 300°). Is that right?" I potentially never use (command) because it tends to be at least six times slower, but in your case, you're only inserting one block. And your error is, once again, caused by a spelling mistake ANGT, as opposed to ANGFT Your line (setq ANGF1 (angle REAL1 REAL2)) would return the same thing as getangle either way, so using getangle is shorter, quicker, and easier to use, which is why I used that instead. You probably want to use this then: (defun c:test ( / ang blkname bpt) (setq blkname "ARROWNORTH") (and (setq ang (getangle "\nSpecify angle or click two points <exit>: ")) ; ok thats the angle (setq bpt (getpoint "\nSpecify arrow location <exit>: ")) ; thats the arrow basepoint (entmake (list '(0 . "INSERT") (cons 2 blkname) (cons 10 bpt) '(41 . 1.0) '(42 . 1.0) '(43 . 1.0) (cons 50 (if (< ang pi) (- pi ang) (- (* 3 pi) ang))) ) ) ) (princ) ) Bud you are pro! thnx alot 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.