Jump to content
Sign in to follow this  
chen2j

Pop-up window problem

Recommended Posts

chen2j

I write a scipt Autocad to PDF.au3.when i run it ,it always stoped here when Autocad poped-up a window "Problem". I should manually click "yes",then the script can go on.Why?

ControlCommand("页面设置 - 模型","",1043,"SelectString", '范围') ;设置打印范围为“范围”
ControlCommand("页面设置 - 模型","",1030,"UnCheck","") ;设置按打印样式打印为“否”
ControlCommand("页面设置 - 模型","",1030,"Check","") ;设置按打印样式打印为“是”---防止没有勾上“打印对象线宽”
ControlCommand("页面设置 - 模型","",1053,"Check","") ;勾上“布满图纸”
ControlCommand("页面设置 - 模型","",1006,"SelectString", 'monochrome') ; ---------------It stoped here.

I tryed many method ,the only one it works is to run another scipt in the same time,how can i do it in just one script?

While 1
WinActivate("问题","是(&Y)")
ControlClick("问题","是(&Y)",6)
WEnd

Posted Image

Flickr 上 izaoki55

Edited by Jos

Share this post


Link to post
Share on other sites
water

Welcome to AutoIt and the forum!

Somehow your example code got screwed up :unsure:


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
chen2j

preview is ok.....where can i edit it ? i can't find it

ControlCommand("页面设置 - 模型","",1043,"SelectString", '范围') ;设置打印范围为“范围”
ControlCommand("页面设置 - 模型","",1030,"UnCheck","") ;设置按打印� �式打印为“否”
ControlCommand("页面设置 - 模型","",1030,"Check","") ;设置按打印� �式打印为“是”---防止没有勾上“打印对象线宽”
ControlCommand("页面设置 - 模型","",1053,"Check","") ;勾上“布满图纸”
ControlCommand("页面设置 - 模型","",1006,"SelectString", 'monochrome') ; ---------------It stoped here.

Posted Image

Edited by chen2j

Share this post


Link to post
Share on other sites
water

You can't. You have to have a post count of at least 5 before you can edit a post.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

Can you please translate the error message in the popup to english? Maybe it gives us some more information.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
chen2j

title:Problem

text:Do you want to specify this print style sheet to all layout?

I tryed many method ,the only one it works is to run another scipt in the same time,how can i do it in just one script?

While 1
WinActivate("问题","是(&Y)")
ControlClick("问题","是(&Y)",6)
WEnd

Posted Image

:ILA2: 3Q

Edited by chen2j

Share this post


Link to post
Share on other sites
KaFu

Share this post


Link to post
Share on other sites
water

This window always pops up even when you do all the steps manually?

If yes, then KaFu's suggestion is the way to go.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
chen2j

If you know the "Problem" dialog will pop-up, add a WinWait & ControlClick after your last Controlcommand.

I tried,the scipt just stoped here,waiting for you to click.So,no matter what i write after it ,it dosen't work.when i click "yes" or "no",the scipt gose on. is this a bug?

ControlCommand("页面设置 - 模型","",1053,"Check","")  ;勾上“布满图纸”
ControlCommand("页面设置 - 模型","",1006,"SelectString", 'monochrome')   ; stoped here................
 Sleep(2000)
 WinWait("问题")
 Sleep(2000)
 WinActivate("问题")
 Sleep(2000)
 WinWaitActive("问题")
 Sleep(2000)
 ControlClick("问题","是(&Y)",6)
ControlClick("页面设置 - 模型","",1)   ;关闭页面设置
WinWaitClose("页面设置 - 模型")   ;等待关闭页面设置
ControlClick("页面设置管理器","",2)   ;关闭页面设置管理器
WinWaitClose("页面设置管理器")   ;等待关闭页面设置
WinActivate("AutoCAD 2011","正在重生成模型")

Share this post


Link to post
Share on other sites
chen2j

The complete script

#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_Outfile_x64=cadtopdf.exe
#PRE_Res_requestedExecutionLevel=None
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#Include <Array.au3>
Local $flag
Local $filename,$i
Global $single,$spit
AutoItSetOption("SendKeyDelay",50)
$flag=1  ;图纸为A3则选择flag=1;图纸为A4则选择flag=0
;ShellExecute(@ScriptDir&"wait.au3")
$filename=FileOpenDialog("请选择需要转换的CAD文件","","图形 (*.dwg)",4)  ;弹出选择文件对话框
If @error Then Exit  ;如果没有选择或选择错误,则退出
$spit=StringSplit($filename,"|")   ;分割文件变成数组
If @error Then
 $single=$filename  ;说明选择的是单个文件
 CADtoPDF($single)
Else
  For $i=2 To $spit[0]   ;一个一个的转换PDF,直到结束。
  $single=$spit[1]&""&$spit[$i]
  CADtoPDF($single)
  Next
EndIf
;_ArrayDisplay($spit,"")  ;可以显示数组,做检查用
;AdlibRegister("wenti",500)
Func CADtoPDF($single)   ;自定义函数。
Local $PID=ProcessExists("acad.exe")   ;检测CAD是否已经在运行。
If $PID Then ProcessClose($PID)   ;如果存在则终止进程
ShellExecute($single)  ;运行文件
MouseMove(0,0)
WinWait("AutoCAD 2011","正在重生成模型")  ;等待AutoCAD加载完成
WinActivate("AutoCAD 2011","正在重生成模型")
WinWaitActive("AutoCAD 2011","正在重生成模型")
ControlSend("AutoCAD 2011","",2,"zoom all ")   ;使页面最大化并打开页面设置管理器
ControlSend("AutoCAD 2011","",2,"pagesetup ")   ;使页面最大化并打开页面设置管理器
WinWait("页面设置管理器")   ;暂停直到打开页面设置管理器
ControlSend("页面设置管理器","",4696,"!m")  ;按“ALT+M”
WinWait("页面设置 - 模型")   ;暂停直到打开页面设置 - 模型
ControlCommand("页面设置 - 模型","",1020,"SetCurrentSelection", 4)   ;设置打印机为“Adobe PDF”
If $flag=1 Then
 ControlCommand("页面设置 - 模型","",1040,"SelectString", 'A3')   ;设置图纸尺寸为“A3”
 ControlCommand("页面设置 - 模型","",1037,"Check","")  ;设置图形方形为“横向”,匹配A3
Else
 ControlCommand("页面设置 - 模型","",1040,"SelectString", 'A4')   ;设置图纸尺寸为“A4”
 ControlCommand("页面设置 - 模型","",1036,"Check","")  ;设置图形方形为“纵向”,匹配A4
EndIf
ControlCommand("页面设置 - 模型","",1043,"SelectString", '范围')   ;设置打印范围为“范围”
ControlCommand("页面设置 - 模型","",1030,"UnCheck","")  ;设置按打印样式打印为“否”
ControlCommand("页面设置 - 模型","",1030,"Check","")  ;设置按打印样式打印为“是”---防止没有勾上“打印对象线宽”
ControlCommand("页面设置 - 模型","",1053,"Check","")  ;勾上“布满图纸”
ControlCommand("页面设置 - 模型","",1006,"SelectString", 'monochrome')   ;设置打印样式表为mochrome.ctb-----未解决弹窗问题  

#comments-start
 Sleep(2000)
 WinWait("问题")
 Sleep(2000)
 WinActivate("问题")
 Sleep(2000)
 WinWaitActive("问题")
 Sleep(2000)
 ControlClick("问题","是(&Y)",6)
#comments-end

ControlClick("页面设置 - 模型","",1)   ;关闭页面设置
WinWaitClose("页面设置 - 模型")   ;等待关闭页面设置
ControlClick("页面设置管理器","",2)   ;关闭页面设置管理器
WinWaitClose("页面设置管理器")   ;等待关闭页面设置
WinActivate("AutoCAD 2011","正在重生成模型")
WinWaitActive("AutoCAD 2011","正在重生成模型")
ControlSend("AutoCAD 2011","",2,"^p")   ;打开打印对话框
WinWait("打印 - 模型")   ;暂停直到打开"打印 - 模型"
ControlClick("打印 - 模型","",1)   ;关闭"打印 - 模型"
WinWaitClose("打印 - 模型") 
WinWait("另存 PDF 文件为")   ;暂停直到打开“另存 PDF 文件为”
Sleep(500)
ControlSend("另存 PDF 文件为","",1001,@DesktopCommonDir&""[email="&@YEAR&@MON&@MDAY&@HOUR&@MIN&@SEC"]&@YEAR&@MON&@MDAY&@HOUR&@MIN&@SEC[/email])  ;输入文件名称为日期时间
ControlSend("另存 PDF 文件为","",1,"^s")
;ControlClick("另存 PDF 文件为","",1)   ;关闭“另存 PDF 文件为”
AutoItSetOption("WinTitleMatchMode",2) ;设置标题匹配模式为“任意匹配”
WinWait("Adobe Acrobat Pro")   ;暂停直到打开“Adobe Acrobat Pro”
WinClose("Adobe Acrobat Pro")   ;关闭“Adobe Acrobat Pro”
WinWaitClose("Adobe Acrobat Pro")
ControlSend("AutoCAD 2011","",2,"^s")   ;保存CAD
WinClose("AutoCAD 2011")   ;关闭CAD
WinWaitClose("AutoCAD 2011")
EndFunc
;#comments-start
Func wenti()
 WinActivate("问题","是(&Y)")
 ControlClick("问题","是(&Y)",6)
 
 WinActivate("AutoCAD","是否将改动保存到")
 ControlClick("AutoCAD","是否将改动保存到",6)
 WinActivate("AutoCAD 警告","准备重生成 -- 是否继续?")
 ControlClick("AutoCAD 警告","准备重生成 -- 是否继续?",1)
 
 Sleep(500)
EndFunc
;#comments-end

Share this post


Link to post
Share on other sites
water

Try to determine where your script halts by checking the return value of the called function:

ControlCommand("页面设置 - 模型","",1053,"Check","") ;勾上“布满图纸”
ControlCommand("页面设置 - 模型","",1006,"SelectString", 'monochrome') ; stoped here................
Sleep(2000)
MsgBox(0, "", "Calling WinWait")
$iResult = WinWait("问题")
MsgBox(0, "", "Result of WinWait: " & $iresult)
Sleep(2000)
$iResult =WinActivate("问题")
MsgBox(0, "", "Result of WinActivate: " & $iresult)
Sleep(2000)
$iResult =WinWaitActive("问题")
MsgBox(0, "", "Result of WinWaitActive: " & $iresult)
Sleep(2000)
ControlClick("问题","是(&Y)",6)
ControlClick("页面设置 - 模型","",1) ;关闭页面设置
WinWaitClose("页面设置 - 模型") ;等待关闭页面设置
ControlClick("页面设置管理器","",2) ;关闭页面设置管理器
WinWaitClose("页面设置管理器") ;等待关闭页面设置
WinActivate("AutoCAD 2011","正在重生成模型")


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
KaFu

For debugging write the function response to console to see where exactly the process went wrong.

$hWnd = WinWait("问题","",5)
if not $hWnd then ConsoleWrite("!Error, Window not found")
ConsoleWrite(WinActivate($hWnd) & @crlf)
ConsoleWrite(ControlClick($hWnd,"","[CLASS:Button; INSTANCE:1]") & @crlf)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×