Jump to content

about "wblock" command


blueshake

Recommended Posts

hi,all

 

 

in autocad 2010,when I type "wblock" in the command line.

cad will jump out a dialogue to choose/setting.

but when I write a lsp file ,the context as follows.

(defun c:partial_saving(/)
(command "-wblock")
)

 

cad turn into command line model.and I read help file.it says

I should not set filedia as 0.so I change the codes to

(defun c:partial_saving(/)
(setvar filedia 1)
(command "-wblock")
)

 

and it make even worse.cad just give some error.

if I want to show the dialogue,what should I do?can anyone help me??

thanks.

Link to comment
Share on other sites

  • 3 years later...

Hi all,

 

I need to write a program that creates a wblock from and entire drawing. I also need this program to do all of the functions below automatically by typing a simple command:

  1. On the command line, enter wblock.
  2. In the Write Block dialog box, under Source, click Entire Drawing.
  3. Under Destination, in the File Name box, enter the file name for the WBLOCK.
  4. In the Location box, enter the location where you want to save the WBLOCK (new drawing file).
  5. Click OK to create the new drawing file.

I know how to call an already existing autocad command but I'm not sure how to do steps 2 through 5.

This is what I have so far:

 


[color=#383838](defun c:wblockm ()
 
(initdia)(command "._wblock")
 )[/color]

Please help! I've been trying to do this for a while and am finally coming to the conclusion that I need a little help.

 

Thanks

Link to comment
Share on other sites

Try this ;

 

(defun c:partial_saving (/ tmpvar)
(if (= (setq tmpvar (getvar 'filedia)) 0)
 (setvar 'filedia 1)
 )
 (vl-cmdf "-wblock" "file name" "*")
 (setvar 'filedia tmpvar)

Link to comment
Share on other sites

Hi Snownut,

 

This is getting me closer to what I want!

 

So when I run this code it prompts me to enter a name for output file and then select "whole drawing" and then the file is saved on my desktop. But I want all of this to be done automatically. I would like for the file to be name Melanie every time and saved in this location ("C:\\AutoCAD\\"Melanie.dwg") when I enter the partial_saving command.

 

I want the following to be done in the code:

 

wblock Enter name of output file: nil

Enter name of output file: Melanie

Enter name of existing block or

[= (block=output file)/* (whole drawing)] : *

 

Is this possible?

Link to comment
Share on other sites

This should do the trick;

 

(defun c:partial_saving ( / tmpvar)
 (if (= (setq tmpvar (getvar 'filedia)) 0)
   (setvar 'filedia 1)
   )
 (vl-cmdf "-wblock" "C:\\Autocad\\Melanie.dwg" "*")
 (setvar 'filedia tmpvar)
 );defun

 

Just corrected the file name.....

Link to comment
Share on other sites

One last go, with file delete if already exist;

(defun c:partial_saving ( / file)
 (if (setq file(findfile "C:\\Autocad\\Melanie.dwg"))
   (vl-file-delete file)
   )
 (vl-cmdf "-wblock" "C:\\Autocad\\Melanie.dwg" "*")
 );defun

Link to comment
Share on other sites

The ( / file), declares the variable "file" that the function uses a local variable and nil's it out upon function completion. (doesn't clutter up memory that way)

 

The vl-cmdf is the Visual Lisp equivalent of the "command" function, it does not call the wblock dialog box when executed like the command function does.

Link to comment
Share on other sites

Thank you for the clarification!

 

I'm still trying to grasp the main idea of the WBLOCK command, I know it reduces the file size but how does it do it? What does WBLOCK command take out of the drawing to reduce the file size?

 

Thank you!

Link to comment
Share on other sites

The WBLOCK command strips everything that is not needed, layers, linetype, blocks etc. It is an old technique for eliminating errors that you couldn't locate! However, use with caution. If you have spent a long time creating blocks that you are going to use next week, they will be disposed of using WBLOCK. Similarly if you have an expected layer convention but some of them are empty they will be removed and you may have to recreate them.

Link to comment
Share on other sites

  • 2 years later...

Hello,

I tried the lisp and it works well.

I would like to use this lisp to get rid of all Displayproperties.

Because of the huge amount of drawings I have to manipulate, I thought of using this lisp in scriptpro 2.0.

Is there a possibility do wblock a drawing and save the wblock in the original folder and maybe using the original filename or an name like ..._wblock.dwg?

 

I hope you can help me.

thanks.

Bernd

Link to comment
Share on other sites

As your using a script and it opens a drawing it would be easy to then load a lisp, even though you know the dwg name via script the lisp does not, so just add (getvar "dwgname") add the "wblock" to name and use what you have already.

Link to comment
Share on other sites

Hello Bigal,

thanks for your Reply.

I should have admitted, that I am a Code-Noob. So, usially my way is trail and error.

I modified the lisp as:

 

(defun c:partial_saving ( / file)
getvar "dwgname"
 (if (setq file(findfile "dwgname"))
   (vl-file-delete file)
   )
 (vl-cmdf "-wblock" "dwgname" "j" "*")
 );defun

 

The lisp reports that there already exists dwgname.dwg .... override Yes/No.

The lisp ends but I dont't know to where the file was saved.

 

Greetings from Munich.

Bernd

Edited by rkmcswain
added [CODE] tags
Link to comment
Share on other sites

Hi,

 

the solution is:

 

(defun c:partial_saving ( / dwg)
 
 (setq dwg (strcat (getvar "dwgprefix") "wblock_" (getvar "dwgname")))
 
 (if (findfile dwg)
   (vl-file-delete dwg)
 )
 
 (vl-cmdf "-wblock" dwg "j" "*")
 
);defun

Greetings.

Bernd

Edited by rkmcswain
added [CODE] tags
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...