Results 1 to 4 of 4

Thread: extract drive letter from dwgprefix

  1. #1
    Member
    Join Date
    2006-10
    Posts
    3
    Login to Give a bone
    0

    Default extract drive letter from dwgprefix

    I need to extract drive letter after i got the path with dwgprefix and add file name.

    Code:
    (Setq DN (getvar "DWGNAME"))
      (Setq DNLEN (strlen DN))
      (Setq PXLEN (- DNLEN 4))
      (Setq PXNAME (substr DN 1 PXLEN))
      (Setq DWGPATH (getvar "DWGPREFIX"))
      (Setq LFNAME (strcat (substr DWGPATH 1 3) PXNAME ".txt"))
      (Setq FN (OPEN LFNAME "W"))
      (close FN)
    It gives me
    Code:
    "error: bad argument type: streamp nil"
    Can you help me?
    Last edited by BlackBox; 2013-04-22 at 12:45 PM.

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: extract drive letter from dwgprefix

    The error you're receiving is due to attempting to Close a file that was never opened... If you step through your code, you'll see that your call to Open returns Nil, instead of the file descriptor you're expecting.

    One reason for that to happen, is that you may not have write-access to create a new file in that particular location.



    Here's one way to avoid the error:

    Code:
    (vl-load-com)
    
    (defun c:FOO (/ _GetDriveLetter file)
    
      (defun _GetDriveLetter (path) (substr path 1 3))
    
      (if (setq file
                 (open
                   (strcat
                     (_GetDriveLetter (getvar 'dwgprefix))
                     (vl-filename-base (getvar 'dwgname))
                     ".txt"
                   )
                   "w"
                 )
          )
        (progn
          ;;<-- do something
          (close file)
        )
        (prompt "\n** Unable to open new file ** ")
      )
      (princ)
    )
    ** Error handling not provided.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Member
    Join Date
    2006-10
    Posts
    3
    Login to Give a bone
    0

    Default Re: extract drive letter from dwgprefix

    Thank you so much. You were right. I change the location of the file was saved and it fixed the issue.

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: extract drive letter from dwgprefix

    Quote Originally Posted by vildantemel View Post
    Thank you so much. You were right. I change the location of the file was saved and it fixed the issue.
    You're welcome; I'm happy to help.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Similar Threads

  1. Map Drive Letter with LISP?
    By vsheehan in forum AutoLISP
    Replies: 2
    Last Post: 2013-10-01, 12:03 PM
  2. Font mapping to a drive letter in MTXT
    By jmctamney in forum AutoCAD General
    Replies: 7
    Last Post: 2010-09-30, 07:13 PM
  3. Remove drive letter from dwgprefix using Diesel
    By jrichardson in forum AutoCAD Customization
    Replies: 3
    Last Post: 2006-02-23, 08:12 PM
  4. UNC pathing verus Drive Letter Mapping
    By kenmarcus in forum Revit Architecture - General
    Replies: 6
    Last Post: 2006-02-07, 07:37 PM
  5. Globally changing the drive letter of all xref paths
    By gregb.68838 in forum AutoLISP
    Replies: 7
    Last Post: 2005-06-20, 08:51 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
  •