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

IMPORT CREATED WBLOCK

14 REPLIES 14
Reply
Message 1 of 15
Domziman
1848 Views, 14 Replies

IMPORT CREATED WBLOCK

Hi Guys

 

I am looking for a lisp or macro where i can import a certain wblock. Scale needs to be one and rotation should be 0. you should still be able to pick an insertion point i have tried several macro's that i found when looking on goolge but it doesnt quite do the job

Civil 3D Certified Professional
14 REPLIES 14
Message 2 of 15
Kent1Cooper
in reply to: Domziman

Does INSERT not do what you want?  There is no such thing as "a WBLOCK" as a file or object type -- WBLOCK is a procedure, and what it makes is just a .DWG file, which can be INSERTED like any other.  There's no "import" unless perhaps you mean XREF.

Macro something like:

^C^C_.-INSERT YourDwgName \;;;

AutoLisp equivalent:

(command "_.insert" "YourDwgName" pause "" "" "")

Those assume the drawing is in a folder location where AutoCAD knows to look.  You can build in a file path if necessary.

 

EDIT:  An advantage [other than very much less code] of doing it this way, i.e. in an INSERT command, as opposed to @Michiel.Valcke's suggestion asking for an insertion point first and then (entmake)ing the insertion, is that you can see it on-screen, and "drag" it into place, just as when INSERTing any ordinary Block.

Kent Cooper, AIA
Message 3 of 15
Michiel.Valcke
in reply to: Domziman

Why not use the blockspalette?
The Libraries tab allows you to look up another dwg (like a wblock). You'll get a list of the block definitions in that dwg but the dwg itself is actually the first one in the list. 

With the below options you can pre-determine scale/insertion point/ rotation etc...

MichielValcke_1-1673009536806.png

 

If you want to have it as a lisp I would try something like this (untested):

(defun c:importwblock_MHV ( / filename bname insPoint)

  (vl-load-com)
  
  (setq filename (getfiled "Select a drawing" (getvar "DWGPREFIX") "dwg" 0))
  (setq insPoint (getpoint "Specify Insertion Point: "))
  (setq bname (vl-filename-base filename))
  
  (command "-insert" filename) (command)
    
  (entmake (list
             (cons 0 "INSERT")
             (cons 100 "AcDbEntity")
             (cons 100 "AcDbBlockReference")
             (cons 66 1)
             (cons 2 bname)
             (cons 10 insPoint)
           )
  ) ; create the block reference

  (princ) ; clean exit
); end of defun

 

Message 4 of 15
pendean
in reply to: Domziman


@Domziman wrote:

i have tried several macro's that i found when looking on goolge but it doesnt quite do the job


Like what? Show us, share the code or the links please.

 

FYI: "There is no such thing as a WBLOCK as a file or object -- WBLOCK is a procedure, and what it makes is just a .DWG file, which can be INSERTED like any other -- there's no "import" "

Message 5 of 15
paullimapa
in reply to: Domziman

open Windows Explorer and place AutoCAD side by side, look for your dwg that you've created using wblock command on Windows Explorer, then drag & drop that onto the AutoCAD graphics window 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 6 of 15
Domziman
in reply to: paullimapa

Surely you are not reading my post correctly, i know how to do it. I am asking for a lisp method.

Civil 3D Certified Professional
Message 7 of 15
paullimapa
in reply to: Domziman

Perhaps you can describe in more detail because there are existing commands or functions n AutoCAD that already does this. Does this wblock exists in the hard disk?  Do you want a selection window to appear to let you browse for it like the classicinsert command?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 8 of 15
Domziman
in reply to: paullimapa

The reason is that i want to create commands and put it as a button on my custom tab. At the moment i have it on my tool pallet but i need a macro or lisp routine to be able to add it to a button

Civil 3D Certified Professional
Message 9 of 15
paullimapa
in reply to: Domziman

Then just put this macro in the menu button to bring up ClassicInsert command

^C^CClassicInsert;


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 10 of 15
Domziman
in reply to: paullimapa

I know all these commands. This does not link to a specific block. I dont know what can be so hard to understand. I specifically asked for what i require and still everyone here tries to point to something else. I know all the other methods and would not ask if it would do what i was looking for. 

 

ITS  SIMPLE. I HAVE A CERTAIN BLOCK IN A DRAWING I WANT TO INSERT WITH A MACRO OR LISP SO I CAN LINK IT TO A COMMAND.

 

 

Civil 3D Certified Professional
Message 11 of 15
paullimapa
in reply to: Domziman

You are still missing the point. What is the name of the wblock?Do you want to be able to select this wblock from somewhere? Is this block now as you added inside a different drawing?  Such simple questions and you cannot answer. This is why you are not getting the answer you need


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 12 of 15
Michiel.Valcke
in reply to: Domziman

Excuse us for the misunderstanding, there's no need to get agitated, but your initial request was not clear. If you want to place a block, whose definition is stored in an external .dwg, but where the external .dwg is not the block itself you might want to try something like this:

If the block definition is already in your drawing (for example: because it's in the template) you don't even have to insert the main drawing, so you can cut that code. 

 

(defun c:importnormalblockfromexternaldwg_MHV ( / insPoint)
  
  (setq insPoint (getpoint "Specify Insertion Point: "))

  (command "-insert" filename) (command) 
    ;| the filename is the URL of the dwg that has your block definition
       write the url as a string (between " ") and make sure you double up all the slashes
       like this: "C:\\users\\....\\thisdwghasmyblock.dwg"
    |;
    
  (entmake (list
             (cons 0 "INSERT")
             (cons 100 "AcDbEntity")
             (cons 100 "AcDbBlockReference")
             (cons 66 1)
             (cons 2 bname) ; the bname is the name of your block that you wish to insert, written as a string (between " ")
             (cons 10 insPoint)
           )
  ) ; create the block reference

  (princ) ; clean exit
); end of defun

 

 

Or you can try Lee Mac's Steal routine, which is basically Autodesk Design Center in Lisp. There will be bits in the code that would allow you to take a block definition directly from another dwg without importing all the block definitions.

Message 13 of 15
Sea-Haven
in reply to: Domziman

The lisp is (comand "-wblock" do its thing enter name and location of new dwg. Save the new dwg name to say (setenv "MYWBLOCK" newname)

 

step 2 change to dwg that you want new block to be imported into run a second lisp -insert that new block at say 0,0 you get the name of the newblock from (getenv "MYWBLOCK")

step3 explode (entlast) you now have what you just wblocked. 

Message 14 of 15
Domziman
in reply to: Michiel.Valcke

I didnt mean to be rude its just so frustrating if you ask for something and everyone keeps pushing you in another direction. I apologize

Civil 3D Certified Professional
Message 15 of 15
Kent1Cooper
in reply to: Domziman


@Domziman wrote:

..... I HAVE A CERTAIN BLOCK IN A DRAWING I WANT TO INSERT WITH A MACRO OR LISP .....


Does Message 2 not answer that?  Or are you talking about a Block definition that is inside a different drawing from the one you're in?

 

EDIT:  I think the confusion is probably because of your use of WBLOCK as though it is a noun, when it's really a verb.

Some are assuming you want to bring in something that you made using the WBLOCK command [e.g. because of the wording "CREATED WBLOCK" in the Topic heading].  That is not a WBLOCK but simply a drawing file that you can INSERT.  My macro and AutoLisp suggestions in Message 2, and I think @paullimapa's Messages, assume that.

Some are assuming you want to bring in something that is inside a different drawing file as a Block definition, which you could Write out from there [that's what the W in WBLOCK stands for] to its own drawing file using the command, but you want to dig in and pull it out directly.  Messages 3 and 12 from @Michiel.Valcke appear to be about that.

Can you clarify exactly which of those, or something else, is what you want to do?

Kent Cooper, AIA

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report