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

Lisp- create block, insert that block

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
m_rogoff
3151 Views, 9 Replies

Lisp- create block, insert that block

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

9 REPLIES 9
Message 2 of 10

Use "strcat" function

 

Eg: (strcat "S1" "x") will return "S1X"

Message 3 of 10

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.

Message 4 of 10

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

Message 5 of 10
hmsilva
in reply to: m_rogoff


 

@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

 

 

EESignature

Message 6 of 10
m_rogoff
in reply to: hmsilva

Both iterations work well.

 

Thank you very much for your help

Message 7 of 10
hmsilva
in reply to: m_rogoff

You're welcome, m_rogoff
Glad I could help

Henrique

EESignature

Message 8 of 10

You are welcome Smiley Happy

Message 9 of 10
m_rogoff
in reply to: hmsilva

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" "")

Message 10 of 10
hmsilva
in reply to: m_rogoff

Hi m_rogoff,

add those commands just after the

(defun c:demo (/ file)

 

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