WashCaps37 Posted March 16, 2005 Posted March 16, 2005 (edited) Please excuse my lack of scripting knowledge for I am new at scripting and just learning. How would I loop the following with a continuous loop? Send("!{TAB}") Send("{CTRLDOWN}") Send("{PGDN}") Send("{CTRLUP}") Send("pagesetup {ENTER}") What I am trying to accomplish is for this to go into AutoCAD, run the pagesetup command then go to the next layout tab and repeat the process until all of the layout tabs have been cycled through. For some wierd reason, AutoCAD won't accept commands through a *.scr or *.lsp file to activate the enter key or ok button in the page setup dialog box so I am trying to perfom the actions that I need done with AutoIt. I have tried the If.....Then with ContinueLoop command, Do...Until with Continue Loop command and While....Until with Continue Loop command and nothing seems to be working. I don't understand what I am missing. Just in case you didn't already know this about AutoCAD, the CTRLDOWN, PGDN, CTRLUP commands allows AutoCAD to go to the next layout. Thanks for your help! Edited March 16, 2005 by WashCaps37
Blue_Drache Posted March 16, 2005 Posted March 16, 2005 (edited) Please excuse my lack of scripting knowledge for I am new at scripting and just learning. How would I loop the following with a continuous loop? Send("!{TAB}")Send("{CTRLDOWN}")Send("{PGDN}")Send("{CTRLUP}")Send("pagesetup {ENTER}")What I am trying to accomplish is for this to go into AutoCAD, run the pagesetup command then go to the next layout tab and repeat the process until all of the layout tabs have been cycled through. I have tried the If.....Then with ContinueLoop command, Do...Until with Continue Loop command and While....Until with Continue Loop command and nothing seems to be working. I don't understand what I am missing. By the way, the CTRLDOWN, PGDN, CTRLUP commands allows AutoCAD to go to the next layout.Thanks for your help!<{POST_SNAPBACK}>Depends on the number of tabs. Let's say there's 20 tabs.The best way would then be a FOR/NEXTFor $x = 1 to 20 step 1 Send("!{TAB}^{PGDN}",0) Send("pagesetup {ENTER}") NextContinueLoop is only for skipping steps...Let's say you wanted to skip step 15 (for whatever reason)For $x = 1 to 20 step 1 If $x = 15 then ContinueLoop Send("!{TAB}^{PGDN}",0) Send("pagesetup {ENTER}") NextThe loop goes back to the top when $x = 15.If you wanted to break out at a certian condition in an infinate While/WEnd loop, use ExitLoopDim $x = 0 While 1; Infinate Loop Sleep(10) $x = $x + 1 Send("!{TAB}^{PGDN}",0) Send("pagesetup {ENTER}") If $x = 20 then ExitLoop WEndEdit: Condensed code. Edited March 16, 2005 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
WashCaps37 Posted March 16, 2005 Author Posted March 16, 2005 Please excuse my lack of scripting knowledge for I am new at scripting and just learning. How would I loop the following with a continuous loop? Send("!{TAB}")Send("{CTRLDOWN}")Send("{PGDN}")Send("{CTRLUP}")Send("pagesetup {ENTER}")What I am trying to accomplish is for this to go into AutoCAD, run the pagesetup command then go to the next layout tab and repeat the process until all of the layout tabs have been cycled through. For some wierd reason, AutoCAD won't accept commands through a *.scr or *.lsp file to activate the enter key or ok button in the page setup dialog box so I am trying to perfom the actions that I need done with AutoIt.I have tried the If.....Then with ContinueLoop command, Do...Until with Continue Loop command and While....Until with Continue Loop command and nothing seems to be working. I don't understand what I am missing. Just in case you didn't already know this about AutoCAD, the CTRLDOWN, PGDN, CTRLUP commands allows AutoCAD to go to the next layout.Thanks for your help!<{POST_SNAPBACK}>
WashCaps37 Posted March 16, 2005 Author Posted March 16, 2005 Blue_Drache, Thank you so much for your help! I tried your suggestions and got it to work. I had been racking my brain trying to figure it out. I was trying to learn from the help files and the online documentation. I really do appreciate you taking the time to help me out. Your explainations make understanding looping a lot easier. Thanks again!!!!!!
WashCaps37 Posted March 16, 2005 Author Posted March 16, 2005 Blue_Drache, Just brainstorming here, Is there a way to prompt the user at the beginning of the script for the amount of layouts? that way the program knows how many layouts there are? or would that be asking too much for AutoIt to do? especially if the script will be turned into an exe file.
WashCaps37 Posted March 16, 2005 Author Posted March 16, 2005 (edited) I think of an example of a layout is pretty much like a page in a book. I have a book (drawing file) and it contains many pages (layouts). Layouts pretty much contain a Title Block with all the information regarding the drawing (i.e. Drawing Name, Number, Company Logo, Company Address & Phone Number, etc.) and within that Title Block there may be a Viewport which displays the actual drawing. Hope that helps. Edited March 16, 2005 by WashCaps37
Blue_Drache Posted March 16, 2005 Posted March 16, 2005 (edited) I think of an example of a layout is pretty much like a page in a book. I have a book (drawing file) and it contains many pages (layouts). Layouts pretty much contain a Title Block with all the information regarding the drawing (i.e. Drawing Name, Number, Company Logo, Company Address & Phone Number, etc.) and within that Title Block there may be a Viewport which displays the actual drawing. Hope that helps.<{POST_SNAPBACK}>Do $x = InputBox("Question","How many Layouts are there?") If @error = 1 then ExitLoop; cancel was pressed Until StringIsDigit($x) And $x > 0; keep looping until we get a numerical answer greater than zero. If $x >= 1 then For $loop = 1 to $x ; put code here Next EndIf Edited March 16, 2005 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
phillip123adams Posted March 17, 2005 Posted March 17, 2005 Just brainstorming here, Is there a way to prompt the user at the beginning of the script for the amount of layouts? that way the program knows how many layouts there are? or would that be asking too much for AutoIt to do? especially if the script will be turned into an exe file.<{POST_SNAPBACK}>WashCaps37,You can get AutoCAD to tell you how many layouts are in the drawing. The AutoLisp function "LayoutList" returns a list of layouts in the current drawing. For example:(layoutlist)might return("Layout1" "Layout2" "MyLayout" "TopView")and (Length (LayoutList)) would return 4.I'm trying to understand the sequence of keystrokes in your Send functions. Are you in the Model mode and at the AutoCAD command line when they are issued? When I press Alt+TAB, the windows selection window appears. And Ctrl+PageUp and Ctrl+PageDn seem to do nothing. Can you help me out here? What am I doing wrong? What version of AutoCAD?This won't help with opening the AutoCAD 2000/2002 PageSetup dialog to a particular tab (I don't know why), but it does work for the AutoCAD 2000/2002 Options dialog. Since it is little known, I thought I would mention it. The Options dialog can be opened on a particular tab by prefixing the command with a plus sign, and including an integer option to signify the desired tab (zero based). For example, via AutoLisp:(command "+Options" 0); opens on Files tab (command "+Options" 3); opens on Plotting tab Phillip
phillip123adams Posted March 17, 2005 Posted March 17, 2005 What I am trying to accomplish is for this to go into AutoCAD, run the pagesetup command then go to the next layout tab and repeat the process until all of the layout tabs have been cycled through. <{POST_SNAPBACK}>WashCaps37,If I understand what you are attempting to do, the following AutoLisp program should do the trick. The first part just creates a few layouts, for demonstration and testing purposes, without setting their page properties. The second part is what you want.(progn ; Create a bunch of layouts for demonstration and testing purposes. (foreach xx1 (list "Top" "Left" "Front" "Right" "Bottom" "3D") (command ".layout" "n" xx1) );_ foreach );_ progn(progn ; Walk through all Layouts. Just opening the tab via AutoLisp ; appears to cause the page setup to default to the last setup. (setq LayoutList1 (layoutlist)) (foreach xx1 LayoutList1 ; Make the next layout current. (command ".layout" "s" xx1) );_ foreach );_ progn Phillip
WashCaps37 Posted March 17, 2005 Author Posted March 17, 2005 Blue_Drache, I finally had some time to try the rest of the code. It works great! You are awesome! I can't thank you enough. I am starting to understand this a little more. It just takes time.........which everyone seems to have little of these days. The reason I wanted to have something like this is because there is an Existing bug within the page setups in AutoCAD 2004 and this helps me to work around it, especially when there are hundreds of layouts per drawing file. Do you have any AutoCAD experience? It seems to me that the AutoIt online documentation is not very clear at times. Are there any books/ebooks or online websites that makes this coding a little easier to understand? Thanks again for all your help! WashCaps37
WashCaps37 Posted March 17, 2005 Author Posted March 17, 2005 Oh, this is the final code if anyone should need it. Do $x = InputBox("Question","How many Layout Tabs are there? Including the Model Space Tab") If @error = 1 then ExitLoop; cancel was pressed Until StringIsDigit($x) And $x > 0; keep looping until we get a numerical answer greater than zero. If $x >= 1 then For $loop = 1 to $x Send("!{TAB}^{PGDN}",0) Send("pagesetup {ENTER}") Next EndIf
WashCaps37 Posted March 17, 2005 Author Posted March 17, 2005 phillip123adams, Thank you for your help! I am currently using AutoCAD 2004. There is a known existing bug in 2004 that after a user imports a page setup (via pagesetupin) and sets the current page setup for all the layout tabs that the drawing (in my case the Title Block) is not centered on the page (layout), even if the Plot Offset checkbox to center the plot is checked. To solve this problem the user then has to go through each layout tab, type in pagesetup on the command line and either click the 'OK' button or even simpler just hit the the 'Enter' key. It gets pretty boring and cumbersome when, and if, there are hundreds of layout tabs. I have tried to solve this problem through Scripts and Lisps but for some reason I could never get the Script or Lisp to simulate either the 'OK' button or 'Enter' key while in the page setup dialog box. Supposedly Autodesk solved the Plot Offset to center issue in the 2005 release but the company I work for won't upgrade. Anyway, thanks to Blue_Drache's help I am able to work around the issue. My hats off to all of you programmers. I have a lot to learn.
Blue_Drache Posted March 17, 2005 Posted March 17, 2005 Blue_Drache,<...>Do you have any AutoCAD experience? <...>WashCaps37<{POST_SNAPBACK}>Not so much AutoCAD, but I know the concepts of CAD/CAM software. My main experience lies in the SmartCAM package of software and building G code for CNC Routers. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
WashCaps37 Posted March 17, 2005 Author Posted March 17, 2005 (edited) Oh, this is the final code if anyone should need it.Do $x = InputBox("Question","How many Layout Tabs are there? Including the Model Space Tab") If @error = 1 then ExitLoop; cancel was pressedUntil StringIsDigit($x) And $x > 0; keep looping until we get a numerical answer greater than zero.If $x >= 1 then For $loop = 1 to $x Send("!{TAB}^{PGDN}",0) Send("pagesetup {ENTER}") NextEndIf<{POST_SNAPBACK}>I am running into a slight snag when I compile this as a *.exe file. The snag is....say I have 3 layout tabs in a drawing (this includes the Model Tab) I have to insert the number "4" when Prompted for the amount of Layout Tabs in order for the 'pagesetup' and 'Enter' to work on the last layout tab. So it looks like I need to figure out how I can have the program automatically add 1 to the amount the user inputs at the Prompt or I need to figure out why this code is acting the way it is. Edited March 17, 2005 by WashCaps37
Blue_Drache Posted March 17, 2005 Posted March 17, 2005 I am running into a slight snag when I compile this as a *.exe file. The snag is....say I have 3 layout tabs in a drawing (this includes the Model Tab) I have to insert the number "4" when Prompted for the amount of Layout Tabs in order for the 'pagesetup' and 'Enter' to work on the last layout tab. So it looks like I need to figure out how I can have the program automatically add 1 to the amount the user inputs at the Prompt or I need to figure out why this code is acting the way it is.<{POST_SNAPBACK}>Simply add an $x = $x + 1 to the code inside the IF. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
WashCaps37 Posted March 17, 2005 Author Posted March 17, 2005 (edited) Simply add an $x = $x + 1 to the code inside the IF.<{POST_SNAPBACK}>So far so good. Runs great! At first I was thinking the $x = $x + 1 goes within the the second If but after testing and re-testing I eventually figured it out. Much appreciated!Here is the final code. Do $x = InputBox("Question","How many Layout Tabs are there?Include Model Tab") If @error = 1 then ExitLoop; cancel was pressed $x = $x + 1Until StringIsDigit($x) And $x > 0; keep looping until we get a numerical answer greater than zero. If $x >= 1 then For $loop = 1 to $x Send("!{TAB}^{PGDN}",0) Send("pagesetup {ENTER}") NextEndIf Edited March 17, 2005 by WashCaps37
Blue_Drache Posted March 17, 2005 Posted March 17, 2005 Do $x = InputBox("Question","How many Layout Tabs are there?Include Model Tab") If @error = 1 then ExitLoop; cancel was pressed $x = $x + 1 Until StringIsDigit($x) And $x > 0; keep looping until we get a numerical answer greater than zero. If $x >= 1 then For $loop = 1 to $x Send("!{TAB}^{PGDN}",0) Send("pagesetup {ENTER}") Next EndIf<{POST_SNAPBACK}>I would have put it inside the IF statement....because the way you have it, X will ALWAYS be one and the IF may be executed. It's up to you though if that code works just fine...so be it.<...> If $x >= 1 then $x = $x + 1 For $loop = 1 to $x <...> Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
WashCaps37 Posted March 18, 2005 Author Posted March 18, 2005 (edited) Edited March 18, 2005 by WashCaps37
Blue_Drache Posted March 18, 2005 Posted March 18, 2005 (edited) I am trying to incorporate more commands once I am in the pagesetup. For example, once I am on the pagesetup screen I would like to do an Alt x and an Alt c before hitting the Enter key. The Alt x and Alt c check an "Extents" checkbox or actually a check circle and Alt c puts a check in a center plot checkbox. If I run *.au3 file with just these commands and it wil work.Did you want X and C or X and Y? Getting your variables mixed up with your cartiesian coordinates?Anyway.... There should be no reason why these shouldn't work. You must make sure that the AutoCAD window is active before sending anything.Try putting a WinActivate() command just before the send, and try condensing.... you don't have to write each command one per line.Send("pagesetup!x!c{enter}",0) is perfectly valid, providing you're sending it to the correct window. Also, check your send-key delay. AutoIt may be sending too fast for the program to pick up the strokes. Increase the delay between keystrokes with Opt("SendKeyDelay",100). This will put a hefty delay in (100 ms) inbetween each keystroke, so it may appear sluggish.Remember, when sending in mode zero: ! = alt ^ = ctrl + = shift # = Windows Key Check out the "Send Key List" in the help file. Edited March 18, 2005 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now