Search code examples
bashshellautolisp

Save a shortcut of a .DWG to specified folder by passing file name and folder location


I'm looking for a script (I believe), so that a lisp from CAD can pass the file name and folder location to the script and save a shortcut of the .DWG in the specified folder. I have no experience with scripts. Could someone show me how I might do this?

I found this in one of the other questions, but I'm not sure if it's what I'm looking for or how to make it work.

param ( [string]$SourceExe, [string]$DestinationPath )

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($DestinationPath)
$Shortcut.TargetPath = $SourceExe
$Shortcut.Save()`

Solution

  • In AutoLISP it would be something like this:

    (defun MakeShortcut ( SourceExe DestinationPath / Shell shortcut ) 
        (setq Shell (vlax-get-or-create-object "Wscript.Shell"))
        (setq shortcut(vlax-invoke-method Shell 'CreateShortcut DestinationPath ))
        (vlax-put-property shortcut 'TargetPath SourceExe)
        (vlax-invoke-method shortcut 'Save)
        (vlax-release-object Shell) 
    )
    

    You can use it by call:

    (MakeShortcut "C:\\Path\\Drawing.dwg" "C:\\Test\\test.lnk" )