inset block using lisp

inset block using lisp

Anonymous
Not applicable
1,097 Views
6 Replies
Message 1 of 7

inset block using lisp

Anonymous
Not applicable

Hi im trying to make a lisp that inserts a block with a preset path so I don't have to look through my files every time to insert this block I use a lot. this is what I have so far but, I cant seem to get it right. 

 

(DEFUN C:erosion10 ( / block_name)

(setq block_name
(cond
((tblsearch "block" "erosion 10") "erosion 10")
((findfile (strcat (getvar 'dwgprefix) "X:\\Justin Gonzalez\\blocks\\erosion 10.dwg")))
(T nil)
)
)

(if block_name
(command "_insert" block_name)
(princ "\nblock name 'erosion 10' not found. ")
)
(PRINC)
)

0 Likes
Accepted solutions (1)
1,098 Views
6 Replies
Replies (6)
Message 2 of 7

pendean
Community Legend
Community Legend
FYI you do know that if you add that folder location to your AutoCAD's default Search paths in OPTIONS>FILES tab, top most entry, you only ever have to use the block name to INSERT it to use.

You can also INSERT that blocks (and others) from ADCENTER if you set that folder to be "home".

You can also create a ToolPalette for all of the blocks in that folder (or just the one(s) you want) from ADCENTER then just drag and drop all day long too.

HTH
0 Likes
Message 3 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

The findfile line is somehow wrong. 

 

(defun c:Erosion10 ( / block_name)

  (if (setq block_name
	     (cond ((tblsearch "block" "erosion 10") "erosion 10")
		   ((findfile "X:\\Justin Gonzalez\\blocks\\erosion 10.dwg") "X:\\Justin Gonzalez\\blocks\\erosion 10.dwg")
		   (nil)))
    (command "_insert" block_name)
    (princ "\nError: block 'erosion 10' not found. ")
    )
  (princ)
  )

 

Message 4 of 7

Anonymous
Not applicable

oh I see thank you for your help @ВeekeeCZ 

0 Likes
Message 5 of 7

Anonymous
Not applicable

I actually didn't know this thanks you @pendean. MY goal is still a lisp though because I want to share it with a few people and this will be easier I think. thanks  

0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

((findfile (strcat (getvar 'dwgprefix) "X:\\Justin Gonzalez\\blocks\\erosion 10.dwg")))
....


I agree, that's the problem line -- the drawing prefix has a drive letter and file path already, so concatenating it onto the front of your "X:\\..." string will give you an invalid path.

 

But it isn't necessary to repeat the whole path and drawing name.  The (findfile) function returns all of that if it finds the file, and being not nil, it will be returned by that condition.  So this is all you need for the second condition:

....

((findfile "X:\\Justin Gonzalez\\blocks\\erosion 10.dwg"))
....

Kent Cooper, AIA
0 Likes
Message 7 of 7

stevo1966
Explorer
Explorer

Thanks, just what I've been needing for a long time !

0 Likes