Randolph Posted January 14, 2011 Share Posted January 14, 2011 Hi, I had this topic before, and a collegue here helped me along. It is about sort of an align functionality. Unfortunately, the lisp has a bug which doesn't always show. Let me explain: Say I have a table in a ground plan. Its x,y-position is right, but in 3D, it hovers above the ground. I want to put on the floor without moving it in x,y. I enter TZP (translate along z using points), select the table, click the table leg base and then any corner of the room. The table will drop to the floor. Now I need the same table on the 2nd floor. I enter DZP (duplicate along z using points), select the table, click the table leg base again and then any point on the level of the 2nd floor. The clue is that I don't need any 2 points which are exactly above each other. This is the code: (defun c:TZP ( / a b c s) (princ "Select objects: ") (setq s (ssget) a (getpoint "\nSelect item base point: ") b (getpoint "\nSelect target point: ") c (list (car a) (cadr a) (caddr b))) (vl-cmdf "move" s "" a c) ) Same goes with copy resp the other axis. I find the code quite elegant, as far as an architect can judge. But for whatever reason, from time to time the "table" will move in x,y-ways in an unpredictable manner, but most often close to the required position. As things get worse the longer I work with this command, could it be that this has to do with variables beeing assigned values which are not cleared? Or with the object snap not beeing deactivated? Thanx for your help in advance! Quote Link to comment Share on other sites More sharing options...
ReMark Posted January 14, 2011 Share Posted January 14, 2011 Are you sure that from time to time you haven't specified a new "origin" and the table is being moved relative to it? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 14, 2011 Share Posted January 14, 2011 Why you are making a routine which is already supported in Autocad ? Quote Link to comment Share on other sites More sharing options...
Randolph Posted January 14, 2011 Author Share Posted January 14, 2011 ReMark: you mean another ucs? I hope that I'm out of making that mistake ... tharwat313: And how is it supported? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 14, 2011 Share Posted January 14, 2011 I mean you can use the "align" command directly in Autocad and there is no need for re-writing a routine , unless you have any other special reasons to do that . Tharwat Quote Link to comment Share on other sites More sharing options...
ReMark Posted January 14, 2011 Share Posted January 14, 2011 I was referring to the origin of the UCS. Don't you ever move this around (as needed)? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 14, 2011 Share Posted January 14, 2011 Also you can not use command move instead of align command to make them aligned with each other. Quote Link to comment Share on other sites More sharing options...
Randolph Posted January 14, 2011 Author Share Posted January 14, 2011 ReMark: Of course I do move the UCS. I just wanted to express that I usually set it to "world" before moving or copying vertically or horzontally. Tharwat: Because the align command works quite differently to what I need. Maybe I was misunderstandable using that expression. What I need is just: move an object from the height of point 1 to the height point 2 without else moving, rotating or scaling it. Quote Link to comment Share on other sites More sharing options...
Randolph Posted January 14, 2011 Author Share Posted January 14, 2011 Tharwat: I know. That's what I usually do: measure the distance, copy the z-value, call my command tz (move z-ways) and paste the z-value. But that's tiresome on the long term. It would be so helpful if anybody found the bug in above routine, as I didn't/couldn't. Quote Link to comment Share on other sites More sharing options...
MSasu Posted January 14, 2011 Share Posted January 14, 2011 (edited) Seems that you want to move some entities to a new elevation - for sure you can use OSNAP filters to achive this. Regarding the inconsistent behaviour of the routine I suppose that is from having OSNAP mode activated while using the routine; please find below some suggested corrections. (defun c:TZP ( / [color=red]OldOsm[/color] a b c s) [color=red](setq OldOsm (getvar "OSMODE"))[/color] [color=red](princ "Select objects: ")[/color] [color=red](if (and[/color] (setq s (ssget)) (setq a (getpoint "\nSelect item base point: ")) (setq b (getpoint "\nSelect target point: "))[color=red])[/color] [color=red](progn[/color] (setq c (list (car a) (cadr a) (caddr b))) [color=red](setvar "OSMODE" 0)[/color] (vl-cmdf "move" s "" a c) [color=red])[/color] [color=red])[/color] [color=red](setvar "OSMODE" OldOsm)[/color] [color=red](princ)[/color] ) Regards, Mircea Edited January 18, 2011 by MSasu fixed a syntax error Quote Link to comment Share on other sites More sharing options...
Randolph Posted January 14, 2011 Author Share Posted January 14, 2011 http://www.cadtutor.net/forum/showthread.php?49158-Move-an-Object-along-an-Axis-using-Coordinate-Filters As I wrote, we had that topic before. I liked Frerefill's version for its simplicity, but maybe I'll just try Alan's version. Quote Link to comment Share on other sites More sharing options...
Randolph Posted January 14, 2011 Author Share Posted January 14, 2011 Hi Mircea, thanx, sorry I didn't see you reply before my last posting. I'll try it yor way; OSNAP is also my suspect. Ralph Quote Link to comment Share on other sites More sharing options...
Randolph Posted January 18, 2011 Author Share Posted January 18, 2011 Hi Mircea, basically, your code works. Only that it deactivates the osnap before choosing the points, which is not so good. Also, it seems that it does not reactivate the osnap. It seems that your code asks the osnap status and shall regenerate it afterwards, but I didn't full understand how. Thus I changed it to my more primitive way, and now it seems to work: (defun c:TZP ( / OldOsm a b c s) (princ "Select objects: ") (if (and (setq s (ssget)) (setq a (getpoint "\nSelect item base point: ")) (setq b (getpoint "\nSelect target point: "))) (progn (setq c (list (car a) (cadr a) (caddr b))) (COMMAND "_OSNAP" "") (vl-cmdf "_move" s "" a c) ) ) (COMMAND "_OSNAP" "_END,_INT,_MID,_CEN,_INS,_PER") (princ) ) Quote Link to comment Share on other sites More sharing options...
MSasu Posted January 18, 2011 Share Posted January 18, 2011 Seems that you missed to copy some lines from my example - I added those to your code along with comments of each action. The OSNAP mode is stored in OSMODE system variable: 1st, the current setting is stored into a local variable; 2nd, the mode is disabled to don't interfere with the command call; 3rd, the previously stored state is restored. Please remember that it is a very good programming practice to restore user's environment after your routine is done. (defun c:TZP ( / OldOsm a b c s) [color=blue] (setq OldOsm (getvar "OSMODE")) ;retain current state of OSNAP mode[/color] (princ "Select objects: ") (if (and (setq s (ssget)) (setq a (getpoint "\nSelect item base point: ")) (setq b (getpoint "\nSelect target point: "))) (progn (setq c (list (car a) (cadr a) (caddr b))) [color=blue];[/color](COMMAND "_OSNAP" "") [color=blue](setvar "OSMODE" 0) ;disable OSNAP mode [/color] (vl-cmdf "_move" s "" a c) ) ) [color=blue] (setvar "OSMODE" OldOsm) ;restore previous state of OSNAP mode[/color] [color=blue];[/color](COMMAND "_OSNAP" "_END,_INT,_MID,_CEN,_INS,_PER") (princ) ) Regards, Mircea Quote Link to comment Share on other sites More sharing options...
MSasu Posted January 18, 2011 Share Posted January 18, 2011 @Randolph, you are right, there was an error in the previous code - I fixed it now. Sorry for inconvenience. Thank you. Regards, Mircea Quote Link to comment Share on other sites More sharing options...
Randolph Posted January 18, 2011 Author Share Posted January 18, 2011 Don't apologize, you helped me a lot! I agree that the method of restoring the previous status is more elegant. But on the other side, I have lots of commands with (COMMAND "_OSNAP" "_END,_INT,_MID,_CEN,_PER,_INS"). This is because I'm no programmer, and copied my acad.lsp together from many places. By the way: would you mind lokking at my other thread: Rotate around x,y,z-axis Somhow, it seems to be a problem there. Quote Link to comment Share on other sites More sharing options...
MSasu Posted January 18, 2011 Share Posted January 18, 2011 If decide to switch to usage of system variables instead of command call, you can set the current mode by summate the values for each desired mode: None 0 Endpoint 1 Midpoint 2 Center 4 Node 8 Quadrant 16 Intersection 32 Insertion 64 Perpendicular 128 Tangent 256 Nearest 512 Apparent Intersection 2048 Extension 4096 Parallel 8192 For example: Endpoint + Midpoint + Quadrant: OSMODE = 1 + 2 + 16 = 19 Regards, Mircea 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.