Results 1 to 4 of 4

Thread: Need help verifying file exists

  1. #1
    I could stop if I wanted to
    Join Date
    2005-08
    Posts
    378
    Login to Give a bone
    0

    Cool Need help verifying file exists

    Could anyone assist me please.
    I am not sure what I am doing wrong ?

    Below is the first part of my routine and not all is relevant. I am stuck with the last part, trying to check if the file already exists to see if I need to replace the file "y" or not.

    Code:
      (setq drawprefix (getvar "dwgprefix"))
      (setq drawname (getvar "dwgname"))
      (setq bldlvl
      (strcase (getstring "\nBuilding Level ie: B1, G, L1 or R? ")
      )
      )
      (setq currentdirectory
      (strcat (getvar "dwgprefix") (getvar "dwgname"))
      )
      (setq newdrawname (strcat "XR-A-" bldlvl))
      (setq num 17)
      (setq strlength (strlen drawprefix))
      (setq newnum (- strlength num))
      (setq ammenddrawprefix1
      (strcat (vl-string-right-trim
         (substr drawprefix newnum strlength)
         drawprefix
       )
       "\\"
      )
      )
      (setq newdirectpath (strcat ammenddrawprefix1 newdrawname))
      (setq check (findfile newdrawname)
      (if (= check newdirctpath) (command "saveas" "r14" newdirectpath "y") (command "saveas" "r14" newdirectpath))
    [ Moderator Action = ON ] What are [ CODE ] tags... [ Moderator Action = OFF ]

    Would be most great full.
    Seems to work when the "If" options are (princ "\n...) rather the (command "saveas" ...)
    Not sure, Should I be using the "cond" function ?

    regards

    stephen
    Last edited by Opie; 2006-09-18 at 01:22 PM. Reason: [CODE] tags added, see moderator comment

  2. #2
    Member
    Join Date
    2003-09
    Posts
    31
    Login to Give a bone
    0

    Default Re: Need help verifying file exists

    You forgot an e in your statement.
    if (= check newdirEctpath) (command "saveas" "r14" newdirectpath "y") (command "saveas" "r14" newdirectpath))

    I am not sure yet if this is The bug, but it IS one.

  3. #3
    Member
    Join Date
    2003-09
    Posts
    31
    Login to Give a bone
    0

    Default Re: Need help verifying file exists

    I put this code Visual LISP and found one error with closing brackets.
    I know that a popular translation of LISP is "Lost In Stupid Parentheses"
    but you must check it or else......

    (setq check (findfile newdrawname)

    In this piece you need 1 more closing bracket.

    In addition to my first reply some explanation:
    (if (= check newdirctpath) (command "saveas" "r14" newdirectpath "y") (command "saveas" "r14" newdirectpath))

    The variable newdirctpath (without a "e") has a value of nil so the if-statement will always do the else (e.g. second) option. When the file exist you get an "error" because AutoCAD ask to confirm the replacing off the old file.

  4. #4
    All AUGI, all the time Avatart's Avatar
    Join Date
    2004-06
    Location
    Upsidedown in dreamtown
    Posts
    928
    Login to Give a bone
    0

    Default Re: Need help verifying file exists

    Below is a snippet of a routine I use to bind in Xrefs, this part of the routine is to check to see if a file exists and set a variable accordingly:
    Code:
    (setq bindpath (strcat (getvar "dwgprefix") "Bind\\"))
    (setq savename (strcat bindpath (getvar "dwgname")))
    (if (/= (findfile savename) nil) (setq exist 1) (setq exist nil))
    (if (/= exist 1)
     (DoBind)
    )
    (if (= exist 1)
      (progn
     (alert "Bound Version Exists")
     (initget 1 "Yes No")
     (setq boundoverwrite (getkword "Bound Version Exists - Overwrite? (Yes/No)"))
    	(if (= boundoverwrite "Yes")
      (DoBind) (DoNotBind)
    	  )
    	)
      )

Similar Threads

  1. 2015: FAMILY ALREADY EXISTS
    By gordolake in forum Revit Architecture - General
    Replies: 2
    Last Post: 2014-08-26, 11:29 PM
  2. 2010: error: Unable to load customization file That customization Group already exists
    By aheintze351177 in forum AutoCAD 3D (2007 and above)
    Replies: 0
    Last Post: 2013-01-09, 10:06 PM
  3. Replies: 0
    Last Post: 2011-05-30, 07:07 AM
  4. How to Find a Layer if It Exists?
    By BeKirra in forum AutoLISP
    Replies: 12
    Last Post: 2008-11-06, 01:25 AM
  5. Check to see if file exists
    By ccowgill in forum AutoLISP
    Replies: 11
    Last Post: 2006-04-10, 09:12 AM

Posting Permissions

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