Jump to content

Get VALUE of Attribute in Block and insert in new block


tmelancon

Recommended Posts

That did it! You enjoy your day! In the meantime I will do some research and mess around with the current code to try and see if I can figure out how to add additional attributes.

Link to comment
Share on other sites

You can transfer all the attributes between the blocks by "translating" the tagstings of the 2 attributes that don't match between the two blocks.

 

If you need help, let me know.

 

Link to comment
Share on other sites

Hi dlanorh you can make this task a more universal program by looking at the block attribute order rather than tag names, say block has 8 attributes use a list of ones required (1 3 6) then get the values save in a list attlst, the same in the new block ( 1 4 7) which may not have matching positions or matching tag names.

 

When you do the (foreach att (vlax-invoke (vlax-ename->vla-object blk ) 'getattributes) the 1st pass is just that attribute 1 next 2 and so on. Just do  a check in list (1 4 7) and update if true (vla-put-textstring att (nth x attlst)) in this example x=0 1 2 

Edited by BIGAL
Link to comment
Share on other sites

Thanks BIGAL for chiming in. I have been messing around with the code trying to adapt it for multiple attributes but am having no luck. If you do not mind editing the code with your suggestions ONLY if you have spare time to even give this your valuable attention, I would greatly appreciate it. If not, I completely understand and do appreciate your already contributed valuable input. God bless.

Link to comment
Share on other sites

Oh nice what a remarkable code! I cannot thank you enough! WOW!

 

When I get in an old drawing with an old titleblock that somehow has the titeblock named "TBLOCK-NEW" it says: Duplicate definition of block TBLOCK-NEW  ignored and doesn't appear to insert the new titleblock. Any idea? Other than that this is fantastic! THANK YOU SO MUCH !

Link to comment
Share on other sites

I found a quick fix, not sure if it was the right fix. I commented out the vlax-invoke and inserted vla-purgeall above the setq ss nil.

 

          (vla-PurgeAll c_doc)
          (setq ss nil)
          ;(vlax-invoke c_doc 'purgeall)

 

Edited by tmelancon
change
Link to comment
Share on other sites

If I run the rename command and rename the old titeblock back to BLOCK, then run the command it works just fine. So apparently if it comes across an old block that for some unknown reason was named TBLOCK-NEW but was never replaced, it just ignores it.

Link to comment
Share on other sites

20 minutes ago, tmelancon said:

I found a quick fix, not sure if it was the right fix. I commented out the vlax-invoke and inserted vla-purgeall above the setq ss nil.

 


          (vla-PurgeAll c_doc)
          (setq ss nil)
          ;(vlax-invoke c_doc 'purgeall)

 

 

They are the same thing. You can also use

 

(vlax-invoke-method c_doc 'purgeall)

If the drawing already contains a block called "TBLOCK-NEW" but it is not the correct one you'll have change the first ssget to read

 

  (mapcar 'setvar sv_lst '(0 0))

  (setq ss (ssget "_X" '((0 . "INSERT") (2 . "TBLOCK,TBLOCK-NEW"))))
  

 

The mapcar statement is just for reference to find the line. This will find a block(s) called either "TBLOCK or TBLOCK-NEW"

 

 

Link to comment
Share on other sites

Ah I see. Just updated code and ran it and got this error. It did in fact delete the old one and insert new one though, just did not populate it with anything.

 

Oops an Error : ActiveX Server returned an error: Parameter not optional occurred

Link to comment
Share on other sites

I have no idea what is causing that. What it means is an activeX call needs to have a parameter which is not present, so something just changed possibly.

Link to comment
Share on other sites

OK, I've tried my modification (2  . "TBLOCK,TBLOCK-NEW") after renaming the block in the tester drawing, and everything works OK.

Link to comment
Share on other sites

I have attached the current Titleblock in question but just changed every attribute text to test1, test2, test3, etc.. for testing purposes. Getting error Oops an Error : ActiveX Server returned an error: Parameter not optional occurred.  Please let me know your thoughts.

 

 

Also changed the code just for this instance:

        ot_lst (list "FECILITY");THESE ARE THE OLD TAG NAMES TO BE UPDATED
        nt_lst (list "PLATFORM");THESE ARE THE CORRESPONDING NEW TAG NAMES

 

FACILITY was misspelled in the old titleblock so I type it as it is, and the new corresponding tag in the new titleblock that the information should show up in is PLATFORM. Which I have updated my code to reflect. Please advise.

TEST-LATEST.dwg

Edited by tmelancon
edit
Link to comment
Share on other sites

The old block in this drawing has two attribute tags with same name "DATE", this is always going to cause problems. Neither of these attribute tags is in the new block and they are not in the tag translation strings, hence the error.

 

If a tag in the old block has a different name to a corresponding tag in the new block it needs to be explicitly translated in the two lists. You can leave old items in the lists and just add new items to the end. The only limiting factor is unique tag names in the "OLD" list as this controls the name translation, the lists can be as long as you like provided each entry has a corresponding correct entry in the new list.

 

With regards to the two tags with the same name, there are two possible solutions, omit updating the tags or try to find a solution to identify which corresponds to what in the new titleblock.

 

I would plump for the first option. I've already implimented it in the attached revised lisp. I have updated Old/New list. Notice that the "INSPECTED" appears in the new list twice. This is allowed as the old list controls the translation.

 

Another point to consider is the fullstop in one of the tag names. This threw me as it wasn't immediately obvious why it wouldn't translate.

 

If you need to change block tag names you should use the "BATTMAN" command (Block ATTribute MANager).

 

bpv3.lsp

Link to comment
Share on other sites

This is why in the example code and block I just recently sent, I removed all but the “FECILITY” tag in the code which like I said was the old misspelled tag in the old titleblock just to use for our test, and specified “PLATFORM” as the new tag. I removed DATE and stuff for this reason. This was just to test on a single attribute as to why I was getting the error. 

Edited by tmelancon
Edit
Link to comment
Share on other sites

Hi guys if block 1 has the same number and ORDER as block 2 then using order is very quick else like I say if its something being done all the time need to look at order. 

 

It looks like 8 attributes so I know a way to do block1 pick block2 new order of attributes. I think I have done this before lots of stuff I have not saved.

 

This is what I am thinking of tagnmes not tagx then enter order if 0 don't do. It will grow or shrink depending on number of atts.

 

image.png.5c0d0e043673cb88f2f6f72a90456f23.png

image.png

Edited by BIGAL
Link to comment
Share on other sites

6 hours ago, tmelancon said:

This is why in the example code and block I just recently sent, I removed all but the “FECILITY” tag in the code which like I said was the old misspelled tag in the old titleblock just to use for our test, and specified “PLATFORM” as the new tag. I removed DATE and stuff for this reason. This was just to test on a single attribute as to why I was getting the error. 

 

Sorry didn't realise that that was your intention.

 

It would seem the error was being generated when no equivalent value for a given tag name was found in the list. By checking if such a value is available we can now avoid this. Attached is a further tweaked lisp.

This now prints a list of attributes (by tag name) where it couldn't fill a value.

 

bpv3.lsp

Link to comment
Share on other sites

@BIGAL Currently both blocks are not present in the drawing at the same time. All the info is collected from the old one, it is deleted, the drawing purged, and then the new block is inserted and updated.

 

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