Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Block insertion routine based on block file name

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
kameron1967
685 Views, 8 Replies

Block insertion routine based on block file name

Hi guys,

 

I wonder if someone can help create a routine that looks for a block based on a portion of that block name, using a specified path or search path. 

 

For example, block to search for is BLOCKABC123, so if someone inputs ABC or 123 as a block name, it will locate that block within that folder and inserts it into the drawing at a user specified location.

 

Ideally, if there is a check in that if it finds more than one match, then perhaps it flags or prompts you to choose 1, 2, or 3 option which block to use.  But I can live without this special function if it requires too much time to code.

 

Hope that makes sense.  Thanks in advance!

8 REPLIES 8
Message 2 of 9
3wood
in reply to: kameron1967

You can realize it simply in DesignCentre (Ctrl+2 to open it).

Press "Search" button in the toolbar.

DC_1.png

In the pop-out Search dialogue box,

Type in keyword to search in "Search for word(s)" with wildcard option, input search path with "Browse" button, tick "Search subfolders" if you wish.

Below is a test search for block names cotain word "chair".

You can drag the block name in the search result into the drawing area to insert it.

DC_Chair.png

Message 3 of 9
pbejse
in reply to: kameron1967


@kameron1967 wrote:

Hi guys,

 

I wonder if someone can help create a routine that looks for a block based on a portion of that block name, using a specified path or search path.... 

 


sounds easyenough to code. Try 3wood's suggestion first and tell us how it goes.

 

Message 4 of 9
kameron1967
in reply to: pbejse

3Wood - hi.  Thanks for the suggestion and a screenshot of the design center functionality.  Unfortunately, I'm try to have it be automated so that all a user needs to do is type in a partial name of that block and the routine will search that path and find the closest block.  If it cannot find, it will say "not found" or if it find more than one match, perhaps it will list or alert to so that the user will know what those exact block names are.

 

Pbejse, if you'd like to tackle this one, that would be great.  I've searched the forum and did not see anyone requesting this functionality.  Thanks in advance!

Message 5 of 9
hmsilva
in reply to: kameron1967

kameron1967,
try the following code, changes the path, to your specified search path, minimally tested...

 

(defun c:test (/ file dir files itm n fil qt)
  (setq file (getstring "\nEnter partial block name to insert: "))
  (if (and (setq dir "C:\\test\\test\\Blocks\\");; changes to your search path
	   (setq files (vl-directory-files dir (strcat "*" file "*.dwg") 1))
      )
    (progn
      (cond ((= (length files) 1)
	     (command "_.insert" (strcat dir (car files)))
	     (while (> (getvar 'cmdactive) 0) (command pause))
	    )
	    ((> (length files) 1)
	     (setq itm 0)
	     (textscr)
	     (foreach n	files
	       (print (strcat " " (rtos itm 2 0) " <-- " n))
	       (setq itm (1+ itm))
	     )
	     (setq qt (- (length files) 1))
	     (while
	       (or
		 (not fil)
		 (not (<= 0 fil qt))
	       )
		(setq
		  fil (getint
			(strcat "\nEnter block number from 0 to " (rtos qt 2 0) " :")
		      )
		)
	     )
	     (graphscr)
	     (command "_.insert" (strcat dir (nth fil files)))
	     (while (> (getvar 'cmdactive) 0) (command pause))
	    )
      )
    )
    (princ (strcat "\nThere are no blocks with -> " file " <- in the name!!!")
    )
  )
  (princ)
)

 hope that helps
Henrique

EESignature

Message 6 of 9
kameron1967
in reply to: hmsilva

Thanks, that was quick Henrique!  I tested it and tried both numbers and letters and it gave me the options as it should.  Bullseye!  That was awesome, Henrique!  Thanks so much for your time and expertise!! Cheers! 🙂

 

 

Message 7 of 9
hmsilva
in reply to: kameron1967

You're welcome, kameron1967

glad i could help

 

Henrique

EESignature

Message 8 of 9
pbejse
in reply to: hmsilva

Oh bummer, you beat me to it.Smiley Happy

 

Nice one Henrique. 

Message 9 of 9
hmsilva
in reply to: pbejse


@pbejse wrote:

Oh bummer, you beat me to it.Smiley Happy

 

Nice one Henrique. 


Thanks pbejse,
cheers

 

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost