Results 1 to 7 of 7

Thread: Datalink Path in Vlisp program

  1. #1
    Active Member
    Join Date
    2015-09
    Posts
    68
    Login to Give a bone
    0

    Default Datalink Path in Vlisp program

    I have been trying to obtain the path of a datalink in order to pass it to a vba program and I have not had any success. Does anyone have any idea how this is stored? I am working on a program that checks to see if an Excel file is open by someone else before they try to Write datalinks to source. I found out that if the Excel file is open, it looks like the write worked from Autocad (2009), but it did not and the data is lost.

  2. #2
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Datalink Path in Vlisp program

    Try my routine in this thread. It may give you some idea of where to find the data. Tip it's in the XRecord-like DATALINK object of the ACAD_DATALINK named object dictionary.

  3. #3
    Active Member
    Join Date
    2015-09
    Posts
    68
    Login to Give a bone
    0

    Default Re: Datalink Path in Vlisp program

    Thank you very much, this gets me pointed in the right direction. I don't know how you found the values, I used Vlisp to browse the drawing, but I could not find the 302 parameter that shows the path. Great routine and I am happy that this shows I still have much to learn.

  4. #4
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Datalink Path in Vlisp program

    You're welcome ... It took me about a month of trial & error to get the thing . Wish I had the time to actually complete what I intended for this ... but I think I've bitten off more than I can chew. It becomes extremely complex when trying to modify a DataLink (as I wanted to do originally).

    In the end, I just used that SLOOOOWWW Data Link Manager of AutoCAD, grinded my teeth a few times, but finally fixed my links. Someone got something out of it though ... I basically paid for my dentist's xmas holiday

  5. #5
    Active Member
    Join Date
    2015-09
    Posts
    68
    Login to Give a bone
    0

    Cool Re: Datalink Path in Vlisp program

    Here is my code and I ended up using some VBA to get the Excel info, for the file being open. There were issues with my knowledge and expanded Vlisp to make this work all in AutoCad. I found the VBA from another web site and then worked on it for awhile. I am still working on the final production version, since I have to redefine the datalinkupdate command to include this check, but the functions do work on a network. I have not put error checking in yet. If there is a guru out there that can figure out how to eliminate the VBA, please let me know as I am learing through trying.
    Attached Files Attached Files

  6. #6
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Datalink Path in Vlisp program

    You do quite a lot in that VBA just to find out if the file is open or not. I'm unsure about that LastUser function ... it doesn't seem to be called from anywhere. The file opened checking can be done through pure Lisp though:
    Code:
    (defun checkFile (path / file)
        (if    (setq path (findfile path))
            (progn
                (setq file (vl-catch-all-apply 'open (list path "w")))
                (if    (or (not file) (vl-catch-all-error-p file))
                    (alert (strcat path "\nFile is already open."))
                    (progn
                        (close file)
                        (alert (strcat path "\nFile is not open."))
                    ) ;_ end of progn
                ) ;_ end of if
            ) ;_ end of progn
            (alert (strcat path "\nFile is not found."))
        ) ;_ end of if
    ) ;_ end of defun
    I'm sure that you can also read from the file to check for the last user through Lisp.

  7. #7
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Datalink Path in Vlisp program

    Just looking through the Excel 2007 VBA reference. Apparently you can open the Workbook in readonly mode, then it has a property of WriteReservedBy which shows the username who had it open for writing last.

    To run this in Lisp, you'll need an ActiveX connection to Excel using something like
    Code:
    (setq excl (vlax-get-or-create-object "Excel.Application"))
    (setq wblst (vlax-get-property excl 'Workbooks)) ;Get the workbooks collection
    (setq wb (vlax-invoke wblst 'Open (findfile "test.csv") nil :vlax-true)) ;Open Readonly
    (alert (vlax-get-property wb 'WriteReservedBy)) ;Show the last user to open the file

Similar Threads

  1. 2015: DATALINK Command - Excel Datalink without Dialog Box
    By ddowdy in forum AutoCAD General
    Replies: 0
    Last Post: 2014-12-13, 02:39 PM
  2. comma in file path breaking program.
    By LSElite in forum AutoLISP
    Replies: 5
    Last Post: 2013-11-01, 03:52 AM
  3. 2011: datalink
    By e.mounir in forum AutoCAD General
    Replies: 1
    Last Post: 2010-07-05, 10:10 PM
  4. Replies: 1
    Last Post: 2008-10-11, 05:25 PM
  5. datalink?
    By CADMama in forum AutoCAD LT - General
    Replies: 5
    Last Post: 2007-11-01, 09:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •