Jump to content

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


MarcoW

Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@ 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 :-)
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...