CSV.lsp - Main Application Entry Point

File (v3.60): src/x86/v3_60/v3.60/CSV.lsp
Size: 5,186 bytes (195 lines)
Purpose: Main command entry point and application initialization
AutoCAD Command: CSV (launches ConstructiVision)

Note

Critical Application Bootstrapper

This file is the main entry point for ConstructiVision. When users type CSV at the AutoCAD command line or click the menu, this function:

  1. Loads required ARX modules (pcms.arx, pcms2.arx)

  2. Creates runtime batch files (cv.bat, cvplst.bat)

  3. Checks registration/licensing

  4. Launches the main dialog (panel or site)

Warning

v7.0 Major Rewrite

The v7.0 CSV.lsp (10,384 bytes, 281 lines) is completely different:

  • â-’ Registration/licensing system removed

  • â-’ Error handler removed

  • â-’ System variables hardcoded (40+ vars vs 7-11)

  • â-’ Module auto-loading added (70+ modules)

  • â-’ Functions embedded (pj_name, project)

See: v3.60 vs v7.0 Comparison for complete analysis.


Command Definition

C:CSV - Main Application Command

Usage: Type CSV at AutoCAD command line

Function Signature:

(defun c:csv ()
  ; ... initialization and launch ...
)

This is an AutoCAD command function (prefix c: makes it callable from command line).


Initialization Sequence

1. Error Handler Setup

(defun *error* (msg)
  (if panelvar
    (alert
      (strcat
        "ConstructiVision detected a fatal memory allocation error.\n
         All of your work has been temporarily saved. To permanently \n
         save your work, run this program again, click [OK] on the \n
         main panel dialog box before you make any more changes.\n\n"
        msg
      )
    )
    (alert msg)
  )
  (foreach a sysvarlist
    (setvar (car a) (cdr a))
  )
)

Purpose:

  • Catches fatal errors during execution

  • Saves work if panelvar is active (panel dialog open)

  • Restores AutoCAD system variables

  • Provides recovery instructions to user

2. System Variable Preservation

(if (not sysvarlist)
  (progn 
    (set 'sysvarlist '("filedia" "grips" "hpbound" "osmode" "pickbox" "xrefctl" "highlight"))
    (if (>= (distof (getvar "acadver")) 15)
      (set 'sysvarlist (append sysvarlist '("sdi" "angbase" "angdir" "shadedge")))
    )
    (foreach a sysvarlist 
      (set 'sysvarlist (subst (cons a (getvar a)) a sysvarlist))
    )
  )
)

Preserved Variables:

  • filedia - File dialog enable/disable

  • grips - Grip display

  • hpbound - Hatch boundary detection

  • osmode - Object snap mode

  • pickbox - Selection pickbox size

  • xrefctl - External reference control

  • highlight - Selection highlighting

AutoCAD 2000+ Additional Variables:

  • sdi - Single Document Interface mode

  • angbase - Angle base direction

  • angdir - Angle direction (clockwise/counter-clockwise)

  • shadedge - Shaded edge rendering

Why Preserve?

  • ConstructiVision modifies AutoCAD settings

  • Must restore to user’s preferences on exit

  • Prevents permanent changes to AutoCAD environment

3. VLISP Symbol Export (AutoCAD R14)

(if (and (< (distof (getvar "acadver")) 15)
         (or (member "csv.arx" (arx))
             (member "vlide.arx" (arx))
             (member "vlarts.arx" (arx))
             (member "vlrts.arx" (arx))
         )
    )
  (progn 
    (vlisp-export-symbol 'sysvarlist)
    (vl-acad-defun 'setvars)
    (vl-acad-defun 'panel)
    (vl-acad-defun 'finpan)
    (vl-acad-defun 'pj_name)
    (vl-acad-defun 'sdwg_dlg)
    (vl-acad-defun 'site_dlg)
  )
)

Purpose:

  • AutoCAD R14 only (acadver < 15)

  • Exports LISP symbols to ObjectARX namespace

  • Allows ARX modules to call LISP functions

  • Necessary for ARX-LISP interop

Exported Functions:

  • setvars - Set system variables

  • panel - Panel dialog launcher

  • finpan - Finalize panel

  • pj_name - Project name dialog

  • sdwg_dlg - Setup drawing dialog

  • site_dlg - Site dialog launcher

4. Initial Variable Setup

(setvars)  ; Call setvars function (from SETVARS.lsp)

(setq pnl "md"
      ok "t"
      x ""
      btch# nil
      xx nil
      wcl nil
      wctl nil
      wcxl nil
      wczl nil
      wclold nil
      wctlold nil
      wcxlold nil
      wczlold nil
      sol nil
      fs nil
      fs1 nil
      htchsub nil
      htchfl nil
      htchea nil
      htchfz nil
      htchez nil
)

Global Variables Initialized:

  • pnl - Panel mode (“md” = main dialog)

  • ok - Success flag

  • wcl, wctl, wcxl, wczl - Weld connection lists

  • wclold, wctlold, wcxlold, wczlold - Previous weld connection lists

  • sol, fs, fs1 - Foundation slab variables

  • htch* - Hatch-related variables

5. Path Detection

(set 'acaddir (substr (findfile "acad.exe") 1 (- (strlen (findfile "acad.exe")) 8)))
(set 'curdir (getvar "dwgprefix"))
(set 'dwg (getvar "dwgname"))
(setq olddwg dwg olddir curdir)

Purpose:

  • acaddir - AutoCAD installation directory (where acad.exe lives)

  • curdir - Current drawing directory

  • dwg - Current drawing name

  • olddwg, olddir - Save previous values for comparison

Why acaddir Matters:

  • ConstructiVision creates batch files in AutoCAD root directory

  • Files: cv.bat, cvplst.bat

  • These enable DOS SHELL commands without VBA

6. ARX Module Loading

(if (< (distof (getvar "acadver")) 15)
  (progn 
    (if (not (member "pcms.arx" (arx)))
      (arxload "pcms")
    )
    (if (or (member "csv.arx" (arx))
            (member "vlide.arx" (arx))
            (member "vlarts.arx" (arx))
            (member "vlrts.arx" (arx))
        )
      (vlisp-import-exsubrs (list (findfile "pcms.arx") 
                                   "CheckPanelCredit" 
                                   "DecrementPanelCredit"))
      (set '*error* nil)
    )
  )
  (if (not (member "pcms2.arx" (arx)))
    (arxload "pcms2")
  )
)

AutoCAD R14 (acadver < 15):

  • Load pcms.arx (Panel Credit Management System)

  • Import ARX functions: CheckPanelCredit, DecrementPanelCredit

AutoCAD 2000+ (acadver >= 15):

  • Load pcms2.arx (newer version)

Purpose of PCMS Modules:

  • Registration/Licensing - Check if software is registered

  • Panel Credits - Track panel creation quota

  • Trial/Demo Mode - Limited functionality without registration


Runtime Batch File Creation

7. Create cv.bat (General Purpose DOS Commands)

(set 'f (open (strcat acaddir "cv.bat") "r"))
(if f
  (progn 
    (set 'x (substr (read-line f) 1 3))
    (set 'y (read-line f))
    (set 'y (read-line f))
    (close f)
  )
)

(if (or (not (findfile (strcat acadir "cv.bat"))) 
        (/= x "rem") 
        (/= y "%1"))
  (progn 
    (set 'f (open (strcat acadir "cv.bat") "w"))
    (princ (strcat "rem " (rtos (fix (getvar "cdate")) 2 0) "\n") f)
    (princ "@echo off\n" f)
    (princ "%1\n" f)
    (princ "shift\n" f)
    (princ "cd\\\n" f)
    (princ ":crd\n" f)
    (princ "if %1 == \"end\" goto end\n" f)
    (princ "if not exist %1\\nul md %1\n" f)
    (princ "cd %1\n" f)
    (princ "shift\n" f)
    (princ "goto crd\n" f)
    (princ ":end\n" f)
    (close f)
  )
)

Generated cv.bat Contents:

rem 20250120
@echo off
%1
shift
cd\
:crd
if %1 == "end" goto end
if not exist %1\nul md %1
cd %1
shift
goto crd
:end

Purpose:

  • General DOS command execution via AutoCAD SHELL

  • First parameter: Command to execute

  • Remaining parameters: Directory path components

  • Creates nested directories if they don’t exist

Usage Example:

; From inside AutoLISP:
(command "shell" (strcat acadir "cv.bat") "xcopy" "source" "dest" "end")

8. Create cvplst.bat (Panel List Generation)

(set 'f (open (strcat acadir "cvplst.bat") "r"))
(if f
  (progn 
    (set 'y (read-line f)) 
    (set 'y (read-line f)) 
    (close f)
  )
)

(if (or (not (findfile (strcat acadir "cvplst.bat"))) 
        (/= y "%1"))
  (progn 
    (set 'f (open (strcat acadir "cvplst.bat") "w"))
    (princ "@echo off\n" f)
    (princ "%1\n" f)
    (princ "cd %2\n" f)
    (princ "dir %3 /-p/od/-v > pnllist.txt\n" f)
    (princ "dir pnllist.txt /-p/-v\n" f)
    (close f)
  )
)

Generated cvplst.bat Contents:

@echo off
%1
cd %2
dir %3 /-p/od/-v > pnllist.txt
dir pnllist.txt /-p/-v

Purpose:

  • Generate panel file list

  • Parameter 1: Command to execute (usually none)

  • Parameter 2: Directory to change to

  • Parameter 3: File pattern to list

  • Output: pnllist.txt (sorted directory listing)

Usage Example:

; List all CSS*.dwg files in project directory
(command "shell" (strcat acadir "cvplst.bat") "" "C:\\Project" "CSS*.dwg")

See: README Installation Notes - Runtime Batch Files for warning about not moving these files.


Registration & Licensing Check

9. Check Panel Credits

(set 'returncode nil)
(if (type CheckPanelCredit)
  (set 'returncode (CheckPanelCredit))
)

CheckPanelCredit() Function:

  • Imported from pcms.arx or pcms2.arx

  • Returns registration status code

  • Return codes:

    • nil - Not registered

    • 10021 - Valid registration

    • > 10000 - Trial/demo mode with expiration

10. Handle Registration Failure

(if (or (not returncode) 
        (and (> returncode 10000) (/= returncode 10021)))
  (progn
    (set 'f (open (strcat acadir "cv.bat") "r"))
    (if (and (> returncode 10000)
             (/= returncode 10021)
             (> (fix (getvar "cdate")) 
                (+ 100 (atoi (substr (read-line f) 5))))
        )
      (progn
        (alert
          "This installation must be registered to continue\n\n
           There is no additonal charge for multiple registrations.\n
           To register now, please call ConstructiVision at\n
           (425) 712-9021.\nError: 1"
        )
        (if (not (startapp (findfile "wincss.exe")))
          (alert
            "FATAL ERROR -- FILES MISSING\n\n
             The program has been disabled.\n\n
             Please call ConstructiVision Technical Support at\n
             (425) 712-9021.\nError: -1"
          )
        )
        (set 'ok nil)
      )
    )
    (close f)
  )
)

Registration Logic:

  1. Read date stamp from first line of cv.bat (rem 20250120)

  2. Add 100 days to date stamp (trial period)

  3. Compare with current date (getvar “cdate”)

  4. If expired: Show registration prompt

  5. Launch wincss.exe (Registration Manager)

  6. If wincss.exe missing: Fatal error

Trial Period:

  • 100 days from first use

  • Date stored in cv.bat first line comment

  • Clever anti-tampering: If user deletes cv.bat, it recreates with current date (resets trial)

  • But if user registered, PCMS.ARX returns 10021 (bypasses trial check)


Application Launch

11. Launch Main Dialog

(if ok
  (progn
    (if (or panelvar sitevar)
      (if panelvar
        (progn
          (alert
            "To permanently recover your work, click [OK] on the\n
             main panel dialog box before you make any more changes."
          )
          (panel)
        )
        (progn
          (alert
            "To permanently recover your work, click [OK] on the\n
             main site dialog box before you make any more changes."
          )
          (sdwg_dlg)
        )
      )
      (progn
        (set 'pnl "mdstart")
        (md_dlg)
      )
    )
  )
)
(princ)  ; Clean exit

Launch Logic:

If panelvar exists:

  • Panel dialog was previously open (recovery mode)

  • Show recovery message

  • Call panel() function (from PANEL.lsp)

Else if sitevar exists:

  • Site dialog was previously open (recovery mode)

  • Show recovery message

  • Call sdwg_dlg() function (from SDWG_DLG.lsp)

Else (normal startup):

  • Set pnl to “mdstart” (main dialog start mode)

  • Call md_dlg() function (from MD_DLG.lsp)

  • Shows main ConstructiVision menu


Function Dependencies

Functions Called

setvars()      ; From SETVARS.lsp - Set system variables
panel()        ; From PANEL.lsp - Panel dialog
finpan()       ; From FINPAN.lsp - Finalize panel
pj_name()      ; From PJ_NAME.lsp - Project name dialog
sdwg_dlg()     ; From SDWG_DLG.lsp - Setup drawing dialog
site_dlg()     ; From SITE_DLG.lsp - Site dialog (unused?)
md_dlg()       ; From MD_DLG.lsp - Main dialog

; ARX Functions:
CheckPanelCredit()      ; From pcms.arx/pcms2.arx
DecrementPanelCredit()  ; From pcms.arx/pcms2.arx

Global Variables Set

*error*         ; Error handler function
sysvarlist      ; System variables to restore
acaddir         ; AutoCAD installation directory
curdir          ; Current drawing directory
dwg             ; Current drawing name
olddwg          ; Previous drawing name
olddir          ; Previous directory
pnl             ; Panel mode flag
ok              ; Success flag
returncode      ; Registration status
wcl, wctl, ...  ; Weld connection lists
htch*           ; Hatch variables

Integration with VLX

In CSV.VLX:

  • This file is compiled to CSV.FAS

  • Listed in VLX LOAD directive: (:fas "CSV")

  • Entry point for entire application

Compilation:

CSV.lsp ? CSV.FAS ? (packaged in CSV.VLX)

See: CSV.VLX Binary Analysis for complete module list.


Modernization Implications

For P3 (AutoCAD 2026):

  • AutoLISP compatible - Core language is stable

  • ARX modules need rebuild - pcms.arx/pcms2.arx must be recompiled

  • Batch files problematic - Modern Windows security flags .bat files

  • Consider replacing SHELL commands with native AutoLISP file I/O

For P4 (Cloud):

  • AutoLISP NOT available in AutoCAD Web

  • Registration logic must move to cloud - No local ARX

  • No batch files - Web browser has no SHELL command

  • Must rewrite in JavaScript/AutoCAD Core Console API

Security Concerns:

  • Trial period hack - Reading date from cv.bat is trivial to bypass

  • Registration in ARX - Binary can be reverse engineered

  • No online validation - All checks are local

  • Modern approach: Cloud-based license server with token validation



Document Metadata

Created: 2025
Analysis Method: Complete source code review
File Size: 5,186 bytes (195 lines)
Complexity: High (initialization, error handling, licensing, batch file creation)
Completeness: 100%

Key Insight: This file is the “main()” function of ConstructiVision. It handles initialization, licensing, recovery, and launches the appropriate dialog. The batch file creation is clever but fragile (Windows security, antivirus issues).


End of Document