Jump to content
MarcoW

Insert a block by lisp: _.insert or another way?

Recommended Posts

MarcoW

Hi folks,

 

I was wondering, if I need to make a line by lisp, I "entmake" one. When I want to make other entities, I "entmake" them also.

 

When it comes to inserting a block, should I then go on the "entmake" tour again? I believe the block is already made, it needs to be inserted so not entmade. Am I right?

 

I'd rather use vl-cmdf in stead of "_.insert", is that true?

 

Thats all for today :-)

Any help is very much appreciated.

 

Regards,

MarcoW.

Share this post


Link to post
Share on other sites
Tharwat

Since that you already have made your block and existed in the current drawing , you need only to use a command to isert that block ....

 

First .

 

(command "_.-insert" "[color="red"][b]YourBlockName[/b][/color]" pause "" "" "")

 

Second .

 

(vl-cmdf "_.-insert" "[b][color="red"]YourBlockName[/color][/b]" pause "" "" "")

 

By "entmakex"

 

 (entmakex (list (cons 0 "INSERT")
                 (cons 2 "Y[b][color="red"]ourBlockName[/color][/b]"); type you Block Name
                 (cons 10 '(0.0 0.0 0.0)))); Insertion point for your Block

Both are the same result .

 

Hope this what you meant .:)

 

Tharwat

Edited by Tharwat
entmakex added

Share this post


Link to post
Share on other sites
asos2000

Entmake BLOCK to create a block

(defun CreatBlock ( BlkNme )
 (entmake (list (0 . "BLOCK")
     (100 . "AcDbEntity")
     (67 . 0)
     (8 . "0")
     (100 . "AcDbBlockReference")
     (cons 2 BlkNme)
     (10 0 0 0)
     (70 . 0)
    )
 )
 ;;;entmake all objects in block

 (entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
 (princ)
)

 

 

 

Entmake INSERT to insert the block

(entmakex
      (list (cons 0 "INSERT")
     (cons 2 BlkNme)
     (cons 8 BlkLyr)
     (cons 10 Pnt)
     (cons 41 BlkScl)
     (cons 42 BlkScl)
     (cons 43 BlkScl)
      )
    )

 

 

 

But first you have to check if the block inserted or not

 

(defun Create_Layers ()
 (if (not (tblsearch "BLOCK" "BlkNme"))
   (progn
     (CreatBlock CADTutor)
     )
   )
 )

Share this post


Link to post
Share on other sites
asos2000

and Entmake is faster than calling command

Share this post


Link to post
Share on other sites
Tharwat

Check this out

 

I believe the block is already made, it needs to be inserted so not entmade. Am I right?

 

I'd rather use vl-cmdf in stead of "_.insert", is that true?

 

So there is no need for "entmake" since the desired Block is already made and existed in the dwg.

Share this post


Link to post
Share on other sites
David Bethel

Marco,

 

Where things can get dicey, is if the INSERT has ATTRIButes.

 

For entmake:

  • the INSERT entity must contain (66 . 1) sequential entities follow flag
  • you make each ATTRIBute as a individual entity
  • you must make a SEQEND entity to finish

 

For command - either:

  • Add a string value for ATTRIBute to the command sequence
  • Accept the default for each ATTRIBute value like this:

(while (> (getvar "CMDACTIVE") 1)
      (command ""))

 

Also for the command style, you will need to check to see if an external file exists:

(or (tblsearch "BLOCK" block_name)
   (findfile (strcat block_name ".dwg")))

 

-David

Share this post


Link to post
Share on other sites
Lee Mac

vla-insertblock is a good alternative - performs faster than the command call, but no faffing around with entmake'ing Block definitions, or attributes.

Share this post


Link to post
Share on other sites
BlackBox

I was going to suggest vla-insertblock, but Lee beat me to it. :)

Share this post


Link to post
Share on other sites
alanjt
vla-insertblock is a good alternative - performs faster than the command call, but no faffing around with entmake'ing Block definitions, or attributes.

And you automatically get the current annotation (if using annotative blocks) - my biggest like over entmake.

Share this post


Link to post
Share on other sites
Lee Mac
And you automatically get the current annotation (if using annotative blocks) - my biggest like over entmake.

 

I'll have to take your word on that one - I've never delved into the world of annotative.... :cry:

Share this post


Link to post
Share on other sites
alanjt
I'll have to take your word on that one - I've never delved into the world of annotative.... :cry:

That's why I always stress using using vla for any *text or block objects.

Share this post


Link to post
Share on other sites
MarcoW

@ Tharwat & Asos:

The vl-cmdf function is the one to prefer besides the "command" one I believe. But also I think both of them are not really lisp but more as a macro-thing. I don't know how to explain there is nothing to "create" rather then to just insert by command. The "entmake" option does really create something allthough in case of inserting existing blocks it is a bad example. Entmaking a line or polyline is a better example. But conclusion: I will explore about entmake and entmakeX. (Yes I'll dig in that difference too...) Oh yeah, I read about entmake being much faster then just "commands".

 

@ David:

I am shure that all my blocks have attributes.

So what will happen if I insert a block that has 3 attributes, this way:

 
(entmakex
(list (cons 0 "INSERT")
(cons 2 BlkNme)
(cons 8 BlkLyr)
(cons 10 Pnt)
(cons 41 BlkScl)
(cons 42 BlkScl)
(cons 43 BlkScl)
)
)

TBH: I cannot completely follow the "sequential" part.

 

But then the vla-insertblock option Lee suggested: it seems much easier but I need some resource to dig in. Maybe it is in the developers bible or the help section. Will look for it!

I've never delved into the world of annotative.... :cry:

Neither have I.... but I should. Annotative stuff (not lisp but the scaling) is on my wishlist also since I use several different viewportscales in one layout.

 

All of you thanks again, and I will be back with more wuestions, thats for sure!

With kind regards,

MarcoW.

Edited by MarcoW
No more excuses, now some good old decent reply :-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×