明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: yanshengjiang

[函数] 替代alert的一个方案, 不用关闭弹窗也能继续操作CAD。适用于需要反复观看报告。

  [复制链接]
 楼主| 发表于 昨天 10:25 | 显示全部楼层
本帖最后由 yanshengjiang 于 2025-11-4 10:29 编辑
kozmosovia 发表于 2025-11-4 10:05
这个比较丑,且并不方便,开启后就丧失了对其的控制,只能用户点关掉。
ET有现成的函数
(acet-ui-status  ...

你这个厉害  , 还可以置顶  ,  还可以跨文档。
我这2026安装了ET  第一次报未定义函数。  
我测试了菜单的其他几个ET工具他又不是未知函数了


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
回复 支持 反对

使用道具 举报

发表于 昨天 10:43 | 显示全部楼层
使用前判断加载需要的ARX,不需要调用其他ET命令来加载上
(and (null acet-ui-status)
       (findfile "acetutil.arx")
       (vl-arx-import "acetutil")
  )

点评

acet有progress bar函数,犯不上用ui-status模拟。  发表于 昨天 17:21

评分

参与人数 2明经币 +2 收起 理由
maiko + 1 好像也可以做进度显示
yanshengjiang + 1 跟着云哥学了不少东西了

查看全部评分

回复 支持 反对

使用道具 举报

发表于 昨天 14:58 | 显示全部楼层
本帖最后由 qazxswk 于 2025-11-4 15:01 编辑

这会弹出很多窗口呀,有点碍眼。在弹出窗口后,继续操作下个命令时,就自动关闭那个弹窗,这样会不会好一些?







本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
回复 支持 反对

使用道具 举报

发表于 昨天 16:14 | 显示全部楼层
kozmosovia 发表于 2025-11-4 10:43
使用前判断加载需要的ARX,不需要调用其他ET命令来加载上
(and (null acet-ui-status)
       (findfile  ...

你这个只适用于ACAD吧。楼主的也国产CAD上也能适用。
回复 支持 反对

使用道具 举报

 楼主| 发表于 昨天 17:05 | 显示全部楼层
qazxswk 发表于 2025-11-4 16:14
你这个只适用于ACAD吧。楼主的也国产CAD上也能适用。

这个让我释然了一点点 ,还以为完全白费功夫了
回复 支持 反对

使用道具 举报

 楼主| 发表于 昨天 17:24 | 显示全部楼层
本帖最后由 yanshengjiang 于 2025-11-4 18:08 编辑
qazxswk 发表于 2025-11-4 14:58
这会弹出很多窗口呀,有点碍眼。在弹出窗口后,继续操作下个命令时,就自动关闭那个弹窗,这样会不会好一些 ...

AI一下就搞定,本次弹窗自动关闭上次弹窗。


回复 支持 反对

使用道具 举报

 楼主| 发表于 昨天 18:24 | 显示全部楼层
本来都准备封贴了,AI一下,惊喜更大。
这个支持弹出位置 定时关闭

  1. (defun CreateMessageBox (title msg 是否关闭上次对话框 / tempDir htaPath htaFile fileHandle WshShell Process)
  2.     (if 是否关闭上次对话框
  3.       (CloseLastMessageBox)
  4.     )
  5.     (setq tempDir (getenv "TEMP"))
  6.     (if (not tempDir)
  7.         (setq tempDir "C:\\Temp")
  8.     )
  9.    
  10.     (setq htaPath (strcat tempDir "\\message_box.hta"))
  11.    
  12.     (setq htaFile (open htaPath "w"))
  13.     (if htaFile
  14.         (progn
  15.             ;; 创建HTA文件,支持自定义位置
  16.             (write-line "<html>" htaFile)
  17.             (write-line "<head>" htaFile)
  18.             (write-line "<title>Message Box</title>" htaFile)
  19.             (write-line "<HTA:APPLICATION " htaFile)
  20.             (write-line "  ID=\"MessageBoxApp\"" htaFile)
  21.             (write-line "  APPLICATIONNAME=\"MessageBox\"" htaFile)
  22.             (write-line "  BORDER=\"thin\"" htaFile)
  23.             (write-line "  CAPTION=\"yes\"" htaFile)
  24.             (write-line "  SHOWINTASKBAR=\"yes\"" htaFile)
  25.             (write-line "  SINGLEINSTANCE=\"yes\"" htaFile)
  26.             (write-line "  SYSMENU=\"yes\"" htaFile)
  27.             (write-line "  WINDOWSTATE=\"normal\"" htaFile)
  28.             (write-line "  INNERBORDER=\"no\"" htaFile)
  29.             (write-line "  MAXIMIZEBUTTON=\"no\"" htaFile)
  30.             (write-line "  MINIMIZEBUTTON=\"no\"" htaFile)
  31.             (write-line ">" htaFile)
  32.             (write-line "<script language=\"VBScript\">" htaFile)
  33.             (write-line "Sub Window_OnLoad" htaFile)
  34.             (write-line "  ' 设置窗口大小" htaFile)
  35.             (write-line "  window.resizeTo 500, 200" htaFile)
  36.             (write-line "  ' 获取屏幕尺寸" htaFile)
  37.             (write-line "  screenWidth = window.screen.availWidth" htaFile)
  38.             (write-line "  screenHeight = window.screen.availHeight" htaFile)
  39.             (write-line "  ' 计算右下角位置" htaFile)
  40.             (write-line "  windowX = screenWidth - 420" htaFile)
  41.             (write-line "  windowY = screenHeight - 200" htaFile)
  42.             (write-line "  ' 移动窗口到右下角" htaFile)
  43.             (write-line "  window.moveTo windowX, windowY" htaFile)
  44.             (write-line "  ' 10秒后自动关闭" htaFile)
  45.             (write-line "  idTimer = window.setTimeout(\"vbscript:window.close\", 10000)" htaFile)
  46.             (write-line "End Sub" htaFile)
  47.             (write-line "</script>" htaFile)
  48.             (write-line "</head>" htaFile)
  49.             (write-line "<body style=\"font-family: Arial; font-size: 12px; padding: 10px;\">" htaFile)
  50.             (write-line (strcat "<h3>" title "</h3>") htaFile)
  51.             (write-line (strcat "<p>" msg "</p>") htaFile)
  52.             (write-line "<input type='button' value='确定' onclick='window.close' style='width: 80px;'>" htaFile)
  53.             (write-line "</body>" htaFile)
  54.             (write-line "</html>" htaFile)
  55.             (close htaFile)
  56.             
  57.             ;; 使用WScript.Shell启动HTA
  58.             (setq WshShell (vlax-create-object "WScript.Shell"))
  59.             (setq Process (vlax-invoke WshShell 'Exec (strcat "mshta \"" htaPath "\"")))
  60.             (setq *LastMessageBoxPID* (vlax-get-property Process 'ProcessID))
  61.             
  62.             (vlax-release-object WshShell)
  63.         )
  64.         (progn
  65.             (alert msg)
  66.             nil
  67.         )
  68.     )
  69. )

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 昨天 18:28 | 显示全部楼层
  1. (defun CreateMessageBox (title msg 是否关闭上次对话框 / tempDir psPath psFile fileHandle WshShell Process)
  2.     (if 是否关闭上次对话框
  3.       (CloseLastMessageBox)
  4.     )
  5.     (setq tempDir (getenv "TEMP"))
  6.     (if (not tempDir)
  7.         (setq tempDir "C:\\Temp")
  8.     )
  9.    
  10.     (setq psPath (strcat tempDir "\\message_box.ps1"))
  11.    
  12.     (setq psFile (open psPath "w"))
  13.     (if psFile
  14.         (progn
  15.             ;; 创建PowerShell脚本实现精确定位
  16.             (write-line "Add-Type -AssemblyName System.Windows.Forms" psFile)
  17.             (write-line "[System.Windows.Forms.Application]::EnableVisualStyles()" psFile)
  18.             (write-line "$form = New-Object System.Windows.Forms.Form" psFile)
  19.             (write-line (strcat "$form.Text = "" title """) psFile)
  20.             (write-line "$form.Size = New-Object System.Drawing.Size(300,150)" psFile)
  21.             (write-line "$form.StartPosition = [System.Windows.Forms.FormStartPosition]::Manual" psFile)
  22.             (write-line "$screen = [System.Windows.Forms.Screen]::PrimaryScreen" psFile)
  23.             (write-line "$form.Location = New-Object System.Drawing.Point(($screen.WorkingArea.Width - $form.Width), ($screen.WorkingArea.Height - $form.Height))" psFile)
  24.             (write-line "$form.TopMost = $true" psFile)
  25.             (write-line "$label = New-Object System.Windows.Forms.Label" psFile)
  26.             (write-line "$label.Location = New-Object System.Drawing.Point(10,20)" psFile)
  27.             (write-line "$label.Size = New-Object System.Drawing.Size(260,50)" psFile)
  28.             (write-line (strcat "$label.Text = "" msg """) psFile)
  29.             (write-line "$form.Controls.Add($label)" psFile)
  30.             (write-line "$button = New-Object System.Windows.Forms.Button" psFile)
  31.             (write-line "$button.Location = New-Object System.Drawing.Point(110,80)" psFile)
  32.             (write-line "$button.Size = New-Object System.Drawing.Size(75,23)" psFile)
  33.             (write-line "$button.Text = "确定"" psFile)
  34.             (write-line "$button.DialogResult = [System.Windows.Forms.DialogResult]::OK" psFile)
  35.             (write-line "$form.AcceptButton = $button" psFile)
  36.             (write-line "$form.Controls.Add($button)" psFile)
  37.             (write-line "$timer = New-Object System.Windows.Forms.Timer" psFile)
  38.             (write-line "$timer.Interval = 3000" psFile)
  39.             (write-line "$timer.Add_Tick({$form.Close()})" psFile)
  40.             (write-line "$timer.Start()" psFile)
  41.             (write-line "$result = $form.ShowDialog()" psFile)
  42.             
  43.             (close psFile)
  44.             
  45.             ;; 启动PowerShell进程
  46.             (setq WshShell (vlax-create-object "WScript.Shell"))
  47.             (setq Process (vlax-invoke WshShell 'Exec (strcat "powershell -WindowStyle Hidden -ExecutionPolicy Bypass -File "" psPath """)))
  48.             (setq *LastMessageBoxPID* (vlax-get-property Process 'ProcessID))
  49.             
  50.             (vlax-release-object WshShell)
  51.         )
  52.         (progn
  53.             (alert msg)
  54.             nil
  55.         )
  56.     )
  57. )



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 昨天 18:59 | 显示全部楼层
本帖最后由 yanshengjiang 于 2025-11-4 19:23 编辑

这个最屌。设置位置、定时关闭、跨进程置顶。 可以 结合另外一段代码的关闭进程函数。
  1. ;(CreateMessageBox "自定义标题" "你好,这是一个测试消息223eee3!" T  "5000")  自动关闭时间:毫秒
  2. (defun CreateMessageBox (title msg closeLast closetime / tempDir psPath psFile WshShell Process returnVal)
  3.     (if closeLast
  4.       (CloseLastMessageBox)
  5.     )
  6.     (setq tempDir (getenv "TEMP"))
  7.     (if (not tempDir)
  8.         (setq tempDir "C:\\Temp")
  9.     )
  10.     (setq psPath (strcat tempDir "\\message_box.ps1"))
  11.     (setq psFile (open psPath "w"))
  12.     (if psFile
  13.         (progn
  14.             (write-line "Add-Type -AssemblyName System.Windows.Forms" psFile)
  15.             (write-line "[System.Windows.Forms.Application]::EnableVisualStyles()" psFile)
  16.             (write-line "$form = New-Object System.Windows.Forms.Form" psFile)
  17.             (write-line (strcat "$form.Text = \"" title "\"") psFile)
  18.             (write-line "$form.Size = New-Object System.Drawing.Size(400,150)" psFile)
  19.             (write-line "$form.StartPosition = [System.Windows.Forms.FormStartPosition]::Manual" psFile)
  20.             (write-line "$screen = [System.Windows.Forms.Screen]::PrimaryScreen" psFile)
  21.             (write-line "$form.Location = New-Object System.Drawing.Point(($screen.WorkingArea.Width - $form.Width), ($screen.WorkingArea.Height - $form.Height))" psFile)
  22.             (write-line "$form.TopMost = $true" psFile)
  23.             (write-line "$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog" psFile)
  24.             (write-line "$form.MaximizeBox = $false" psFile)
  25.             (write-line "$form.MinimizeBox = $false" psFile)
  26.             (write-line "$label = New-Object System.Windows.Forms.Label" psFile)
  27.             (write-line "$label.Location = New-Object System.Drawing.Point(10,20)" psFile)
  28.             (write-line "$label.Size = New-Object System.Drawing.Size(360,50)" psFile)
  29.             (write-line (strcat "$label.Text = \"" msg "\"") psFile)
  30.             (write-line "$form.Controls.Add($label)" psFile)
  31.             (write-line "$button = New-Object System.Windows.Forms.Button" psFile)
  32.             (write-line "$button.Location = New-Object System.Drawing.Point(150,80)" psFile)
  33.             (write-line "$button.Size = New-Object System.Drawing.Size(75,23)" psFile)
  34.             (write-line "$button.Text = \"确定\"" psFile)
  35.             (write-line "$button.Add_Click({$form.Close()})" psFile)
  36.             (write-line "$form.Controls.Add($button)" psFile)
  37.             (write-line "$timer = New-Object System.Windows.Forms.Timer" psFile)
  38.             (write-line "$timer.Interval = 10000" psFile)
  39.       (write-line (strcat"$timer.Interval = " closetime) psFile)
  40.             (write-line "$timer.Add_Tick({$form.Close()})" psFile)
  41.             (write-line "$timer.Start()" psFile)
  42.             (write-line "$form.ShowDialog()" psFile)
  43.             (write-line "$timer.Stop()" psFile)
  44.             (write-line "$form.Dispose()" psFile)
  45.             (close psFile)
  46.             (setq WshShell (vlax-create-object "WScript.Shell"))
  47.             (setq Process (vlax-invoke WshShell 'Exec (strcat "powershell -WindowStyle Hidden -ExecutionPolicy Bypass -File \"" psPath "\"")))
  48.             (setq *LastMessageBoxPID* (vlax-get-property Process 'ProcessID))
  49.             (vlax-release-object WshShell)
  50.         )
  51.         (progn
  52.             (alert msg)
  53.         )
  54.     )

  55. )

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
回复 支持 反对

使用道具 举报

发表于 昨天 19:05 | 显示全部楼层
继续研究,还有没有
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-11-5 11:59 , Processed in 0.203934 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表