I am trying to make a Lisp that will create a Block from ALL objects in a drawing. I would like the name to be exactly the same as the Dwg name (without the ".DWG" extension) with an "X" after. Then I need to insert this block back at 0,0 (when I run the -BLOCK command, the objects disappear upon creation of the block). I was using this expression to get the Dwg name, I just need to add an "X" at the end.
(substr (setq dwgname (getvar "dwgname")) 1 (- (strlen dwgname) 4))
So drawing "S1.DWG" will have a block called "S1X" with the pickpoint placed at 0,0
Thanks
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
Solved by chaitanya.chikkala. Go to Solution.
I found a lisp that will get me close (attached)
I do not want to have to enter each specific dwg file name. I want it to automatically grab the name of a random file, as I have Many to do.
Hello....
I have modified your attached file which saves the block with the drawing name....Try it.
Note that I didnt understand your requirement completely. Hope this serves your purpose
@m_rogoff wrote:
...
So drawing "S1.DWG" will have a block called "S1X" with the pickpoint placed at 0,0
Hi m_rogoff,
perhaps something like this
(vl-load-com)
(defun c:demo (/ file) (setq file (strcat (vl-filename-base (getvar 'DWGNAME)) "_X")) (if (tblsearch "BLOCK" file) (command "_.-block" (setq file (strcat file "X")) "0,0" "_All" "") (command "_.-block" file "0,0" "_All" "") ) (command "_.insert" file "_S" 1 "0,0" "") (princ) )
Hope that helps,
Henrique
Henrique,
I chose your routine becuase the language is simpler and easier for me to understand. However, I need to add two additional lines and I am having trouble figuering out where to merge these commands into your lisp. Where would I add the following lines? Thanks
(command "-layer" "m" "S-Hardware" "c" "2" "" "s" "0" "")
(command "_.chprop" "all" "" "layer" "S-HARDWARE" "c" "bylayer" "lw" "bylayer" "")