Jump to content

What is the difference between BLOCK & INSERT?


shailujp

Recommended Posts

I see sometimes INSERT is used in SSGET and sometimes BLOCK to capture the blocks. Whats the difference between two and any specific application it requires to be used?

 

Please guide.

Link to comment
Share on other sites

BLOCK is the definition of the block, while INSERT were the instance (that it, instertion of said block in drawing) entities.

Link to comment
Share on other sites

Mircea,

 

I'm not sure If I understood what you explained. My bad English to be blamed :)

 
(tblsearch "BLOCK" "SW_TABLEANNOTATION_0")

(setq swbom (ssget "_x" '((0 . "INSERT")(2 . "SW_TABLEANNOTATION_0"))))

 

Can you explain based on this? Tblsearch uses BLOCK and SSGET uses INSERT? Can this be switched and still be the same?

Link to comment
Share on other sites

Not Msasu, but I think I could answer this question for you.

 

Each block has a definition, and a reference.

The block definition is what is in the drawing file BLOCKNAME.DWG, it's what you would modify if you are making a change that you want to be reflected with each new insertion of BLOCKNAME, assuming that it is inserted into a blank drawing.

 

If you insert this new block definition "BLOCKNAME" into a drawing that already has your block "BLOCKNAME", but before you modified it, the NEWLY INSERTED "BLOCKNAME" will appear as the OLD "BLOCKNAME" because of the DEFINITION that is currently existing in the drawing. That definition is stored from placing it there before you made the changes to your block, said otherwise: the first time you inserted that block, that's how the drawing thinks all of them will look unless it is told otherwise. Here's how you'd go about that:

 

What you'd do is simply make sure that all corresponding block REFERENCES are gone from your dwg, typically done via the purge method. And then once no more REFERENCES to BLOCKNAME you can insert your new "BLOCKNAME" DEFINITION , and the block graphically will now appear as the definition in your "BLOCKNAME" drawing file because there is not a REFERENCE to the old BLOCKNAME still in the drawing that would stop it from picking up the new changes.

 

Programmatically, and at the command line, you can purge all as mentioned before to solve this issue but you may also use lisp in the form of:

 

BlockNEW is BlockOLD modified, okay?

You have an existing block and you just made some changes so now you have BlockOLD and BlockNEW.

When inserting BlockNEW into a BLANK drawing, it will come in fine.

When inserting BlockNEW into a drawing that BlockOLD has been put into (and visibly or invisibly resides within the dwg database, this is why purge is used), then BlockNEW will appear as BlockOLD because the REFERENCE has not been updated within that drawing.

To do so you would use the following lisp command:

(command "insert" "BlockOLD=BlockNEW")

typed exactly like that, where BlockOLD is found within your drawing and BlockNEW is found within a standard directory that is in the autocad search path.

Obviously BlockOLD and BlockNEW are variable names I'm using as examples, if this bit of information was needed then lisping may not be the correct path for the person reading this to go down, but I am adding the statement just to ensure that anyone who reads this doesn't take me literately when I say "exactly like that". I meant of course with the parenthesis and quotes and the equal sign.

 

If you have a task, say, insert BlockNEW into 25 new drawings.....and after you insert BlockNEW into the first blank drawing and then realize you messed up on a linetype, or layer or whatnot...

You'd go make the changes to the block definition, save them, then come back to your first blank drawing, this is how you'd update your BlockNEW to reflect the changes that you just fixed.

Method one is the purge....erase the block, and then purge it. After doing that when you insert BlockNEW again, it will look like it should (with the changes you just made to linetype or layer or whatnot)

Alternatively, you can use lisp to UPDATE THE BLOCK REFERENCE, by using a similar line of code.

(command "insert" "BlockNEW=")

Just like that. It will update the old block to the new block by redefining it's reference.

 

HTH and was clear enough and correct enough to be worthwhile.

Edited by Bhull1985
Link to comment
Share on other sites

I didn't touch the TBLSEARCH in my response because I figured Msasu would come and straighten us both out on it and how it works relating to the DEFINITIONS vs the REFERENCES.

I.e. I would think that because TBLSEARCH searches through dictionaries, which are contained within each individual drawing, that TBLSEARCH would be locating references and not definitions.

But Msasu will explain best I think, or another guru. Just wanted to help some.

Link to comment
Share on other sites

 
(tblsearch "BLOCK" "SW_TABLEANNOTATION_0")
(setq swbom (ssget "_x" '((0 . "INSERT")(2 . "SW_TABLEANNOTATION_0"))))

You would use tblsearch (or perhaps tblnext or tblobjname) when you want to access the definitions, not the insert references in the drawing.

"BLOCK" is just the name of the table. There are several other tables for linestyles, layers, textstyles etc.

This may help... http://www.afralisp.net/autolisp/tutorials/into-the-database.php or refer to Autodesk's DXF reference guide. These will help you understand how tables are structured and accessed.

 

In contrast, an INSERT, as Brandon and Mircea have explained, refer to the references of the block within the drawing.

Link to comment
Share on other sites

Mircea, Brandon & Clint,

 

Thank you very much for your help.

 

I have another question pertaining to AND and NOT. In the Code #1, AND is used just once NOT is used for each line. Why cant I do it per the Code #2 where NOT is enlcosing all the 3 lines. I'm asking this because I did the Code #2 for one of my task and it did not work but still not sure why it didnt work.

 

Code #1

 
(if (and   
       (tblsearch "LAYER" "AM_0")
       (tblsearch "LAYER" "AM_3")
       (tblsearch "LAYER" "AM_7")


      (not (tblsearch "LAYER" "FORMAT"))
      (not (tblsearch "LAYER" "OBJECT_LINE"))
      (not (tblsearch "LAYER" "PHANTOM"))
    )
(progn...

 

Code #2

 
(if (and   
       (tblsearch "LAYER" "AM_0")
       (tblsearch "LAYER" "AM_3")
       (tblsearch "LAYER" "AM_7")
     
      
      (not (tblsearch "LAYER" "FORMAT")
             (tblsearch "LAYER" "OBJECT_LINE")
             (tblsearch "LAYER" "PHANTOM")
      )  
    )
(progn...

Link to comment
Share on other sites

The 'not function only takes one argument, not three. In the code posted it is checking that each of the three layers DO NOT exist. So it looks for the first, if it is not there it will return nil, which the 'not function then evaluates as T and then processing goes to the next line. If it is there, it will return a list, which the 'not function evaluates as nil. If that happens, evaluation of the 'and function ends.

Link to comment
Share on other sites

The 'not function only takes one argument, not three.

 

Does it matter if the 3 lines are combined in just one line? Like this...

 

 
(not (tblsearch "LAYER" "FORMAT") (tblsearch "LAYER" "OBJECT_LINE") (....) )

And what is the alternate way of verifying this in one shot rather than doing it in 3 lines?

Link to comment
Share on other sites

You should use a function that allows for multiple arguments, since NOT will accept only one:

(not [color=red](and [/color](tblsearch "LAYER" "FORMAT")
         (tblsearch "LAYER" "OBJECT_LINE")
         (tblsearch "LAYER" "PHANTOM")[color=red])[/color])

Link to comment
Share on other sites

I guess it depends on what you are really testing for. Mircea's approach will return true if ANY (not all) of the layers are not present, and nil only if ALL of them are present. Maybe that is what you are testing for?

If it is important that none of the layers are present then you either test them like you have in your original code posting or if you really want to get fancy you could use something like:

 

(not (vl-some
      (function
        (lambda ( x )
          (tblsearch "LAYER" x)
          )
        )
      '("FORMAT" "OBJECT_LINE" "PHANTOM")
      )
    )

Link to comment
Share on other sites

Another way

(apply
 'and
 (mapcar
   (function
     (lambda ( x )
       (not (tblsearch "LAYER" x))
       )
     )
   '("FORMAT" "OBJECT_LINE" "PHANTOM")
   )
 )

Link to comment
Share on other sites

If it is important that none of the layers are present then you either test them like you have in your original code posting

 

Yes, none should be present otherwise my following code will fail since I'm trying to either rename the existing layer or create new.

 

I think now I have multiple option to choose from. However, I do want to mention that since my first code is simple enough for my level and serves purpose (atleast for now) so I wont complicate it. But this was a good learning.

 

Thank you guys for your time and effort.

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