Need help with LISP routine - doesn't find blocks

Need help with LISP routine - doesn't find blocks

Anonymous
Not applicable
1,643 Views
8 Replies
Message 1 of 9

Need help with LISP routine - doesn't find blocks

Anonymous
Not applicable

FOHUNT_error.PNG(defun c:FH ( / *error* fp block blk)
  (defun *error* (msg)
    (cond
      ((not msg))
      ((wcmatch (strcase msg) "*CANCEL*"))
      (1 (prompt (strcat "\nERROR: " msg)))
    )
    (princ)
  )
  (and
    (setq blk (getstring "Enter Block Name:"))
    (or
      (setq file (findfile "FOPATH.INF"))
      (alert "File 'fopath.inf' not found.")
    )
    (setq fp (open file "r"))
    (while (not block)
      (setq block (findfile (strcat (read-line fp) "/" blk ".dwg")))
    )
    (not (close fp))
    (setq block (vl-cmdf "insert" block "scale" 1))
     ;; because command returns nil
  )
  (*error* nil)
)

 

I have this lisp that we use to "Hunt" in frequently used blocks. I created this and a directory to place the dwg files for each block.  Each block is WBLOCK'd out to its own file and the code uses FOPATH.inf to search for the directory where the files are kept.  On the first two blocks I put in work just fine.  We are adding to this and each new block that is made (same way as the original two) returns ERROR: bad argument type: stringp nil and doesn't insert the block. You call which block based on typing the name of the dwg file of the block you want.  Is there something that I'm missing in the code?  This still works for the old ones, but does not work on any new blocks added to the list.

 

The FOPATH.INF file is a notebook file that contains only the directory where the blocks are located.

The screenshot below shows 2705dyn as the block that doesn't work and 32a6 as one that does.  They are both in the same folder and made the same way.

0 Likes
Accepted solutions (2)
1,644 Views
8 Replies
Replies (8)
Message 2 of 9

dbhunia
Advisor
Advisor
Accepted solution

Hi

 

Send the written path format in side "FOPATH.INF"

 

Your code it's OK, only thing you have to keep all the blocks in that folder which one you wanted to insert......

 

(It has been tested in "AutoCAD 2007", hope fully it will work in latest version.)


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 9

Anonymous
Not applicable

G:\SHARED\FOHUNT\BLOCKS

 

I have also included a screen shot for reference.

0 Likes
Message 4 of 9

ВeekeeCZ
Consultant
Consultant

Use a slash-forward / at the path.

0 Likes
Message 5 of 9

Anonymous
Not applicable

@ВeekeeCZ wrote:

Use a slash-forward / at the path.


Does this need to be in the path of the fopath.inf file?

0 Likes
Message 6 of 9

Anonymous
Not applicable

------UPDATE------

 

I have two separate versions of this routine attached.  The FOPATH.INF file is also included but the file extension is .txt so you will need to change that. Both of them work on another computer after I copied the "FOPATH.INF" file in my "c:\users\appdata\roaming\autodesk\applicationplugins" folder.  I have the path where the lisp and the .inf file are located in my search path directories under options. If I delete the file from the application plugins folder it gives me the error "FOPATH.INF" file not found. On the other computer, both of them work for ALL the blocks in the folder.  On my computer, the FH command gives me "ERROR: bad argument type: stringp nil" in the command line.  The GG command gives me "Block not found" in the command line....  I don't know where I'm going wrong and I think I may be going crazy.  It's a short trip so I'm kind of worried! HELP!! 

0 Likes
Message 7 of 9

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

@ВeekeeCZ wrote:

Use a slash-forward / at the path.


Does this need to be in the path of the fopath.inf file?


 

Anywhere you have a file path... see HELP for details.

0 Likes
Message 8 of 9

dbhunia
Advisor
Advisor
Accepted solution

Hi,

 

I already told you there is no problem in your lsp code or inf file .........

 

And "findfile" don't required any particular diroctory it finds file allover.........

 

Only thing you have to place all the drawings in that particular folder mentioned in .inf file

 

Try to reset to default. ......the Autocad in your system then try........

 

It may resolve your problem. ......


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 9 of 9

Anonymous
Not applicable

Ok, I think I figured it out..... FINALLY!!  The path I initially created in the .inf file was in a different directory.  The old file is what I had in my App plugin folder.  I was updating the new one and not that one. That is why when I deployed it to another computer it worked just fine and not on mine!!  It's crazy how one character can drive you soooo crazy!  LOL  Thank you everyone for your help and insight!!

0 Likes