Wblock named block to specific path/directory

Wblock named block to specific path/directory

Anonymous
Not applicable
2,762 Views
9 Replies
Message 1 of 10

Wblock named block to specific path/directory

Anonymous
Not applicable

Hello, I've already tried to search here in forum a LISP for this task and all over Internet, but I can't find a LISP to accomplish this task at any place. Basically, I would like to Wblock a specific named block (like "B-IMP-", for example), to some specific predefined path/directory, or as a second option (if possible), to the same folder/directory where the file that will be "Wblocked/Opened file/Original File" is located, without being necessary any input from user. Just load the LISP and it's done, the file will be exported with only the "B-IMP-" block, the file will be named "B-IMP-.dwg" (same name as the exported block) and in the correct predefined folder/directory or in the original file path.

 

Is there any easy way of accomplishing that? How difficult is to write a LISP for that?

 

Thanks in advance for all good souls here... 

0 Likes
Accepted solutions (3)
2,763 Views
9 Replies
Replies (9)
Message 2 of 10

_gile
Consultant
Consultant
Accepted solution

Hi,

 

Something like this?

 

(if (tblsearch "block" "B-IMP-")
  (command "_.wblock"
           (strcat (getvar 'dwgprefix) "B-IMP-.dwg")
           "B-IMP-"
  )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 10

Anonymous
Not applicable

 

@_gile wrote:

Hi,

 

Something like this?

 

(if (tblsearch "block" "B-IMP-")
  (command "_.wblock"
           (strcat (getvar 'dwgprefix) "B-IMP-.dwg")
           "B-IMP-"
  )
)

Ow, amazing! Many thanks for that mate! From what I know about LISP the part when you tell the path/directory to be exported is here no?

 

(strcat (getvar 'dwgprefix)

If I want to export the drawing using Wblock to some specific folder/path, so the "Wblocked" file will always appears on Desktop or any other choosen folder, how can I use this?

 

I almost got it working to export to Desktop by the following code:

(if (tblsearch "block" "B-IMP-")
(command "_.wblock"
(strcat (getenv "UserProfile") "\\Desktop" "B-IMP-.dwg")
"B-IMP-"
)
)
 

Thnks a lote for your help!

0 Likes
Message 4 of 10

_gile
Consultant
Consultant
Accepted solution

The strcat function concatenates the strings passed as arguments.

With AutoLISP the backslash (\) is the escape character, so if you need to use it in a string, you have 'escape' it: "\\".

With AutoLISP you cannot directly use the environnment variable shortcuts (as %systemdrive% or "%username%"), you have to use the getenv function.

 

That said, you can use:

(strcat (getenv "userprofile") "\\Desktop\\B-IMP-.dwg")


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 10

Anonymous
Not applicable

@_gile wrote:

The strcat function concatenates the strings passed as arguments.

With AutoLISP the backslash (\) is the escape character, so if you need to use it in a string, you have 'escape' it: "\\".

With AutoLISP you cannot directly use the environnment variable shortcuts (as %systemdrive% or "%username%"), you have to use the getenv function.

 

That said, you can use:

(strcat (getenv "userprofile") "\\Desktop\\B-IMP-.dwg")

Worked 100%! Genious!

 

One last question mate, if I want to plug any other directory on server or at the computer, like for example "V:\BLOCKS\EXPORTED\B-IMP.dwg", how can I achieve that?

 

Thanks for your amazing support and for sharing your knowledge!

0 Likes
Message 6 of 10

_gile
Consultant
Consultant
Accepted solution

As said upper, for hard coded path strings, just replace the backslash (\) directory separators with double backslashes (\\) (or single slashes (/)):

 

"V:\\BLOCKS\\EXPORTED\\B-IMP.dwg"

or

"V:/BLOCKS/EXPORTED/B-IMP.dwg"

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 7 of 10

Anonymous
Not applicable

@_gile wrote:

As said upper, for hard coded path strings, just replace the backslash (\) directory separators with double backslashes (\\) (or single slashes (/)):

 

"V:\\BLOCKS\\EXPORTED\\B-IMP.dwg"

or

"V:/BLOCKS/EXPORTED/B-IMP.dwg"

 


Thanks Gile! This post will help someone else for sure. I've accepted all your solutions. Thanks for your help and time! 🙂

0 Likes
Message 8 of 10

emsquare.arch
Participant
Participant
Hello Gale,

Hope you are doing good.
Nice to see your response. Iam also looking for the wblock lisp but my requirements is little bit different.
I will have polyline (Floor plan) with multiple unit numbers and multiple floors in one drawing. If I want to make wblock I have to select each floor individually, give the name, location etc as per local methodology. But What Iam looking is if I select all floors then tool must make separate wblock for each floor based on the polyline line weight 0.07mm and give the name also based on line weight 0.07mm. I have attached a rough sketch for reference.
Please have a look and help me in this regard.

Thanks,
Saad
0 Likes
Message 9 of 10

devitg
Advisor
Advisor

Hi   , please upload YOUR-sample.dwg , as up now, acad can not edit , or lisp can not manage a hand made sketch 

0 Likes
Message 10 of 10

emsquare.arch
Participant
Participant
Hello

Just give me some time I will upload the sample drawing.

Thanks
0 Likes