Mellie Posted August 14, 2014 Share Posted August 14, 2014 (edited) Good morning, I am trying to write a program in which will take the text "Road" (which is put in its own layer called Road) and move it to the right by 3791.4481. I am also trying to take the text "Field" (which is put in its own layer called Field) and move it to the left by 3791.4481. Below is the code: (defun C: Melanie () ; define function ;Selects Road text and moves it to the Field text coordinates (setq Road (ssget "X" '(8."Road")) (setq pt 1 '(0 0 0)) (setq pt 2 '(3791.4481 0 0)) (command "_.Move" Road "" pt1 pt2) ;Selects Field text and moves it to the Road text coordinates (setq Field (ssget "X"'(8."Field")) (setq pt 3 '(0 0 0)) (setq pt 4 '(-3791.4481 0 0)) (command "_.Move" Field "" pt3 pt4) (princ) (princ "Done") )) ; End of condition statement that determines if cancel button has been pressed ) ;end defun Please help as when ever I try to load this program it doesn't work. Kind regards, Mellie Edited August 18, 2014 by SLW210 Code Tags Quote Link to comment Share on other sites More sharing options...
7o7 Posted August 14, 2014 Share Posted August 14, 2014 (edited) You should write : (setq Road (ssget "X" '((8 . "Road")))) (setq pt1 '(0 0 0)) (setq pt2 '(3791.4481 0 0)) and : (setq Field (ssget "X" '((8 . "Field")))) (setq pt3 '(0 0 0)) (setq pt4 '(-3791.4481 0 0)) Edited August 18, 2014 by SLW210 Code Tags Quote Link to comment Share on other sites More sharing options...
SLW210 Posted August 14, 2014 Share Posted August 14, 2014 I moved your thread to the AutoLISP, Visual LISP & DCL Forum. also, please read the Code Posting Guidelines and use Code tags for your Code. Edit----I see you already started another thread, I've merged them. Quote Link to comment Share on other sites More sharing options...
Mellie Posted August 14, 2014 Author Share Posted August 14, 2014 (edited) Okay so I modified my code to the following: (defun C: Melanie () ; define function ;Selects Road text and moves it to the Field text coordinates (setq Road (ssget "X" '((8."Road")))) (setq pt1 '(0 0 0)) (setq pt2 '(3791.4481 0 0)) (command "_.Move" Road "" pt1 pt2)) ;Selects Field text and moves it to the Road text coordinates (setq Field (ssget "X"'((8."Field")))) (setq pt3 '(0 0 0)) (setq pt4 '(-3791.4481 0 0)) (command "_.Move" Field "" pt3 pt4)) (princ) (princ "Done") )) ; End of condition statement that determines if cancel button has been pressed ) ;end defun But I get the following error: Command: (LOAD "C:/Users/patenaude/Desktop/Melanie.LSP") bad DEFUN syntax: (C: MELANIE nil (SETQ ROAD (SSGET "X" (QUOTE (8.0 "Road")))) (SETQ PT1 (QUOTE (0 0 0))) (SETQ PT2 (QUOTE (3791.45 0 0))) (COMMAND "_.Move" ROAD "" PT1 PT2)) What does this mean? Thanks Mellie Edited August 18, 2014 by SLW210 Code Tags Quote Link to comment Share on other sites More sharing options...
7o7 Posted August 14, 2014 Share Posted August 14, 2014 Be careful that there is a space between 8 and . '((8 . "Road")) and also with "Field". Quote Link to comment Share on other sites More sharing options...
Mellie Posted August 14, 2014 Author Share Posted August 14, 2014 How would you make this code select the object automatically. I have a text called Read in its own layer which is also called Read. How would I select that layer and move it to the right by 3100"? I know if you use ssget "X" you could select everything in that layer and move it to the right by 3100 but I'm confused on how to write the program. Please Help. Quote Link to comment Share on other sites More sharing options...
Mellie Posted August 14, 2014 Author Share Posted August 14, 2014 I added the spaces that you mentioned and when I load my program autocad finally recognizes it but when I enter the Melanie Command and press enter, nothing happens. Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted August 14, 2014 Share Posted August 14, 2014 (defun c:movelayer ( / lay p1 p2 ss ) (initget 1) (setq lay (getstring t "\nSpecify layer name : ")) (initget 1) (setq p1 (getpoint "\nPick or specify start point : ")) (initget 1) (setq p2 (getpoint p1 "\nPick or specify end point : ")) (if (tblsearch "LAYER" lay) (if (/= 4 (cdr (assoc 70 (tblsearch "LAYER" lay)))) (progn (setq ss (ssget "_X" (list (cons 8 lay)))) (command "_.move" ss "" p1 p2) ) (alert (strcat "Layer : \"" lay "\" is locked - unable to perform operation...")) ) (alert (strcat "Layer : \"" lay "\" don't exist - unable to perform operation...")) ) (princ) ) HTH, M.R. Quote Link to comment Share on other sites More sharing options...
Commandobill Posted August 14, 2014 Share Posted August 14, 2014 I didn't want to re-write your code, so you could still understand it, but I made a couple of corrections, and it should run just fine. I would personally add some more checks in there to make sure it's doing everything correctly, but this should do for now. I took out pt3 since you already defined 0,0,0. I also fixed your parenthesis. Lastly I put in a check to make sure there was something on that layer so it didn't error out if there wasn't. (defun C:Melanie ( / road pt1 pt2 field pt4) ; define function ;Selects Road text and moves it to the Field text coordinates (setq Road (ssget "X" '((8 . "Road")))) (setq pt1 '(0 0 0)) (setq pt2 '(3791.4481 0 0)) (if road (command "_.Move" Road "" pt1 pt2));make sure there is something on that layer ;Selects Field text and moves it to the Road text coordinates (setq Field (ssget "X"'((8 . "Field")))) (setq pt4 '(-3791.4481 0 0)) (if field (command "_.Move" Field "" pt1 pt4));make sure there is something on that layer (princ "Done") (princ) ) ;end defun Quote Link to comment Share on other sites More sharing options...
Mellie Posted August 14, 2014 Author Share Posted August 14, 2014 Perfect thank you!! The "if" statement is a great idea but what happens if there's nothing in the layer? Could there be a message box that appears that had an "OK" button? How you I go about that? Kind regards Quote Link to comment Share on other sites More sharing options...
Mellie Posted August 14, 2014 Author Share Posted August 14, 2014 That's great thank you but would it be possible to comment your code as I am just starting to understand Lisp and am still a beginner. That would be really appreciated! Kind regards Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 14, 2014 Share Posted August 14, 2014 Consider the following code: ([color=BLUE]defun[/color] c:movetextonlayer ( [color=BLUE]/[/color] sel ) [color=GREEN];; Define function & declare local variables[/color] [color=GREEN];; See http://bit.ly/15Qw104 to understand why.[/color] ([color=BLUE]if[/color] [color=GREEN];; if the following expression returns a non-nil value[/color] ([color=BLUE]setq[/color] sel [color=GREEN];; Assign the return of the following expression to the symbol 'sel'[/color] ([color=BLUE]ssget[/color] [color=GREEN];; Retrieve a selection set[/color] [color=MAROON]"_X"[/color] [color=GREEN];; Iterate over the entire drawing database[/color] [color=GREEN];; Retrieve entities whose DXF data matches the following filter:[/color] '( (0 . [color=MAROON]"TEXT"[/color]) [color=GREEN];; Entity type of TEXT[/color] (8 . [color=MAROON]"Read"[/color]) [color=GREEN];; Entity layer is 'Read'[/color] ) ) [color=GREEN];; end ssget[/color] ) [color=GREEN];; end setq[/color] [color=GREEN];; THEN:[/color] ([color=BLUE]command[/color] [color=GREEN];; Evaluate the following expressions at the command-line[/color] [color=MAROON]"_.move"[/color] [color=GREEN];; Invoke the MOVE command (see http://bit.ly/18cyqA3 for command prefixes)[/color] sel [color=GREEN];; Selection Set to be moved[/color] [color=MAROON]""[/color] [color=GREEN];; 'Enter' to submit selection[/color] [color=MAROON]"_non"[/color] [color=GREEN];; Ignore any active Object Snaps for the next input[/color] '(0.0 0.0) [color=GREEN];; Use a base point of the origin[/color] [color=MAROON]"_non"[/color] [color=GREEN];; Ignore any active Object Snaps for the next input[/color] '(3100.0 0.0) [color=GREEN];; Move text 3100 in the positive x-direction[/color] ) [color=GREEN];; end command[/color] [color=GREEN];; ELSE:[/color] ([color=BLUE]princ[/color] [color=MAROON]"\nNo Text objects found on layer \"Read\"."[/color]) [color=GREEN];; Inform user that no objects were found[/color] ) [color=GREEN];; end if[/color] ([color=BLUE]princ[/color]) [color=GREEN];; Suppress the return of the last evaluated expression[/color] ) [color=GREEN];; end defun[/color] Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 14, 2014 Share Posted August 14, 2014 It seems this question was also asked & answered in this thread: http://www.cadtutor.net/forum/showthread.php?59246-lisp-to-move-objects-over-20in&p=605087&viewfull=1#post605087 @Mod, suggest merging posts with this thread. Quote Link to comment Share on other sites More sharing options...
Mellie Posted August 14, 2014 Author Share Posted August 14, 2014 Thank you very much! Quote Link to comment Share on other sites More sharing options...
Mellie Posted August 18, 2014 Author Share Posted August 18, 2014 (edited) I am trying to write a condition statement for the above code that Commandobill posted. I have this program that when ever you write the command Framing, it brings up a menu with a whole bunch of drop down menus. I am trying to get that piece of code to only occur when certain drawings are selected from a drop down menu in section "equipbotttomval". Is this possible? If so, how would I incorporate this into the following code: (defun C:Melanie ( / road pt1 pt2 field pt4) ; define function ;Selects Road text and moves it to the Field text coordinates (setq Road (ssget "X" '((8 . "Road")))) (setq pt1 '(0 0 0)) (setq pt2 '(3791.4481 0 0)) (if road (command "_.Move" Road "" pt1 pt2));make sure there is something on that layer ;Selects Field text and moves it to the Road text coordinates (setq Field (ssget "X"'((8 . "Field")))) (setq pt4 '(-3791.4481 0 0)) (if field (command "_.Move" Field "" pt1 pt4));make sure there is something on that layer (princ "Done") (princ) ) ;end defun This is what I have so far regarding the condition statement: (cond ((or(= equipbottomval "04-1008035-STD")(= equipbottomval "04-1008077-STD")(= equipbottomval "04-1008156-STD")))) Kind regards Edited August 18, 2014 by Mellie adding a question Quote Link to comment Share on other sites More sharing options...
SLW210 Posted August 18, 2014 Share Posted August 18, 2014 It seems this question was also asked & answered in this thread: http://www.cadtutor.net/forum/showthread.php?59246-lisp-to-move-objects-over-20in&p=605087&viewfull=1#post605087 @Mod, suggest merging posts with this thread. Posts have been merged. Quote Link to comment Share on other sites More sharing options...
Mellie Posted August 18, 2014 Author Share Posted August 18, 2014 I'm not exactly sure where this question has already been answered. Please help! Quote Link to comment Share on other sites More sharing options...
asos2000 Posted August 18, 2014 Share Posted August 18, 2014 Add this part of code at end of LEE code and before (princ)[/code/ [code] (if (< 0 (setq sl (sslength sel))) (setq sl (rtos (sslength sel) 2 0)) (setq sl "No Objects")) (alert (strcat "\nNumber of objects moved on layer \"Read\": " sl " Object(s)")) This will show the number of moved objects? Quote Link to comment Share on other sites More sharing options...
Mellie Posted August 18, 2014 Author Share Posted August 18, 2014 I already have a program that when you type a command it brings up a window with 11 drop down menus. I would like the condition statement to say that when one these specific drawings are selected (04-1008035-STD or 04-1008077-STD or 04-1008156-STD) from the equipbottom drop down, that it prompts the following code: (defun C:road () ; define function ; Calling the road function in the condition statement (cond ((or(= equipbottomval "04-1008035-STD")(= equipbottomval "04-1008077-STD")(= equipbottomval "04-1008156-STD")))) ;Selects Road text and moves it to the Field text coordinates (setq Road (ssget "X" '((8 . "Road")))) (setq pt1 '(0 0 0)) (setq pt2 '(3100 0 0)) (command "_.move" Road "" pt1 pt2) ;Selects Field text and moves it to the Road text coordinates (setq Field (ssget "X" '((8 . "Field")))) (setq pt3 '(0 0 0)) (setq pt4 '(-3100 0 0)) (command "_.move" Field "" pt3 pt4) (Princ "Done") (princ) ) ;End Defun This code needs to run automatically without having to select anything but the OK button on the window. 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.