├── img ├── include.png ├── application-load.png ├── project-window.png ├── vscode-include.png ├── vscode-load-file.png ├── ._application-load.png ├── application-create.png ├── application-files.png ├── ._application-create.png ├── ._application-files.png ├── ._application-include.png ├── ._application-options.png ├── application-acaddoc.png ├── application-files_jpn.png ├── application-include.png ├── application-load_jpn.png ├── application-options.png ├── application-resource.png ├── ._application-files_jpn.png ├── ._application-load_jpn.png ├── ._application-resource.png ├── application-create_jpn.png ├── application-options_jpn.png ├── ._application-create_jpn.png ├── ._application-options_jpn.png ├── ._application-resource_jpn.png └── application-resource_jpn.png ├── LICENSE ├── include.lsp ├── README_JPN.md ├── README.md └── include-lib.LSP /img/include.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/include.png -------------------------------------------------------------------------------- /img/application-load.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/application-load.png -------------------------------------------------------------------------------- /img/project-window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/project-window.png -------------------------------------------------------------------------------- /img/vscode-include.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/vscode-include.png -------------------------------------------------------------------------------- /img/vscode-load-file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/vscode-load-file.png -------------------------------------------------------------------------------- /img/._application-load.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/._application-load.png -------------------------------------------------------------------------------- /img/application-create.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/application-create.png -------------------------------------------------------------------------------- /img/application-files.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/application-files.png -------------------------------------------------------------------------------- /img/._application-create.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/._application-create.png -------------------------------------------------------------------------------- /img/._application-files.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/._application-files.png -------------------------------------------------------------------------------- /img/._application-include.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/._application-include.png -------------------------------------------------------------------------------- /img/._application-options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/._application-options.png -------------------------------------------------------------------------------- /img/application-acaddoc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/application-acaddoc.png -------------------------------------------------------------------------------- /img/application-files_jpn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/application-files_jpn.png -------------------------------------------------------------------------------- /img/application-include.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/application-include.png -------------------------------------------------------------------------------- /img/application-load_jpn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/application-load_jpn.png -------------------------------------------------------------------------------- /img/application-options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/application-options.png -------------------------------------------------------------------------------- /img/application-resource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/application-resource.png -------------------------------------------------------------------------------- /img/._application-files_jpn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/._application-files_jpn.png -------------------------------------------------------------------------------- /img/._application-load_jpn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/._application-load_jpn.png -------------------------------------------------------------------------------- /img/._application-resource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/._application-resource.png -------------------------------------------------------------------------------- /img/application-create_jpn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/application-create_jpn.png -------------------------------------------------------------------------------- /img/application-options_jpn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/application-options_jpn.png -------------------------------------------------------------------------------- /img/._application-create_jpn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/._application-create_jpn.png -------------------------------------------------------------------------------- /img/._application-options_jpn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/._application-options_jpn.png -------------------------------------------------------------------------------- /img/._application-resource_jpn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/._application-resource_jpn.png -------------------------------------------------------------------------------- /img/application-resource_jpn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manualChair/include/HEAD/img/application-resource_jpn.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Manual Chair Japan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /include.lsp: -------------------------------------------------------------------------------- 1 | ;;;===================================================================== 2 | ;;; Please register this file at the top of youe project files in 3 | ;;; Visual LISP, when you make Separate-namespace VLX Application. 4 | ;;; If you are using Visual Studio Code with AutoCAD 2021 or later, 5 | ;;; make sure it loads before your project's files. 6 | ;;; The functions described in this file are a companion to the 7 | ;;; functions described in include-lib.LSP and will only work if loaded 8 | ;;; in Separate-namespace. 9 | ;;; Please see also include-lib.LSP 10 | ;;;===================================================================== 11 | ;;; (include 'function filename) 12 | ;;;--------------------------------------------------------------------- 13 | ;;; function : symbol 14 | ;;; filename : string 15 | ;;;--------------------------------------------------------------------- 16 | ;;; If no function is defined, the file will be loaded in Separate- 17 | ;;; namespace VLX Application. 18 | ;;;===================================================================== 19 | ;;; NOTE 20 | ;;; In its Separate-namespace, the load-file and resource-file 21 | ;;; functions will have no effect. 22 | ;;;===================================================================== 23 | 24 | ;;; +------------------------------------------------------------------+ 25 | ;;; Copyright (c) 2020 manual chair japan 26 | ;;; Released under the MIT license 27 | ;;; https://opensource.org/licenses/mit-license.php 28 | ;;; +------------------------------------------------------------------+ 29 | 30 | (if (null *DrawingLevelEnviromet*) 31 | (setq *include:stack* nil 32 | include (lambda ($_include:symbol $_include:resource / 33 | $_filename-base 34 | ) 35 | (if 36 | (and (not (boundp $_include:symbol)) 37 | (null 38 | (member 39 | (setq $_filename-base (vl-filename-base 40 | $_include:resource 41 | ) 42 | ) 43 | *include:stack* 44 | ) 45 | ) 46 | ) 47 | (progn 48 | (setq *include:stack* (cons $_filename-base 49 | *include:stack* 50 | ) 51 | ) 52 | (load $_filename-base 53 | '(princ 54 | (strcat 55 | "\n; Resource Load Error : " 56 | $_filename-base 57 | ) 58 | ) 59 | ) 60 | (setq *include:stack* (cdr *include:stack*)) 61 | $_include:symbol 62 | ) 63 | ) 64 | ) 65 | load-file (lambda (filename) nil) 66 | resource-file (lambda (filename) nil) 67 | ) 68 | ) -------------------------------------------------------------------------------- /README_JPN.md: -------------------------------------------------------------------------------- 1 | # include 2 | 3 | ![Visual LISP IDE における AutoLISP のためのライブラリシステム](img/include.png) 4 | 5 | # 概要 6 | 7 | このライブラリシステムは include 関数を代表とするいくつかの関数で構成され、AutoLISP の開発環境において必要な外部関数のファイルをロードする仕組み等を提供します。そしてロードした関数のリストを Visual LISP のプロジェクトファイルや【VLX アプリケーション】の定義ファイルとして作成することができます。これらを使って【VLX アプリケーション】を作成するのが最終的な目的です。 8 | 9 | AutoLISP には load 関数があり、他のファイルから必要な関数をロードすることができます。しかしそれは単純な動作のため、常にロードされるファイルを把握しておかなければなりません。そのため、必要な関数を効率よく自動でロードするライブラリのようなシステムを元々の AutoLISP 実行環境では利用できません。ここでは、load 関数を拡張した include 関数を定義してライブラリシステムを構築します。include 関数と load 関数との主要な違いは、既にロードしたファイルは記憶しておいて不要なロードは行いません。 10 | 11 | include 関数を前提とした既存のライブラリに加えて、あなたの作った再利用性の高い独自の関数を、今書いているプログラムとは別のフォルダに同じ要領で整理することで、あなた自身のライブラリを作っていくことができます。 12 | 13 | include 関数を使用すると自動で関数がロードされる一方で、どの関数がロードの対象になるのか把握することは困難になります。そのためプログラムの開発に使った AutoLISP 実行環境以外の他で利用することは困難になります。このことから最終的にあなたの書いたプログラムと必要なライブラリの関数を合わせて一つの【独自の名前空間 VLX アプリケーション】として仕上げることが必要になります。【独自の名前空間 VLX アプリケーション】とすることで、一つのファイルで扱いやすく、他の AutoCAD ユーザーの AutoLISP 実行環境においても干渉せずに動作するプログラムとすることができます。 14 | 15 | include 関数がロードして記憶しておいた関数のファイルのリストを Visual LISP のプロジェクトファイルの形式に書き出すことができます。これは、あなたのプログラムを【独自の名前空間 VLX アプリケーション】として仕上げる際にアプリケーション定義ファイルのリソースとして使用できます。また、Visual LISP のプロジェクトが使えない Visual Studio Code の開発環境用には、直接【VLX アプリケーション】の定義ファイルを作成することもできます。そのために include 関数に加えて load-file 関数と resource-file 関数を使って少しの手間が必要です。これは Visual LISP でアプリケーション定義ファイルを手動で編集していたのに対応するものです。 16 | 17 | # ライセンスについて 18 | 19 | 本関数のソースコードについては、MIT ライセンスとします。MIT ライセンスはオープンソースソフトウェアのライセンスの一つで、制約が少ししかないものです。 20 | 21 | MIT ライセンスのあらましを本件にあわせて意訳すると以下の通りです。 22 | * 無保証です! 23 | * 本関数のソースコードは誰でも無料で使用できます。商用を含めて、自由にソースコードの配布や変更を行うこと、これ使ったプログラムの作成ができます。 24 | * 本関数のソースコードの再配布や変更を行う場合、これらに既に含まれている下記の著作権表示は消してはいけません。また、この関数を使用して作成したあなたのプログラムを配布しようとするときの著作権表示には、同じく下記の著作権表示の三行を、同梱するライセンス表示用の別ファイルなど適当な、しかし確認できるところに明示してください。 25 | ``` 26 | Copyright (c) 20xx manual chair japan 27 | Released under the MIT license 28 | https://opensource.org/licenses/mit-license.php 29 | ``` 30 | 31 | # ライブラリシステムの事前準備 32 | 33 | ## サポートファイルの検索パスの設定 34 | 35 | 1. AutoCAD の【サポートファイルの検索パス】の設定をする。 36 | 37 | ライブラリへのパスの設定を行います。include 関数を前提とした他から入手したライブラリやあなたが独自に作ろうとしているライブラリを置くフォルダは、あなたが好きなところに置くことができます。しかしそこまでのパスは AutoCAD の【サポートファイルの検索パス】の設定を行ってください。この設定は、AutoCAD の OPTIONS コマンドで表示されるダイアログの【ファイル】タブから設定できます。 38 | 39 | ![setting-support-file](img/application-files_jpn.png) 40 | 41 | AutoCAD のバージョンによっては【信頼できるフォルダ】に該当のフォルダを含める設定を行ってください。 42 | 43 | ## include 関数やその他関数の定義 44 | 45 | 2. AutoCAD の AutoLISP 開発環境に include 関数をロードして使用可能にする。 46 | 47 | include 関数はライブラリから関数をロードします。この関数は **include-lib.LSP** ファイルを acaddoc.LSP などから前もって開発環境にロードしておきます。 48 | 49 | ![setting-accaddoc](img/application-acaddoc.png) 50 | 51 | このファイルをロードすると、include 関数やこの関数を使ってロードしたファイルの一覧を書き出す関数など一連の関数が定義されます。また、グローバル変数 \*DrawingLevelEnviromet\* が T にセットされます。 52 | 53 | 以上でライブラリシステムの設定は終わりです。以降はプログラム開発過程の手順を説明します。手順はVisual Studio Code を使っている(CASE 1)か、 Visual LISP を使っている(CASE 2)かで二通りに分かれます。Visual LISP の場合は以降のプログラムの開発作業はプロジェクト機能を使って行った方がスムーズで、これを使用している前提で説明します。 54 | 55 | # 使用法 - CASE 1 : Visual Studio Code 開発環境の場合 56 | 57 | Visual Studio Code 開発環境の場合としていますが、プロジェクトファイルを使わない方法であり Visual LISP でも可能です。 58 | 59 | Visual LISP のプロジェクトが使えない Visual Studio Code の開発環境用には、直接【VLX アプリケーション】の定義ファイルを自動で作成します。そのために load-file 関数と resource-file 関数を使った少しの手間が必要です。これは Visual LISP でアプリケーション定義ファイルを手動で編集するものに対応するものです。 60 | 61 | ## STEP 1 - プログラムを開発する 62 | 63 | ### プロジェクトロード用 LISP ファイルの用意 64 | 65 | 1. load-file 関数と resource-file 関数を使用してプロジェクトロード用の LISP ファイルを用意する。 66 | 67 | Visual LISP のプロジェクトに対応するロード用の LISP プログラムを用意します。ここにはあなたのプロジェクトの複数のプログラムファイルを一式ロードするコードを記述しますが、load 関数ではなく load-file 関数を使用して書いておきます。 68 | 69 | ```lisp 70 | (load-file "./project/DrawTools") 71 | ``` 72 | 73 | load-file 関数はファイル名を表す文字列の引数を一つ受け取り load 関数と同じように呼び出された時点で LISP のプログラムファイルをロードしますが、ロードしたファイルを記憶しています。これはアプリケーション定義ファイルを出力する際に使用されます。load 関数と同じくファイルの拡張子は不要です。 74 | 75 | LISP のプログラムファイル以外で、プログラムが DCL ファイルや TXT ファイルを使用していて最終の【VLX アプリケーション】にリソースとして含めるものは resource-file 関数を使用します。 76 | 77 | ```lisp 78 | (resource-file "./resource/data.txt") 79 | ``` 80 | 81 | この関数はファイル名を表す文字列の引数を一つ受け取り、呼び出された時点ではファイルの記録のみを行いあなたのプログラムの実行とは直接関係しません。記録されたファイルはアプリケーション定義ファイルに出力されます。resource-file 関数で指定するリソースはファイルの拡張子を含めて指定してください。この宣言はプロジェクトロード用ファイルに記述するか、そこからロードされるファイルのいずれかに記述しておきます。 82 | 83 | ### 独自の名前空間 VLX アプリケーション用の include 関数 84 | 85 | 2. プロジェクトロード用ファイルの先頭に【独自の名前空間 VLX アプリケーション】用の include 関数を load-file 関数で登録する。 86 | 87 | あなたのプログラムを最終的に【独自の名前空間 VLX アプリケーション】として仕上げた場合、ライブラリの関数はリソース内から実行コードがロードされます。この際は、開発時に使用していた include 関数とは別のリソースをターゲットにした内容が定義された include 関数を使用するようにします。この関数は **include.lsp** に定義されています。 88 | 89 | このファイルは、プロジェクトロード用ファイルの先頭に登録しておき【独自の名前空間 VLX アプリケーション】に含まれるようにします。このファイルの include 関数はロードされても \*DrawingLevelEnviromet\* が T の間は定義がスキップされ、【独自の名前空間 VLX アプリケーション】内でのみ活性化します。 90 | 91 | ![vscode-load-file](img/vscode-load-file.png) 92 | 93 | ### include ステートメント 94 | 95 | 3. 必要なライブラリ関数の include ステートメントを、あなたのプログラムに書いておく。 96 | 4. Visual Studio Code から AutoCAD に接続しプロジェクトロード用ファイルを使ってファイルのロードを行う。 97 | 5. テストを繰り返して、あなたのプログラムを完成させる。 98 | 99 | プロジェクトのファイル内で include 関数を使って適時ライブラリの関数をロードしながら、あなたのプログラムを完成させてください。Visual Studio Code からは最初に作ったプロジェクトロード用ファイルを指定して AutoCAD と接続すれば、プロジェクトのファイル一式をロードすることができます。 100 | 101 | あなたのプログラムには次のようなステートメントを記述するとライブラリの関数が書かれたファイルが必要に応じてライブラリからロードされるようになります。 102 | 103 | ```lisp 104 | (include 'default "./common/default") 105 | ``` 106 | 107 | include 関数の最初の引数が必要な関数の関数名、第二引数は関数が定義されたファイル名を表します。上の例の場合は、default 関数が定義されていなければ、"./common/default" ファイルをロードせよ、という意味になります。ファイル名は、AutoCADの【サポートファイルの検索パス】からの相対パスで記述されています。 108 | 109 | ![vscode-include](img/vscode-include.png) 110 | 111 | ## STEP 2 - 独自の名前空間 VLX アプリケーションの作成 112 | 113 | ### アプリケーション定義ファイルの出力 114 | 115 | 1. createPRV 関数を使って、アプリケーション定義ファイルを書き出す。 116 | 117 | あなたのプログラムが完成したら、createPRV 関数を使って【独自の名前空間 VLX アプリケーション】の作成に向けてアプリケーション定義ファイルを書きだします。この作業は開発過程で include 関数、load-file 関数そして resource-file 関数が記憶したものを書き出すものですから、試行錯誤の間に不要なファイルが登録されているかもしれません。そのため、一度 AutoLISP 実行環境をリセットしてから改めてあなたのプログラムをロードして、不要なものが含まれていない状態で行ってください。createPRV 関数を【コンソール】から実行するとファイルを保存するダイアログが出るので、ファイル名を指定して保存を行ってください。 118 | 119 | ```lisp 120 | > (createPRV nil nil) ⏎ 121 | 122 | ; An application make file has been created. 123 | ; F:\VisualLISP\project\DrawTools\DrawTools.prv 124 | ``` 125 | createPRV 関数には二つの引数があります。一つ目は一時ファイルフォルダを文字列で指定します。nil を指定した場合は "temp" となります。二つ目の引数は【VLX アプリケーション】の出力先のフォルダを指定します。nil の場合はアプリケーション定義ファイルと同じ場所に作成されます。 126 | 127 | ### VLX アプリケーションの作成 128 | 129 | 2. AutoCAD のコマンド MAKELISPAPP から【VLX アプリケーション】を作成する。 130 | 131 | 出力されたアプリケーション定義ファイルの内容に、あなたのプロジェクトファイルやリソースファイルが含まれているか一通り確認してください。 132 | 133 | AutoCAD のコマンド MAKELISPAPP からこのアプリケーション定義ファイルを指定して【VLX アプリケーション】を作成してください。 134 | 135 | 再度 AutoLISP 実行環境をリセットしてから、作成された【VLX アプリケーション】をロードしてきちんと動作するかテストしてください。 136 | 137 | # 使用法 - CASE 2 : Visual LISP 開発環境の場合 138 | 139 | ## STEP 1 - プログラムを開発する 140 | 141 | ### 独自の名前空間 VLX アプリケーション用の include 関数 142 | 143 | 1. あなたのプロジェクトの先頭に【独自の名前空間 VLX アプリケーション】用の include 関数を登録する。 144 | 145 | あなたのプログラムを最終的に【独自の名前空間 VLX アプリケーション】として仕上げた場合、ライブラリの関数はリソース内から実行コードがロードされます。この際は、開発時に使用していた include 関数とは別のリソースをターゲットにした内容が定義された include 関数を使用するようにします。この関数は **include.lsp** に定義されています。 146 | 147 | このファイルは、あなたが作ろうとしているプログラムのプロジェクトファイルの先頭に登録しておくなどして【独自の名前空間 VLX アプリケーション】に含まれるようにします。この include 関数はファイルがプロジェクトに登録されていても \*DrawingLevelEnviromet\* が T の間は定義がスキップされ、【独自の名前空間 VLX アプリケーション】内でのみ活性化します。 148 | 149 | ![setting-project](img/project-window.png) 150 | 151 | ### include ステートメント 152 | 153 | 2. 必要なライブラリ関数の include ステートメントを、あなたのプログラムに書いておく。 154 | 3. Visual LISP からプロジェクトをロードしプログラムを実行する。 155 | 4. テストを繰り返して、あなたのプログラムを完成させる。 156 | 157 | include 関数で適時ライブラリの関数をロードしながら、あなたのプログラムを完成させてください。あなたのプログラムには次のようなステートメントを記述するとライブラリの関数が書かれたファイルが必要に応じてライブラリからロードされるようになります。 158 | 159 | ```lisp 160 | (include 'default "./common/default") 161 | ``` 162 | 163 | include 関数の最初の引数が必要な関数の関数名、第二引数は関数が定義されたファイル名を表します。上の例の場合は、default 関数が定義されていなければ、"./common/default" ファイルをロードせよ、という意味になります。ファイル名は、AutoCADの【サポートファイルの検索パス】からの相対パスで記述されています。 164 | 165 | ![include-statement](img/application-include.png) 166 | 167 | ## STEP 2 - 独自の名前空間 VLX アプリケーションの作成 168 | 169 | ### ライブラリ関数一覧のプロジェクトファイルを作成 170 | 171 | 1. exportLib 関数を使って、利用しているライブラリ関数の一覧をプロジェクトファイルに書き出す。 172 | 173 | あなたのプログラムが完成したら、【独自の名前空間 VLX アプリケーション】の作成に向けてライブラリから使用している関数の一覧を Visual LISP のプロジェクトファイルの形で書きだします。この作業は開発過程で include 関数がロードしたものを書き出すものですから、試行錯誤の間に不要な関数がロードされているかもしれません。そのため、一度 AutoLISP 実行環境をリセットしてから改めてあなたのプログラムをロードして、不要なものが含まれていない状態で行ってください。exportLib 関数を【コンソール】から実行すると、ファイルを保存するダイアログが出るので、ファイル名を指定して保存を行ってください。 174 | 175 | ```lisp 176 | _$ (exportLib nil nil) ⏎ 177 | 178 | ; Resouce files was exported as project file. 179 | ; F:\VisualLISP\resource\DrawTools\resource.prj 180 | ``` 181 | exportLib 関数は二つの引数を受け付けます。一つ目は FAS ファイルが出力される一時フォルダを表す文字列です。二つ目は 一時ファイルが出力される一時フォルダを表す文字列です。ともに nil が指定されれば、デフォルト値の "temp" が使われます。 182 | 183 | exportLib 関数に加えて exportresource 関数も使用できます。exportresource 関数には引数がなく、 exportLib 関数の二つの引数に nil を与えた場合と動作が同じです。 184 | 185 | ```lisp 186 | _$ (exportresource) ⏎ 187 | 188 | ; Resouce files was exported as project file. 189 | ; F:\VisualLISP\resource\DrawTools\resource.prj 190 | ``` 191 | 192 | ### アプリケーション定義ファイルを設定し VLX アプリケーションを作成する 193 | 194 | 2. アプリケーション定義ファイルを用意する。 195 | 196 | Visual LISP のメニュー【ファイル】→【アプリケーションを作成】→【アプリケーション新規作成ウィザード】または【既存のアプリケーションのプロパティ】を使って【VLX アプリケーション】定義ファイルの設定を行っていきます。 197 | 198 | ![filemenu-→application](img/application-create_jpn.png) 199 | 200 | 必要なポイントは以下の通りです。 201 | 202 | - 【アプリケーションのオプション】タブで【独自の名前空間】にチェックを入れる。 203 | - 【ファイルをロード】にあなたのプロジェクトファイルを登録する。 204 | - 【リソースファイル】のタブにライブラリ関数一覧のプロジェクトファイルを登録する。 205 | 206 | 【~ アプリケーションのプロパティ】ダイアログの【アプリケーションのオプション】タブで【独自の名前空間】にチェックを入れてください。 207 | 208 | ![application-options](img/application-options_jpn.png) 209 | 210 | 次に【ファイルをロード】タブに、あなたが作成したプログラムのプロジェクトファイルを登録します。 211 | 212 | ![application-load](img/application-load_jpn.png) 213 | 214 | ライブラリの関数一覧を記録したプロジェクトファイルは【リソースファイル】のタブに登録します。 215 | 216 | ![application-resource](img/application-resource_jpn.png) 217 | 218 | その他のアプリケーションの設定はあなたの環境に合わせて適時設定してください。 219 | 220 | 3. Visual LISP の【ファイル】→【アプリケーションを作成】からVLXアプリケーションを作成する。 221 | 222 | 以上の設定が出来たら Visual LISP のメニュー【ファイル】→【アプリケーションを作成】→【アプリケーションを作成】または【アプリケーションを再作成】から【VLX アプリケーション】を作成します。 223 | 224 | 再度 AutoLISP 実行環境をリセットしてから、作成された【VLX アプリケーション】をロードしてきちんと動作するかテストしてください。 225 | 226 | # VLX アプリケーションのロード時のトラブル 227 | 228 | APPLOAD コマンドから完成した【VLX アプリケーション】を AutoCAD にロードして「~が正常にロードされました」と表示されても、ロード中にエラーが発生してプログラムが実行できない場合があります。開発時に正常に動いていたならば、ほとんどの場合は【独自の名前空間 VLX アプリケーション】内にライブラリ関数等をパックするのに漏れがあったのが原因です。次のことを確認して、再度【VLX アプリケーション】を作成してみてください。 229 | 230 | * 再度、ライブラリ関数一覧のプロジェクトファイルやアプリケーション定義ファイルを作成して最新の状態にする。 231 | 232 | * Visual LISP のプロジェクトを使って既に一度【VLX アプリケーション】を作成していたならば、作成時に前回のライブラリ関数一覧のプロジェクトファイルが Visual LISP で開かれています。開かれたプロジェクトが、ファイルの内容より優先されるので以前のプロジェクトを【プロジェクト】→【プロジェクトを閉じる】から確実に閉じてください。 233 | 234 | * 以上の対応でも解決できない場合、Visual LISP を開いた状態で APPLOAD コマンドから【VLX アプリケーション】のロードの失敗を再現してみます。そこで Visual LISP の【エラートレース】を表示させると、何がエラーとなっているか情報を得られる場合があります。ここでの原因は、外部【ObjectARX アプリケーション】による関数を独自の名前空間へインポートし忘れていた事などが考えられます。このような場合は、例えば次のような宣言をプログラムに含めます。 235 | 236 | (vl-arx-import 'startapp) 237 | 238 | 239 | (EOF) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # include 2 | 3 | ![Library system for AutoLISP on Visual LISP IDE](img/include.png) 4 | 5 | # INTRODUCTION 6 | 7 | This library system consists of several functions including the include function, and provides a mechanism for loading the external function files required in the AutoLISP development environment. Then, the list of loaded functions can be created as a Visual LISP project file or a [VLX application] definition file. The final purpose is to create a [VLX application] using these. 8 | 9 | AutoLISP has a load function that allows you to load the required function from another file. But it's a simple operation, so you have to keep track of which files are loaded. Therefore, a system such as a library that loads required functions efficiently and automatically cannot be used in the original AutoLISP execution environment. Here, the include function that extends the load function is defined to build the library system. The main difference between the include function and the load function is that the already loaded file is remembered and unnecessary loading is not performed. 10 | 11 | In addition to an existing library, which is based on the include function, you can create your library of your own reusable functions by organizing them in a separate folder from the program you're writing, in the same way. 12 | 13 | While using the include function automatically loads the function, it becomes difficult to know which function is the target of loading. Therefore, it becomes difficult to use the program in an environment other than the AutoLISP execution environment used for development. From this, it is necessary to finally combine the program you have written and the functions of the necessary libraries into one [Separate-namespace VLX application]. By using [Separate-namespace VLX Application], it is possible to make the program easy to handle with one file and operate without interfering with AutoLISP execution environment of other AutoCAD users. 14 | 15 | You can write the list of function files that the include function has loaded and remembered to the Visual LISP project file format. This can be used as a resource in the application definition file when finishing your program as a "Separate-namespace VLX application". You can also directly create a application definition file for the development environment of Visual Studio Code where Visual LISP projects cannot be used. For that, it requires a little work using the load-file and resource-file functions in addition to the include function. This corresponds to manually editing the application definition file in Visual LISP. 16 | 17 | # ABOUT LICENSE 18 | 19 | The function source code is a MIT license. The MIT license is one of the open source software licenses that has few restrictions. 20 | 21 | The outline of the MIT license is translated into this case as follows. 22 | * No warranty! 23 | * Anyone can use the source code of this function for free. You can freely distribute and change the source code, including commercial use, and create programs that use it. 24 | * When redistributing or changing the source code of this function, the following copyright notices already included in this must not be erased. Also, when you try to distribute your program created using this, please display the following three copyright notice lines in appropriate place where we can confirm, such as another file for the license display that is included. 25 | ``` 26 | Copyright (c) 20xx manual chair japan 27 | Released under the MIT license 28 | https://opensource.org/licenses/mit-license.php 29 | ``` 30 | 31 | # Preparation of library system 32 | 33 | ## Set Support File Search Path 34 | 35 | 1. Set [Support File Search Path] of AutoCAD. 36 | 37 | Set the path to the library. You can put the libraries that depend on the include function or libraries that you want to create on your own wherever you want. However, for the path up to that, please set the [Support file search path] of AutoCAD. This setting can be set from the [Files] tab of the dialog displayed by the OPTIONS command of AutoCAD. 38 | 39 | ![setting-support-file](img/application-files.png) 40 | 41 | Depending on the version of AutoCAD, include the folder in the [trusted Location]. 42 | 43 | ## Define include and other functions 44 | 45 | 2. Load include function in AutoLISP development environment of AutoCAD. 46 | 47 | The include function loads a function from a library. In advance, load this function into the development environment from the **include-lib.LSP** file from acaddoc.LSP etc. 48 | 49 | ![setting-accaddoc](img/application-acaddoc.png) 50 | 51 | When this file is loaded, a series of functions are defined, including the include function and functions that writes the list of files loaded using include function. Also, the global variable \*DrawingLevelEnviromet\* is set to T. 52 | 53 | This completes the library system settings. The process of program development is explained below. The process can be divided into two types depending on whether you are using Visual Studio Code (CASE 1) or Visual LISP (CASE 2) . In the case of Visual LISP, it is easier to develop programs using Visual LISP projects. 54 | 55 | # Usage - CASE 1: Visual Studio Code development environment 56 | 57 | Although it is the case of the Visual Studio Code development environment, it is also possible with Visual LISP without using the project file. 58 | 59 | For Visual Studio Code development environment where Visual LISP project cannot be used, the definition file of [VLX application] is automatically created directly. For that, a little work is required using the load-file and resource-file functions. This corresponds to manually editing the application definition file in Visual LISP. 60 | 61 | ## STEP 1 - Develop a program 62 | 63 | ### Preparing LISP file for project loading 64 | 65 | 1. Prepare a LISP file for project loading using the load-file and resource-file functions. 66 | 67 | Prepare a LISP program for loading corresponding to the Visual LISP project. Here is the code that loads a set of program files for your project. In that case, use the load-file function instead of the load function. 68 | 69 | ```lisp 70 | (load-file "./project/DrawTools") 71 | ``` 72 | 73 | The load-file function receives a single string argument representing the file name and loads the LISP program file when it is called as in the load function, but remembers the loaded file. This is used when outputting the application definition file. The file extension is not required, which is the same as the load function. 74 | 75 | Use the resource-file function for programs other than LISP program files that use DCL files or TXT files and include them as resources in the final [VLX application]. 76 | 77 | ```lisp 78 | (resource-file "./resource/data.txt") 79 | ``` 80 | 81 | This function takes one argument, a string that represents a filename, and when called, only records the file and has nothing to do with running your program. The recorded file is output to the application definition file. Please specify the resource specified in the resource-file function including the file extension. Describe this declaration in either the project loading file or the file loaded from it. 82 | 83 | ### Include Function For Separate-namespace VLX Applications 84 | 85 | 2. Register the include function for [Separate-namespace VLX application] at the top of the project loading file using the load-file function. 86 | 87 | When the program is finally created as [Separate-namespace VLX applications], the library functions are loaded from within the resource. In this case, use an include function that target resources different from the include function used during development. This function is defined in **include.lsp**. 88 | 89 | Register this file at the top of the project file of the program you are creating, so that it is included in the [Separate-namespace VLX applications]. This include function skips the definition while \*DrawingLevelEnviromet\* is T even if the file is registered in the project loading file, and is activated only in the [Separate-namespace VLX applications]. 90 | 91 | ![vscode-load-file](img/vscode-load-file.png) 92 | 93 | ### Include Statement 94 | 95 | 3. Write an include statement for the required library function in your program. 96 | 4. Connect to AutoCAD from Visual Studio Code and use the project loading file to load the file. 97 | 5. Repeat the test to complete your program. 98 | 99 | Complete your program while loading library functions in time with the include function. From Visual Studio Code, you can load the set of project files by connecting to AutoCAD by specifying the project loading file. 100 | 101 | If you write the following statement in your program, the file containing the library functions will be loaded from the library as needed. 102 | 103 | ```lisp 104 | (include 'default "./common/default") 105 | ``` 106 | 107 | The first argument of the include function is the name of the function that requires it, and the second argument is the file-name in which the function is defined. In the above example, if the default function is not defined, it means to load the "./common/default" file. The file name is described as a relative path from the AutoCAD [Support File Search Path]. 108 | 109 | ![vscode-include](img/vscode-include.png) 110 | 111 | ## STEP 2 - Creating Separate-namespace VLX application 112 | 113 | ### Write of application definition file 114 | 115 | 1. Write the application definition file using the createPRV function. 116 | 117 | After your program is complete, use the createPRV function to write an application definition file for creating [Separate-namespace VLX application]. This work writes out what the include, load-file, and resource-file functions remember during the development process, so you may have registered unnecessary files during trial and error. Therefore, please reset the AutoLISP execution environment once, then load your program again, and do the operation without unnecessary items. When you execute the createPRV function from [Console], the dialog to save the file appears. Please specify the file name and save. 118 | 119 | ```lisp 120 | > (createPRV nil nil) ⏎ 121 | 122 | ; An application make file has been created. 123 | ; F:\VisualLISP\project\DrawTools\DrawTools.prv 124 | ``` 125 | The createPRV function has two arguments. First, specify the temporary file folder with strings. If you specify nil, it will be "temp". The second argument specifies the output destination folder of [VLX application]. If nil, it is created in the same location as the application definition file. 126 | 127 | ### Creating a VLX application 128 | 129 | 2. Create [VLX application] from AutoCAD command MAKELISPAPP. 130 | 131 | Please check whether the contents of the output application definition file include your project file and resource file. 132 | 133 | Make or rebuild [VLX application] by specifying this application definition file from AutoCAD command MAKELISPAPP. 134 | 135 | After resetting the AutoLISP execution environment again, load the created [VLX application] and test if it works properly. 136 | 137 | # Usage - CASE 2: Visual LISP development environment 138 | 139 | ## STEP 1 - DEVELOP PROGRAMS 140 | 141 | ### Include Function For Separate-namespace VLX Applications 142 | 143 | 1. Register the include function for [Separate-namespace VLX applications] at the top of your project. 144 | 145 | When the program is finally created as [Separate-namespace VLX applications], the library functions are loaded from within the resource. In this case, use an include function that target resources different from the include function used during development. This function is defined in **include.lsp**. 146 | 147 | Register this file at the top of the project file of the program you are creating, so that it is included in the [Separate-namespace VLX applications]. This include function skips the definition while \*DrawingLevelEnviromet\* is T even if the file is registered in the project, and is activated only in the [Separate-namespace VLX applications]. 148 | 149 | ![setting-project](img/project-window.png) 150 | 151 | ### Include Statement 152 | 153 | 2. Write an include statement for the required library function in your program. 154 | 3. Load the project from Visual LISP and run the program. 155 | 4. Repeat the test to complete your program. 156 | 157 | Complete your program while loading library functions in time with the include function. If you write the following statement in your program, the file containing the library functions will be loaded from the library as needed. 158 | 159 | ```lisp 160 | (include 'default "./common/default") 161 | ``` 162 | 163 | The first argument of the include function is the name of the function that requires it, and the second argument is the file-name in which the function is defined. In the above example, if the default function is not defined, it means to load the "./common/default" file. The file name is described as a relative path from the AutoCAD [Support File Search Path]. 164 | 165 | ![include-statement](img/application-include.png) 166 | 167 | ## STEP 2 - CREATE SEPARATE-NAMESPACE VLX APPLICATION 168 | 169 | ### Create Project File of Library Function List 170 | 171 | 1. Use the exportLib function to export a list of library functions as a project file. 172 | 173 | When your program is completed, write a list of functions used from the library to a Visual LISP project file to create your [Separate-namespace VLX applications]. Since this process writes out what the include function loaded during the development process, unnecessary functions may have been loaded during trial and error. Therefore, reset the AutoLISP execution environment once, load your program again, and make sure that unnecessary functions are not included. When the exportLib function is executed from [Console], a dialog to save the file appears. Specify the file name and save. 174 | 175 | ```lisp 176 | _$ (exportLib nil nil) ⏎ 177 | 178 | ; Resouce files was exported as project file. 179 | ; F:\VisualLISP\resource\DrawTools\resource.prj 180 | ``` 181 | The exportLib function accepts two arguments. The first is a string that represents the temporary folder where the FAS file is output. The second is a string that represents the temporary folder to which temporary files are output. If both are nil, the default value "temp" is used. 182 | 183 | You can use the exportresource function in addition to the exportLib function. The exportresource function has no arguments, and the behavior is the same as when nil is given to the two arguments of the exportLib function. 184 | 185 | ```lisp 186 | _$ (exportresource) ⏎ 187 | 188 | ; Resouce files was exported as project file. 189 | ; F:\VisualLISP\resource\DrawTools\resource.prj 190 | ``` 191 | 192 | ### Set application definition file and Create a VLX application 193 | 194 | 2. Prepare application definition file. 195 | 196 | Use the Visual LISP menu [File] -> [Create Application] -> [New Application Wizard] or [Existing Application Properties] to set up the application definition file. 197 | 198 | ![filemenu-→application](img/application-create.png) 199 | 200 | The necessary points are as follows. 201 | 202 | - Check [Separate Namespace] on the [Application Options] tab. 203 | - Register your project file in [Load Files]. 204 | - Register the project file of the library function list in the [Resource Files] tab. 205 | 206 | Check [Separate Namespace] on the [Application Options] tab of the [~ Application Properties] dialog. 207 | 208 | ![application-options](img/application-options.png) 209 | 210 | Next, register the project file of the program you created in the [Load Files] tab. 211 | 212 | ![application-load](img/application-load.png) 213 | 214 | The project file that contains the library function list is registered on the [Resource Files] tab. 215 | 216 | ![application-resource](img/application-resource.png) 217 | 218 | Other application settings should be set as appropriate for your program. 219 | 220 | 3. Create a VLX application from the [File]→[Make Application] menu of Visual LISP. 221 | 222 | After the above settings are completed, create a [VLX application] from the Visual LISP menu [File]→[Make Application]→[Make Application] or [Rebuild Application]. 223 | 224 | After resetting the AutoLISP execution environment again, load the created [VLX application] and test whether it works properly. 225 | 226 | # About Trouble Loading VLX Application 227 | 228 | Even if the [VLX application] is loaded into AutoCAD using the APPLOAD command and "~ was successfully loaded" is displayed, an error may occur during loading and the program may not be able to be executed. If it worked properly during development, it is most likely because there was a leak in packing the library functions in the [Separate-namespace VLX application]. Check the following and try to create the [VLX application] again. 229 | 230 | * Create the project file of the library function list or the application definition file again and make it the latest version. 231 | 232 | * If you have already created a [VLX application] using a Visual LISP project, the project file of the previous library function list will be opened in Visual LISP at the time of creation. The opened project file takes precedence over the contents of the file, so be sure to close the previous project file from [Project]→[Close Project]. 233 | 234 | * If the above does not solve the problem, try to reproduce the load failure of the [VLX application] from the APPLOAD command with Visual LISP open. Therefore, if you display the [Error Trace] of Visual LISP, you may be able to get information on what caused the error. A possible cause here is that the functions by the external [ObjectARX application] was forgotten to be imported into its Separate-namespace. In this case, for example, include the following declaration in your program. 235 | 236 | (vl-arx-import 'startapp) 237 | 238 | (EOF) -------------------------------------------------------------------------------- /include-lib.LSP: -------------------------------------------------------------------------------- 1 | ;;;===================================================================== 2 | ;;; Please load this LISP file to your autolisp development 3 | ;;; enviroment. Then the following function is declared. 4 | ;;; Please see also include.LSP. 5 | ;;; 6 | ;;; Use the following functions depending on your development 7 | ;;; environment. 8 | ;;; 9 | ;;; ----------------------+------------------------- 10 | ;;; Visual LISP | Visual Studio CODE 11 | ;;; | or Visual LISP 12 | ;;; ----------------------+------------------------- 13 | ;;; include | include 14 | ;;; | load-file 15 | ;;; | resource-file 16 | ;;; | createPRV 17 | ;;; exportResource | 18 | ;;; (or exportLib) | 19 | ;;; ----------------------+------------------------- 20 | ;;; 21 | ;;;===================================================================== 22 | ;;; (include 'function filename) 23 | ;;;--------------------------------------------------------------------- 24 | ;;; function : symbol 25 | ;;; filename : string 26 | ;;;--------------------------------------------------------------------- 27 | ;;; If no function is defined, the file will be loaded. The loaded 28 | ;;; file name is stored in *include:LibraryFiles* . 29 | ;;; This function is used to load a file from the library, if needed. 30 | ;;;===================================================================== 31 | ;;; (load-file filename) 32 | ;;;--------------------------------------------------------------------- 33 | ;;; filename : string 34 | ;;;--------------------------------------------------------------------- 35 | ;;; The file is loaded and the name is stored in *include:LoadFiles* . 36 | ;;; This function can be used to load your project's files from Visual 37 | ;;; Studio Code instead of the load function in AutoCAD 2021 and later. 38 | ;;; This is used in combination with the createPRV function. 39 | ;;;===================================================================== 40 | ;;; (resource-file filename) 41 | ;;;--------------------------------------------------------------------- 42 | ;;; filename : string 43 | ;;;--------------------------------------------------------------------- 44 | ;;; The file name is stored in *include:ResourceFiles* . 45 | ;;; This function remembers the name of the resource file so that it 46 | ;;; can be used by the createPRV function. It has no direct effect on 47 | ;;; the execution of your program. Specify a DCL or TXT file with this 48 | ;;; function. 49 | ;;;===================================================================== 50 | ;;; (createPRV obj-temp target-folder) 51 | ;;;--------------------------------------------------------------------- 52 | ;;; obj-temp : string or nil (If nil, the default value is "temp") 53 | ;;; target-folder : string or nil (If nil, the default value is "") 54 | ;;;--------------------------------------------------------------------- 55 | ;;; This function creates the VLX application make file (PRV) for 56 | ;;; Visual LISP or command MAKELISPAPP. This configuration file contains 57 | ;;; the contents of *include:LoadFiles*, *include:LibraryFiles* and 58 | ;;; *include:ResourceFiles*. 59 | ;;; The AutoCAD 2021 and later commands MAKELISPAPP enables the 60 | ;;; creation of VLX applications without the use of VisualLISP projects. 61 | ;;;===================================================================== 62 | ;;; (exportResource) 63 | ;;;--------------------------------------------------------------------- 64 | ;;; This function writes out a project file that can be used with 65 | ;;; Visual LISP. The project file is the contents of *include:LibraryFiles* 66 | ;;; loaded with the include function. 67 | ;;; This project file can be included as a resource in the Visual LISP 68 | ;;; VLX application definition file(PRV). In principle, this function 69 | ;;; should be used if you are developing a program using Visual LISP 70 | ;;; instead of Visual studio Code and MAKELISPAPP. 71 | ;;;===================================================================== 72 | ;;; (exportLib fas-temp temp) 73 | ;;;--------------------------------------------------------------------- 74 | ;;; fas-temp : string or nil (If nil, the default value is "temp") 75 | ;;; temp : string or nil (If nil, the default value is "temp") 76 | ;;;--------------------------------------------------------------------- 77 | ;;; The basic behavior of this function is the same as the exportResource 78 | ;;; function. You can change the content a little bit, depending on the 79 | ;;; argument. 80 | ;;; The fas-temp and temp arguments specify a temporary folder. 81 | ;;; (exportLib nil nil) is the same as (exportResource). 82 | ;;;===================================================================== 83 | 84 | ;;; +------------------------------------------------------------------+ 85 | ;;; Copyright (c) 2020 manual chair japan 86 | ;;; Released under the MIT license 87 | ;;; https://opensource.org/licenses/mit-license.php 88 | ;;; +------------------------------------------------------------------+ 89 | 90 | (setq *DrawingLevelEnviromet* T) 91 | 92 | ;;;******************************************************************* 93 | ;;; 94 | ;;; support functions 95 | ;;; 96 | ;;;******************************************************************* 97 | 98 | (setq *include:LoadFiles* nil 99 | *include:LibraryFiles* nil 100 | *include:ResourceFiles* nil 101 | *include:symbol-table* nil 102 | *include:loading-stack* nil ;; 103 | ;; *include:message-mode* = 0~ NOTICE, COUTION and ERROE 104 | ;; 10~ COUTION and ERROE 105 | ;; 100~ ERROR only 106 | *include:message-mode* 0 107 | *include:working-folder* nil 108 | ) 109 | 110 | (defun include:message (level message) 111 | (if (<= *include:message-mode* level) 112 | (princ message) 113 | ) 114 | nil 115 | ) 116 | 117 | (defun include:replace-to-slash (path) 118 | (if path 119 | (vl-list->string 120 | (mapcar 121 | (function 122 | (lambda (char) 123 | (if (= char 92 ;|(ascii "\\")|;) 124 | 47 125 | ;|(ascii "/")|; 126 | char 127 | ) 128 | ) 129 | ) 130 | (vl-string->list path) 131 | ) 132 | ) 133 | ) 134 | ) 135 | 136 | (defun include:normalize-path (path last-slash / last-char) 137 | (if (/= path "") 138 | (progn (setq last-char (vl-string-elt path (1- (strlen path)))) 139 | (if (= last-char 47 ;|(ascii "/")|;) 140 | (if last-slash 141 | path 142 | (substr path 1 (1- (strlen path))) 143 | ) 144 | (if last-slash 145 | (strcat path "/") 146 | path 147 | ) 148 | ) 149 | ) 150 | path 151 | ) 152 | ) 153 | 154 | (defun include:make-list (size initial-element) 155 | (if (not (zerop size)) 156 | (cons initial-element 157 | (include:make-list (1- size) initial-element) 158 | ) 159 | ) 160 | ) 161 | 162 | (defun include:trySearch:sub (extensions) 163 | (if extensions 164 | (if (setq full-filename (findfile (strcat filename "." (car extensions)))) 165 | full-filename 166 | (include:trySearch:sub (cdr extensions)) 167 | ) 168 | ) 169 | ) 170 | 171 | (defun include:trySearch (filename extensions) 172 | (include:trySearch:sub extensions) 173 | ) 174 | 175 | (defun include:full-filename (filename extension-serach / full-filename path) 176 | (include:replace-to-slash 177 | (if (not (null (setq full-filename (findfile filename)))) 178 | full-filename 179 | (if extension-serach 180 | (include:trySearch 181 | (if (/= (setq path (vl-filename-directory filename)) "") 182 | (strcat path "/" (vl-filename-base filename)) 183 | (vl-filename-base filename) 184 | ) 185 | '("VLX" "FAS" "LSP") 186 | ) 187 | ) 188 | ) 189 | ) 190 | ) 191 | 192 | (defun include:file-info (filename extension-serach load-file-symbol / file-info 193 | full-filename 194 | ) 195 | (if (setq full-filename (include:full-filename filename extension-serach)) 196 | (cons (strcase filename) 197 | (list (read (substr (vl-filename-extension full-filename) 2)) 198 | full-filename 199 | ) 200 | ) 201 | ) 202 | ) 203 | 204 | (defun include:load-file ($_filename $_load-list-symbol / $_file-info $_list-item 205 | $_result 206 | ) 207 | (if 208 | (setq $_file-info ;_ Check for file availability 209 | (include:file-info $_filename T $_load-list-symbol) 210 | ) 211 | (if 212 | (vl-catch-all-error-p 213 | (setq $_result (vl-catch-all-apply 214 | 'load 215 | (list (cadr (cdr $_file-info))) 216 | ) 217 | ) 218 | ) 219 | (progn 220 | (include:message 221 | 100 222 | (strcat "\n; ERROR : An error occurred while loading " 223 | $_filename 224 | " ." 225 | ) 226 | ) 227 | (exit) 228 | ) 229 | (progn 230 | (set $_load-list-symbol 231 | (if 232 | (setq $_list-item (assoc (strcase $_filename) 233 | (vl-symbol-value $_load-list-symbol) 234 | ) 235 | ) 236 | (subst $_file-info 237 | $_list-item 238 | (vl-symbol-value $_load-list-symbol) 239 | ) 240 | (cons $_file-info (vl-symbol-value $_load-list-symbol)) 241 | ) 242 | ) 243 | $_result 244 | ) 245 | ) 246 | (progn 247 | (include:message 248 | 100 249 | (strcat "\n; ERROR : There is no module file - " 250 | $_filename 251 | " ." 252 | ) 253 | ) 254 | (exit) 255 | ) 256 | ) 257 | ) 258 | 259 | (defun include:check-circular-reference:dump-string (stack indent) 260 | (if stack 261 | (strcat "\n" 262 | (include:make-list (* indent 2) 32 ;|(ascii " ")|;) 263 | "-->" 264 | (vl-princ-to-string (car stack)) 265 | (include:check-circular-reference:dump-string 266 | (cdr stack) 267 | (1+ indent) 268 | ) 269 | ) 270 | "" 271 | ) 272 | ) 273 | 274 | (defun include:check-circular-reference ($_func $_symbol-info $_load-list-symbol / 275 | $_result 276 | ) 277 | (if 278 | (null 279 | (vl-member-if 280 | (function 281 | (lambda (symbol-info) 282 | (= (strcase (cdr symbol-info)) 283 | (strcase (cdr $_symbol-info)) 284 | ) 285 | ) 286 | ) 287 | *include:loading-stack* 288 | ) 289 | ) 290 | (progn 291 | (setq *include:loading-stack* (cons $_symbol-info 292 | *include:loading-stack* 293 | ) 294 | ) 295 | (if 296 | (vl-catch-all-error-p 297 | (setq $_result (vl-catch-all-apply 298 | $_func 299 | (list (cdr $_symbol-info) $_load-list-symbol) 300 | ) 301 | ) 302 | ) 303 | (progn (setq *include:loading-stack* nil) (exit)) 304 | (progn 305 | (setq *include:loading-stack* (cdr *include:loading-stack*)) 306 | $_result 307 | ) 308 | ) 309 | ) 310 | (include:message 311 | 0 312 | (strcat "\n; NOTICE : " 313 | (cdr $_symbol-info) 314 | " of " 315 | (vl-symbol-name (car $_symbol-info)) 316 | " is causing a circular reference!\n; STACK is -> " 317 | (include:check-circular-reference:dump-string 318 | (recerce (cons $_symbol-info *include:loading-stack*)) 319 | 0 320 | ) 321 | ) 322 | ) 323 | ) 324 | ) 325 | 326 | 327 | ;;;******************************************************************* 328 | ;;; 329 | ;;; include function 330 | ;;; 331 | ;;;******************************************************************* 332 | 333 | (defun include:symbol-info (asymbol filename / symbol-info) 334 | (if (setq symbol-info (assoc asymbol *include:symbol-table*)) 335 | (if (/= (strcase (cdr symbol-info)) (strcase filename)) 336 | (progn 337 | (include:message 338 | 10 339 | (strcat "\n; CAUTION : " 340 | (vl-symbol-name asymbol) 341 | " is doubly defined in " 342 | filename 343 | " and " 344 | (cdr symbol-info) 345 | " ." 346 | ) 347 | ) 348 | (exit) 349 | ) 350 | ) 351 | ) 352 | (cons asymbol filename) 353 | ) 354 | 355 | (defun include ($_include:symbol $_include:filename / $_symbol-info $_list-item 356 | $_result 357 | ) 358 | (if 359 | (and (not (boundp $_include:symbol)) 360 | (setq $_symbol-info ;_ Check the double definition. 361 | (include:symbol-info 362 | $_include:symbol 363 | (include:replace-to-slash $_include:filename) 364 | ) 365 | ) 366 | ) 367 | (progn 368 | (setq $_result (include:check-circular-reference 369 | 'include:load-file 370 | $_symbol-info 371 | '*include:LibraryFiles* 372 | ) 373 | *include:symbol-table* (if 374 | (setq $_list-item (assoc $_include:symbol 375 | *include:symbol-table* 376 | ) 377 | ) 378 | (subst $_symbol-info 379 | $_list-item 380 | *include:symbol-table* 381 | ) 382 | (cons $_symbol-info 383 | *include:symbol-table* 384 | ) 385 | ) 386 | ) 387 | (if (not (boundp $_include:symbol)) 388 | (include:message 389 | 10 390 | (strcat "\n; CAUTION : " 391 | (vl-symbol-name $_include:symbol) 392 | " is not defined in " 393 | $_include:filename 394 | ) 395 | ) 396 | ) 397 | $_result 398 | ) 399 | ) 400 | ) 401 | 402 | ;;;******************************************************************* 403 | ;;; 404 | ;;; load-file function 405 | ;;; 406 | ;;;******************************************************************* 407 | 408 | (defun load-file ($_load-file:filename / $_result) 409 | (include:check-circular-reference 410 | 'include:load-file 411 | (cons 412 | (read 413 | (strcat "$_load-file::" 414 | (vl-filename-base $_load-file:filename) 415 | ) 416 | ) 417 | $_load-file:filename 418 | ) 419 | '*include:LoadFiles* 420 | ) 421 | ) 422 | 423 | ;;;******************************************************************* 424 | ;;; 425 | ;;; resource-file function 426 | ;;; 427 | ;;;******************************************************************* 428 | 429 | (defun resource-file:main (filename / file-info list-item) 430 | (if 431 | (setq file-info ;_ Check for file availability 432 | (include:file-info filename nil '*include:ResourceFiles*) 433 | ) 434 | (setq *include:ResourceFiles* (if 435 | (setq list-item (assoc (strcase filename) 436 | *include:ResourceFiles* 437 | ) 438 | ) 439 | (subst file-info 440 | list-item 441 | *include:ResourceFiles* 442 | ) 443 | (cons file-info *include:ResourceFiles*) 444 | ) 445 | ) 446 | (progn 447 | (princ 448 | (strcat "\n; ERROR : There is no resource file - " 449 | filename 450 | " ." 451 | ) 452 | ) 453 | (exit) 454 | ) 455 | ) 456 | ) 457 | 458 | (defun resource-file (filename / ext) 459 | (if (/= (setq ext (vl-filename-extension filename)) "") 460 | (if (member (read (substr ext 2)) '(DCL PRJ TXT VLX FAS LSP)) 461 | (resource-file:main filename) 462 | (progn (princ "\n; ERROR : Illegal file name extension. (DCL TXT)") 463 | (exit) 464 | ) 465 | ) 466 | (progn 467 | (princ 468 | "\n; ERROR : The file name must have an extension. (DCL TXT)" 469 | ) 470 | (exit) 471 | ) 472 | ) 473 | ) 474 | 475 | ;;;******************************************************************* 476 | ;;; 477 | ;;; createPRV function 478 | ;;; 479 | ;;;******************************************************************* 480 | 481 | (defun createPRV:write:sub (file-info-list) 482 | (if file-info-list 483 | (progn 484 | (princ 485 | (strcat "\n (:" 486 | (strcase (vl-symbol-name (cadr (car file-info-list))) T) 487 | " " 488 | (vl-prin1-to-string (caddr (car file-info-list))) 489 | ")" 490 | ) 491 | fp 492 | ) 493 | (createPRV:write:sub (cdr file-info-list)) 494 | ) 495 | ) 496 | ) 497 | 498 | (defun createPRV:write (fp target obj-temp) 499 | (princ ";;; Visual LISP Apprication make file" fp) 500 | (princ "\n(PRV-DEF" fp) 501 | (princ (strcat "\n (:target . " (vl-prin1-to-string target) ")") 502 | fp 503 | ) 504 | (princ "\n (:active-x . T)" fp) 505 | (princ "\n (:separate-namespace . T)" fp) 506 | (princ "\n (:protected . T)" fp) 507 | (princ "\n (:load-file-list" fp) 508 | (createPRV:write:sub (reverse *include:LoadFiles*)) 509 | ;; 510 | (princ "\n )" fp) 511 | (princ "\n (:require-file-list" fp) 512 | (createPRV:write:sub (reverse *include:LibraryFiles*)) 513 | (createPRV:write:sub 514 | (vl-sort *include:ResourceFiles* 515 | (function 516 | (lambda (file-info-1 file-info-2) 517 | (< (vl-position (cadr file-info-1) resource-order) 518 | (vl-position (cadr file-info-2) resource-order) 519 | ) 520 | ) 521 | ) 522 | ) 523 | ) 524 | ;; 525 | (princ "\n )" fp) 526 | (princ 527 | (strcat "\n (:ob-directory . " 528 | (vl-prin1-to-string obj-temp) 529 | ")" 530 | ) 531 | fp 532 | ) 533 | (princ "\n (:tmp-directory)" fp) 534 | (princ "\n (:optimization . st)" fp) 535 | (princ "\n)" fp) 536 | (princ "\n;;; EOF" fp) 537 | ) 538 | 539 | (defun createPRV (obj-temp target-folder / resource-order filename fp) 540 | (setq resource-order '(DCL PRJ TXT VLX FAS LSP)) 541 | ;; 542 | (if 543 | (setq filename (getfiled "Create Visual LISP PRV file" 544 | (if (null *include:working-folder*) 545 | (getvar "MYDOCUMENTSPREFIX") 546 | *include:working-folder* 547 | ) 548 | "prv" 549 | (+ 1 4 16 128) 550 | ) 551 | ) 552 | (if (setq fp (open filename "w")) 553 | (progn 554 | (if 555 | (vl-catch-all-error-p 556 | (vl-catch-all-apply 557 | 'createPRV:write 558 | (list fp 559 | (strcat 560 | (include:normalize-path 561 | (if (null target-folder) 562 | "" 563 | (include:replace-to-slash target-folder) 564 | ) 565 | T 566 | ) 567 | (vl-filename-base filename) 568 | ".VLX" 569 | ) 570 | (if (null obj-temp) 571 | "temp" 572 | (include:normalize-path 573 | (include:replace-to-slash obj-temp) 574 | nil 575 | ) 576 | ) 577 | ) 578 | ) 579 | ) 580 | (princ "\n; An error occurred while writing the file.") 581 | (progn (princ "\n; An application make file has been created.") 582 | (princ (strcat "\n; " (include:replace-to-slash filename))) 583 | (if 584 | (not 585 | (or *include:LoadFiles* 586 | *include:LibraryFiles* 587 | *include:ResourceFiles* 588 | ) 589 | ) 590 | (princ "\n;\n; But the list of files was empty.\n;") 591 | ) 592 | (setq *include:working-folder* (vl-filename-directory filename)) 593 | ) 594 | ) 595 | (close fp) 596 | ) 597 | (princ "\n; A file open error has occurred.") 598 | ) 599 | ) 600 | (princ) 601 | ) 602 | 603 | ;;;******************************************************************** 604 | ;;; Below functions are used with only Visual LISP ******************** 605 | ;;;******************************************************************** 606 | 607 | (if (or (null (getvar "LISPSYS")) (zerop (getvar "LISPSYS"))) 608 | (progn 609 | ;;******************************************************************* 610 | ;; 611 | ;; exportLib function 612 | ;; 613 | ;;******************************************************************* 614 | (defun exportLib:write:sub (file-info-list) 615 | (if file-info-list 616 | (progn 617 | (princ 618 | (strcat "\n " 619 | (vl-prin1-to-string (caddr (car file-info-list))) 620 | ) 621 | fp 622 | ) 623 | (exportLib:write:sub (cdr file-info-list)) 624 | ) 625 | ) 626 | ) 627 | (defun exportLib:write (fp filename fas-temp temp single / fp) 628 | (princ ";;; Visual LISP project file" fp) 629 | (princ "\n(VLISP-PROJECT-LIST" fp) 630 | (princ "\n :NAME" fp) 631 | (princ (strcat "\n " filename) fp) 632 | (princ "\n :OWN-LIST" fp) 633 | (princ "\n (" fp) 634 | (exportLib:write:sub (reverse *include:LibraryFiles*)) 635 | (princ "\n )" fp) 636 | (princ "\n :FAS-DIRECTORY" fp) 637 | (princ (strcat "\n " (vl-prin1-to-string fas-temp)) fp) 638 | (princ "\n :TMP-DIRECTORY" fp) 639 | (princ (strcat "\n " (vl-prin1-to-string temp)) fp) 640 | (princ "\n :PROJECT-KEYS" fp) 641 | (princ 642 | (strcat "\n (:BUILD (:standard) :MERGED " 643 | (if single 644 | "T" 645 | "nil" 646 | ) 647 | " :SAFE-MODE T :MSGLEVEL 1)" 648 | ) 649 | fp 650 | ) 651 | (princ "\n :CONTEXT-ID" fp) 652 | (princ "\n :AUTOLISP" fp) 653 | (princ "\n)" fp) 654 | (princ "\n;;; EOF" fp) 655 | ) 656 | (defun exportLib (fas-temp temp / filename fp) 657 | (if 658 | (setq filename (getfiled "Export Libraries to Visual LISP Project file" 659 | (if (null *include:working-folder*) 660 | (getvar "MYDOCUMENTSPREFIX") 661 | *include:working-folder* 662 | ) 663 | "prj" 664 | (+ 1 4 16 128) 665 | ) 666 | ) 667 | (if (setq fp (open filename "w")) 668 | (progn 669 | (if 670 | (vl-catch-all-error-p 671 | (vl-catch-all-apply 672 | 'exportLib:write 673 | (list fp 674 | (vl-filename-base filename) 675 | (if (null fas-temp) 676 | "temp" 677 | (include:normalize-path 678 | (include:replace-to-slash fas-temp) 679 | nil 680 | ) 681 | ) 682 | (if (null temp) 683 | "temp" 684 | (include:normalize-path 685 | (include:replace-to-slash temp) 686 | nil 687 | ) 688 | ) 689 | nil 690 | ) 691 | ) 692 | ) 693 | (princ "\n; An error occurred while writing the file.") 694 | (progn 695 | (princ 696 | "\n; The list of library files was written to the project file" 697 | ) 698 | (princ (strcat "\n; " (include:replace-to-slash filename))) 699 | (if (null *include:LibraryFiles*) 700 | (princ "\n;\n; But the list of files was empty.\n;") 701 | ) 702 | (setq *include:working-folder* (vl-filename-directory filename)) 703 | ) 704 | ) 705 | (close fp) 706 | ) 707 | (princ "\n; A file open error has occurred.") 708 | ) 709 | ) 710 | (princ) 711 | ) 712 | ;;******************************************************************* 713 | ;; 714 | ;; exportResource function 715 | ;; 716 | ;;******************************************************************* 717 | (defun exportResource () (exportLib nil nil)) 718 | ) ;_ end-of-progn 719 | ) ;_ end-of-if 720 | 721 | ;;; 722 | 723 | (princ "\ninclude-lib was loaded.") 724 | (princ) --------------------------------------------------------------------------------