明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 6321|回复: 24

[源码] Lsp vlx fas程序自动加载程序 支持xp ~win10 32及64位系统

  [复制链接]
发表于 2018-8-24 16:13 | 显示全部楼层 |阅读模式
本帖最后由 言戲無軍 于 2018-8-26 07:08 编辑

本程序用于发布已开发的CAD lsp程序,将你的lsp或vlx fas放到文件夹下,
或者通过inno setup安装后运行文件夹下apploader就能选择加载程序,后期再次运行可卸载
win10 win8 win7 64位系统都需要管理员权限运行
1.二次开发程序很多用秋风的打包程序,但是不开源,有秋枫的印记,很不爽,不便于发布专业的程序。
2.还有通过拖动lsp到CAD窗口加载的,在win10下有些不能拖动加载,而且太不专业。
3.还有一些用的CAD werx(已倒闭)的inst.exe程序,不支持64位系统。
4.用innosetup脚本直接在安装时候选择CAD加载,如果不想加载某个CAD,得重新安装程序,麻烦。



经过多年的开发探索,终于找到比较齐全的方案,本方案支持64位及32位系统以及CAD,便于发布,便于定制自己的自动加载程序。
此程序分别用了C# .net和VB进行开发,容易修改深化。
此方案的最大好处是便于结合innosetup发布程序 ,安装结束【run】字段运行此程序加载
在不同的CAD,后期想更换CAD再次运行程序可卸载更换,不用重新安装
最重要的是完全开源,想怎么改怎么改。

关于inno setup发布CAD二次开发程序 百度即可。

VB源码已公布在本论坛 VB及VBA区。
程序完善后将公布所有源码,许多代码借用了网络资源,在此表示感谢。
目前已知有一个问题,就是首次打开CAD,会自动加载2次lsp,找不到解决办法,求大神改改。
C# net源码
  1. namespace LspLoad._17
  2. {
  3.     using Autodesk.AutoCAD.ApplicationServices;
  4.     using Autodesk.AutoCAD.DatabaseServices;
  5.     using Autodesk.AutoCAD.EditorInput;
  6.     using Autodesk.AutoCAD.Runtime;
  7.     using Autodesk.AutoCAD.Windows;
  8.     //using DotNetARX;
  9.   // using Autodesk.AutoCAD.Interop;
  10.     //using Autodesk.AutoCAD.Interop.Common;
  11.     using System;
  12.     using System.Text;
  13.     //using System.Drawing;
  14.     using System.IO;
  15.     using System.Runtime.InteropServices;
  16.    // using System.Windows.Forms;
  17.     using System.Diagnostics;

  18.     public class ExtApp : IExtensionApplication
  19.     {
  20.       
  21.         [System.Security.SuppressUnmanagedCodeSecurity]
  22.         [DllImport("acad.exe", CharSet = CharSet.Auto,CallingConvention = CallingConvention.Cdecl)]
  23.         extern static private int ads_queueexpr(string strExpr);

  24.       



  25.         public void AppLoad(string ex)
  26.         {
  27.             Document mdiActiveDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  28.             Editor editor = mdiActiveDocument.Editor;
  29.           // AcadApplication app = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
  30.            
  31.             //Application.ShowAlertDialog(ThisNetProperty.Path_LispLocation.ToString());
  32.             if (Directory.Exists(ThisNetProperty.Path_LispLocation))
  33.             {
  34.                
  35.                 try
  36.                 {
  37.                     string[] files = Directory.GetFiles(ThisNetProperty.Path_LispLocation, ex,SearchOption.TopDirectoryOnly);
  38.                     
  39.                     foreach (string str in files)
  40.                     {
  41.                         editor.WriteMessage(str);
  42.                          //editor.Command("(vl-load-all" + ("\"" + str.Replace(@"\", "/") + "\"") + ")");
  43.                         ads_queueexpr("(vl-load-all" + ("\"" + str.Replace(@"\", "/") + "\"") + ")(princ)\n");
  44.                         //Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.SendStringToExecute("(vl-load-all" + ("\"" + str.Replace(@"\", "/") + "\"") + ")\n", true, false, true);
  45.                        // app.ActiveDocument.SendCommand("(vl-load-all" + ("\"" + str.Replace(@"\", "/") + "\"") + ")\n");
  46.                        // app.ActiveDocument.SendCommand("(vl-load-all" + ("\"" + str.Replace(@"\", "/") + "\"") + ")\n");
  47.                        
  48.                     }
  49.                 }
  50.                 catch (Autodesk.AutoCAD.Runtime.Exception exception)
  51.                 {

  52.                     Application.ShowAlertDialog(exception.ToString());
  53.                 }

  54.             }
  55.             
  56.         }
  57.       
  58.         
  59.       

  60.         private void DocumentManager_DocumentCreated(object sender, DocumentCollectionEventArgs e)
  61.         {

  62.            // AppLoad("*.lsp");

  63.             //Application.DocumentManager.DocumentCreated -= new DocumentCollectionEventHandler(DocumentManager_DocumentCreated);
  64.         }

  65.         public void Initialize()
  66.         {
  67.             Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(Autodesk.AutoCAD.ApplicationServices.Application.Version.ToString());
  68.             ThisNetProperty.LoadPath();
  69.             // Application.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(DocumentManager_DocumentCreated);

  70.             //this.LoadEvents();
  71.             //Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  72.             // Application.SetSystemVariable("cmdecho", 0);
  73.             // DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();




  74.             AppLoad("*.lsp");
  75.             AppLoad("*.vlx");
  76.             AppLoad("*.fas");


  77.         }
  78.       
  79.       


  80.         public void LoadEvents()
  81.         {
  82.         }

  83.    


  84.       

  85.         public void Terminate()
  86.         {
  87.         }
  88.     }
  89. }


apploader 源码
有人不知道如何在lsp里面添加支持路径及菜单,引用下秋枫、夜未眠的自动加载lsp,自己修改下,就行了,程序里定义了一个lsp函数
(get_apppath)用于获取 apploader所在路径。
秋枫及夜未眠源码加载菜单及支持路径:
  1. ;;;部分代码转自mjtd
  2. ;;; 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
  3. ;;; 判断是否加载本文件
  4. (if (car (atoms-family 1 '("vl-load-com")))
  5.   (vl-load-com)
  6.   (progn
  7.     (Alert
  8.       "这个程序集是为AutoCAD 2000以及更高的版本设计的,有些功能有可能在没有Visual Lisp for R14支持的AutoCAD R14上不能正确地运行。"
  9.     )
  10.     (exit)        ; 版本不符,退出加载。
  11.   )
  12. )

  13. ;;; 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
  14. ;;; 取得本程序的路径
  15. (defun GetPath (AppID)
  16.   ;;(vl-registry-read
  17.   ; ; (strcat
  18.   ; ;   "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
  19.   ; ;   AppID
  20.   ;;    "_is1"
  21.    ; )
  22.   ;;  "Inno Setup: App Path"
  23. ;; )
  24.   ;;;;(get_apppath) 为apploader自定义的lsp函数,可以获取apploader运行的路径;;;
  25.   (car (get_apppath))

  26. )

  27. (defun GetmylyPath () (GetPath "图层管理中心"))

  28. ;;; 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
  29. ;;; 解析字符串为表
  30. (defun strParse  (Str Delimiter / SearchStr StringLen return n char)
  31.   (setq SearchStr Str)
  32.   (setq StringLen (strlen SearchStr))
  33.   (setq return '())
  34.   (while (> StringLen 0)
  35.     (setq n 1)
  36.     (setq char (substr SearchStr 1 1))
  37.     (while (and (/= char Delimiter) (/= char ""))
  38.       (setq n (1+ n))
  39.       (setq char (substr SearchStr n 1))
  40.     )
  41.     (setq return (cons (substr SearchStr 1 (1- n)) return))
  42.     (setq SearchStr (substr SearchStr (1+ n) StringLen))
  43.     (setq StringLen (strlen SearchStr))
  44.   )
  45.   (reverse return)
  46. )

  47. ;;; 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
  48. ;;; 反解析表为字符串
  49. (defun StrUnParse (Lst Delimiter / return)
  50.   (setq return "")
  51.   (foreach str Lst
  52.     (setq return (strcat return Delimiter str))
  53.   )
  54.   (substr return 2)
  55. )

  56. ;;; 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
  57. ;;; 移除支持文件搜索路径
  58. (defun QF_RemoveSupportPath (PathToRemove / supportlist)
  59.   (setq supportlist (strparse (getenv "ACAD") ";"))
  60.   (setq supportlist (vl-remove "" supportlist))
  61.   (setq  supportlist
  62.    (vl-remove-if
  63.      '(lambda (x) (= (strcase x) (strcase PathToRemove)))
  64.      supportlist
  65.    )
  66.   )
  67.   (setenv "ACAD" (strUnParse supportlist ";"))
  68. )

  69. ;;; 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
  70. ;;; 添加支持文件搜索路径
  71. ;;; 第二个参数如果为真, 插最前,否则插最后

  72. (defun AddSupportPath (PathToAdd isFirst / supportlist)
  73.   (QF_RemoveSupportPath PathToAdd)
  74.   (setq supportlist (strparse (getenv "ACAD") ";"))
  75.   (setq supportlist (vl-remove "" supportlist))
  76.   (if isFirst
  77.     (setq supportlist (cons PathToAdd supportlist))
  78.     (setq supportlist (append supportlist (list PathToAdd)))
  79.   )
  80.   (setenv "ACAD" (strUnParse supportlist ";"))
  81. )

  82. ;;; 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
  83. ;;; 加载菜单
  84. (defun load-mymenu (/ n)
  85.   (if (not (menugroup "mlayer"))
  86.     (progn (setq n 1)
  87.      (while (< n 24)
  88.        (if (menucmd (strcat "P" (itoa n) ".1=?"))
  89.          (setq n (+ n 1))
  90.          (progn (if (> n 3)
  91.       (setq n (- n 2))
  92.       (setq n 3)
  93.           )
  94.           (command "menuload" "tuceng")
  95.           (menucmd (strcat "p" (itoa n) "=+mlayer.pop111"))
  96.           (setq n 25)
  97.          )
  98.        )
  99.      )
  100.     )
  101.   )
  102.   (princ)
  103. )

  104. ;;; 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
  105. ;;; 初始化主函数
  106. (defun Init_mylayer ()
  107.   (if (not (menugroup "mlayer"))  ; 如果菜单组还没有被加载,则加载之
  108.     (progn (AddSupportPath (GetmylyPath) nil) ; 添加支持路径
  109.      (AddSupportPath (strcat (GetmylyPath) "\\LISP") nil)
  110.      (AddSupportPath (strcat (GetmylyPath) "\\LIB") nil)
  111.      (AddSupportPath (strcat (GetmylyPath) "\\BIN") nil)
  112.      (load-mymenu)
  113.     )
  114.   )
  115.   (princ)
  116. )

  117. ;;; 〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
  118. ;;; 主程序:
  119. (princ "\n加载图层管理中心菜单……")

  120. (setq cmdecho_save (getvar "cmdecho"))
  121. (setvar "cmdecho" 0)

  122. ;;; 执行初始化
  123. (Init_mylayer)

  124. (setvar "cmdecho" cmdecho_save)
  125. (setq cmdecho_save nil)

  126. (princ "\n图层管理中心菜单 α版 加载完毕。")
  127. (princ)








本帖子中包含更多资源

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

x

评分

参与人数 3明经币 +3 金钱 +10 收起 理由
BaoWSE + 1 赞一个!
hhh454 + 1 + 10 赞一个!
669423907 + 1 很给力!

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2018-8-25 09:01 | 显示全部楼层

(defun loadmapp()
        (load "D:\\cad\\123.fas")
        (alert "加载程序成功.")
)
(loadmapp)

就是像这样用吗?把要加载的东西放到这里
但是为什么要弹出窗口2次,就像alert运行了2次一次不知道为什么?
发表于 2018-9-30 16:10 | 显示全部楼层
taoyi0727 发表于 2018-8-25 09:01
(defun loadmapp()
        (load "D:\\cad\\123.fas")
        (alert "加载程序成功.")

请问,要手动将插件的路径添加到里面吗,有一百个就要写一百遍吗,那不是也麻烦啊
 楼主| 发表于 2018-8-25 13:18 | 显示全部楼层
taoyi0727 发表于 2018-8-25 09:01
(defun loadmapp()
        (load "D:\\cad\\123.fas")
        (alert "加载程序成功.")

目前就是有这个bug,找不到解决办法,加载程序里不添加窗口提示就好,在.net里加
发表于 2018-8-24 16:19 | 显示全部楼层
关注一波,谢谢楼主
发表于 2018-8-25 08:47 | 显示全部楼层
都是专业的呀!  C# .net VB 啥都有
只会lisp看着都不会用
发表于 2018-8-25 13:22 | 显示全部楼层
不会 只会点lisp 望哪位高手能改改
 楼主| 发表于 2018-8-25 15:54 | 显示全部楼层
taoyi0727 发表于 2018-8-25 13:22
不会 只会点lisp 望哪位高手能改改

你在加载文件里只加载函数和菜单,不要有alert 和princ之类的文字,提示没问题的,即使加载两次用户也不知道,对程序没影响
发表于 2018-8-25 20:17 | 显示全部楼层
试了下 这个不错!想添加一些用户支持搜索路径不知道怎么弄,期待下个版本。
发表于 2018-8-26 23:48 | 显示全部楼层
好东西学习学习!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-19 23:04 , Processed in 4.244667 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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