Emmanuel Delay Posted August 20, 2014 Share Posted August 20, 2014 (edited) Hi, I am basically making a block replace, to replace old blocks with the latest version of that same block. Same block name, but the number of attributes and dynamic properties could have changed (which causes definition problems when you just copy/paste). Obviously I am talking about a lot of blocks per dwg. I will do this through a data file. (extract from old dwg -> open new file with the new block defined -> import data file). My question: - does anyone have a recommendation on a format to save the data? I could make a csv, an xml, JSON, ... - Is there a standard notation that looks like lisp that can be directly read by lisp? When you do a princ of a block, after entget, entsel ... you get this kind of data: (2 . "DI_O_")(10 . (-385.185 1878.27 0.0) ... ) (2 . "clock_a_side_")(10 . (-383.492 2018.29 0.0) ... ) (2 . "clock_a_side_")(10 . (-383.492 2031.03 0.0) ... ) Could this kind of format be interesting? ---- Further explanation I will extract block name, insert point, layer, scale, ... but also all the attributes, the constants and any dynamic properties (name + value). What i will not extract is any of the lines inside block editor. Then I open a fresh dwg, I insert a legend of the new blocks. The import program will just insert the blocks (at the right insert point, layer,...) then see if the old attribute is still there in the new version. If it's still there, I fill in the value. Dito for the dynamic properties. This ensures you get clean new blocks. Edited August 20, 2014 by Emmanuel Delay Quote Link to comment Share on other sites More sharing options...
Bhull1985 Posted August 21, 2014 Share Posted August 21, 2014 Try this: (command "insert" "oldblock=newblock") Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted August 21, 2014 Author Share Posted August 21, 2014 (edited) Let me explain this again. (Strictly speaking this is not what my question is about; I just wonder if anyone can advise on a format to export/import to a data file) We have a library full of blocks, all containing attributes and dynamic properties. From time to time we change the definition of the blocks. Example: some guy wants some extra stretch button on the camera block, so I add a stretch to the block, in the library. Another guy wants an extra attribute. ... Now, we have a dwg with the old block (without the stretch), and a new library containing that same block, but with the stretch. Both blocks keep their block name!! Our plans need revisions; some plans are really old (plans for the Belgian railroads, we've been around since the 1830's). So, we need to add a few cameras to the old dwg. The blocks in our library are no longer the same as those on the plan; but the customer expects to see the new cameras, with the new attribute and the stretch button. So either we have to draw all those camera's again, on a fresh dwg (anyone who programs in lisp is not gonna accept this), or we need something different. ---- My initial solution: - I open a fresh dwg, empty - I insert the whole library - I open the old dwg, copy the blocks - I paste the blocks in the new dwg. What happens is: the new dwg will ignore the old block definition, since the new block is already in the block table. So you get all the new blocks at the position of the old blocks. Usually this works great; exactly what I need. ... but not with dynamic properties. Dynamic properties will mess up your blocks after pasting them in a dwg with an other block definition. So, what I need is an export/import file containing all the important stuff. A lisp program inserts those blocks and fills in all it can. If an old property is not found on the new block definition, that old property will be ignored. If a new property is not found on the old block definition, that property will be kept to the default of the new block. If an old block is not found in the (block table of the) new dwg, the block will not be inserted. This guarantees all the blocks will be clean. ----- By the way, the program is progressing just fine; the data format I use is 1 line per block (so separated by "\n"); properties separated by ";" example 2:RD48_;10:-100.605,1909.96,0.0;8:ICTRA-INF_TEA;41:2.0;50:0.0; ... block name: RD48_; insert point: -100.605,1909.96,0.0; layer: ICTRA-INF_TEA; ... Edited August 22, 2014 by Emmanuel Delay Quote Link to comment Share on other sites More sharing options...
7o7 Posted August 21, 2014 Share Posted August 21, 2014 The format of data file should be a text file with any extention, such as txt, csv ...and you need 2 lisp routine to export / import to transfer you data. The format with ; is allright. Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted August 21, 2014 Author Share Posted August 21, 2014 Yes, that's what I'm using right nog. I would be happy to have a JSON encoder/parser; that would be nice. If anyone has experience with JSON (in Autocad), please tell me. ---- example of JSON: [{"2":"RD48_","8":"ICTRA-INF_TEA","10":[-100.605,1909.96,0.0],"attributes":[{"ATT1":"My Camera 1"},{"ATT2":"Filming the stairs"}] ... }] [] is an array, {} is an object The you can use PHP, javascript, databases, ... to read or write these objects directly Quote Link to comment Share on other sites More sharing options...
7o7 Posted August 21, 2014 Share Posted August 21, 2014 So you have already a data file made by JSON. All you need now is a lisp routine to import and update data? if so could you post a fresh new drawing with some new dynamic block and your data file? Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted August 21, 2014 Author Share Posted August 21, 2014 No, I haven't Both export and import are done with Autocad. But JSON is a good format; you're sure it will be consistent. Now I will have to make sure the deliminators are not used in the data, this wouldn't be a problem when encoded in JSON. And when you have this string, why not have it in a language (data notation) that can be read by other programming languages? Who knows what usefull things can be done with this. if so could you post a fresh new drawing with some new dynamic block and your data file? Sure, I'll post it here Quote Link to comment Share on other sites More sharing options...
chiimayred Posted August 21, 2014 Share Posted August 21, 2014 The easiest way to manage this I've found is using Tool Palettes to manage your library. When you update the blocks from the source drawing it'll automatically update the tool palette (if the block name doesn't change and if you are using the same source drawing). If the user right-clicks on the block definition inside of the tool palette and clicks on "redefine", it'll update all blocks in the open drawing to the latest iteration of the block in the source drawing. Make sure you write-protect the drawings so the users can't accidentally block edit. You can import/export them, which is the method to give your users the tool palettes you created. Ensure you do some organization of the tool palette so it makes sense. There's lots of literature on how to use them online. I've had to update our block library a few times and it was a pain. Then I found out about tool palettes and it saved so much time for roll out cause the users didn't have to do a thing. Quote Link to comment Share on other sites More sharing options...
David Bethel Posted August 21, 2014 Share Posted August 21, 2014 ASCII text works fine. And if you write the data inAutoLISP list format, you simply use the (load) function Example of a text file The file name & extension doesn't matter, but I would suggest sticking to the 8 . 3 DOS format TEST.DAT (setq data '( ((2 . "NAME1")(10 0 0 1)("ATT1" . "MyCamera")) ((2 . "NAME2")(10 5 5 1)("ATT1" . "MyCamera2")) )) Then simply (load "TEST.DAT") You would then have access to the information Command: !data Most spreadsheets and databases are capable of exporting a report or string concatenation fairly easily. HTH -David Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted August 22, 2014 Author Share Posted August 22, 2014 (edited) Ah, thanks, this looks exactly like what I need. If I can keep everything in the format tha LISP uses it self, it must be more robust. EDIT: It is working perfectly. This saves a lot of custom made parsing @ chiimayred : Thanks, I'll try that. Of course I will continue writing my program. It has a few extra benefits. I can notify the designer, example: a list of all the layers and blocks that are missing; I can put extra layer-filters, ... Edited August 22, 2014 by Emmanuel Delay Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.