zride91 Posted June 15, 2010 Share Posted June 15, 2010 I have a project that has a requirement to submit .dwg and .dgn files. The project was originally done in MicroStation. The problem we are having is that some of the dimensions were exploded in the original MicroStation file when drafted, so those dimensions are just lines with a single line text of "F" for the dimension terminator. The "F" is due to the dimension style from MS. I am hoping that someone has seen some kind of lisp that could find all the single line text that JUST contains the letter "F", place a block on top of it with the same rotation and attributes, then delete the "F". I may be dreaming something fierce on this, but thought I'd throw it out there. There is a ton of files that need to be fixed. I have already found so many helpful posts on this forum. I've been searching for something for a good two days now, even if it's something close, maybe I can piece a few things together. I'm just a beginer with lisp, but this site has helped A LOT. Thanks Quote Link to comment Share on other sites More sharing options...
Freerefill Posted June 15, 2010 Share Posted June 15, 2010 Give this a shot. Just edit the indicated line to use the correct block name. This will only apply the rotation attribute; if you want layers and stuff, let me know. (defun c:txttoblk( / ss) (vl-load-com) (setq blk "BLOCK") ; Put block name here, with directory if block is not already in drawing (setq ss (ssget "X" '((0 . "TEXT")(1 . "F")))) (if ss (progn (setq ss (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))) (mapcar '(lambda (x) (vl-cmdf "-insert" blk (cdr (assoc 10 (entget x))) 1 1 (* (/ 180 pi) (cdr (assoc 50 (entget x))))) (entdel x)) ss) ) (princ "\nNo text entities found.") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
zride91 Posted June 15, 2010 Author Share Posted June 15, 2010 WOW!! Freerefill, thank you SO much. I really wasn't expecting anything, yet so soon! I've only seen text to text, and block to block examples. The lisp works well and is definately in the right direction. There is definately a block for each of the terminator locations, however some of them are inconsistent. I was thinking some of them may have been effected by OSNAP and/or OTRACK, so I turned all the OSNAPS off except insertion, this helped the locations out quite a bit, but there were still a few terminators not being placed at the text insertion point. I noticed these few were outside the current view, so I did a zoom extent, and that seemed to do it. Is there a way to govern the size of the block in relation to the text? The drawing set contains multiple drawing scales, and all the files are done in model space. Thank you SOOO much again!! Quote Link to comment Share on other sites More sharing options...
Freerefill Posted June 15, 2010 Share Posted June 15, 2010 If the text scale and the block scale have any constant relationship to each other, then yes, it is not only possible but probably quite easy. The only question would be the scale. Is it 1:1, or something else? That is to say, if the text height is 1, will the blocks come in at a scale of 1? As for the inconsistencies, it's likely due to my "command line cop-out" code... sorry about that. Edit: I just tested it again, and I'm not getting those inconsistencies... so I'm lost on that one... if you'd like, I'll toss in a bit of code to turn the osnaps off and zoom extents, just so you don't have to remember to do it yourself, but that's up to you. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 15, 2010 Share Posted June 15, 2010 Mark, If you are using _.-insert, remember to use "_non" before specifying the insertion point If I were to approach this problem, I would strip out a few of the DXF codes from the text entity and entmake the insert from that - then all the layer/thickness/linetype etc data is retained with little effort Quote Link to comment Share on other sites More sharing options...
Freerefill Posted June 15, 2010 Share Posted June 15, 2010 Good idea, Lee. I actually haven't even seen "_non" until I saw Alan's code here: http://www.cadtutor.net/forum/showthread.php?p=334825#post334825 I knew it was possible to modify the snaps from the command line like that, but I didn't know "_non" was an option. I'll keep it in mind. As for the rest, I've worked with .dgns before, and I know that an awful lot of information is stripped out (can't even use blocks, dimensions or leaders), that's why I didn't bother with linetypes and layers.. but you're right, it's still doable. Quote Link to comment Share on other sites More sharing options...
zride91 Posted June 15, 2010 Author Share Posted June 15, 2010 If the text scale and the block scale have any constant relationship to each other, then yes, it is not only possible but probably quite easy. The only question would be the scale. Is it 1:1, or something else? That is to say, if the text height is 1, will the blocks come in at a scale of 1? As for the inconsistencies, it's likely due to my "command line cop-out" code... sorry about that. Edit: I just tested it again, and I'm not getting those inconsistencies... so I'm lost on that one... if you'd like, I'll toss in a bit of code to turn the osnaps off and zoom extents, just so you don't have to remember to do it yourself, but that's up to you. Freerefill, Thanks again! I can add the OSNAP and zoom extent stuff, I already have that in a script for this now. I will look into the relationship in text/block size and let you know, that would be the icing on the cake! Thanks Quote Link to comment Share on other sites More sharing options...
zride91 Posted June 15, 2010 Author Share Posted June 15, 2010 If the text scale and the block scale have any constant relationship to each other, then yes, it is not only possible but probably quite easy. The only question would be the scale. Is it 1:1, or something else? That is to say, if the text height is 1, will the blocks come in at a scale of 1? Freerefill, the relationship is text height = 1" when block scale = 10.6666667 Thank you Quote Link to comment Share on other sites More sharing options...
Freerefill Posted June 15, 2010 Share Posted June 15, 2010 I took Lee's suggestion, since it was pretty slick, turning the text DXF codes right into the DXF codes for the block. I don't usually use entmake because, to me at least, it makes cumbersome and ugly lists... but, it does have its benefits. Here it is; let me know if you need anything else. I'm pretty sure I got the scale correct. (defun c:txttoblk( / ss e) (vl-load-com) (setq blk "BLOCK") ; Put block name here, with directory if block is not already in drawing (setq ss (ssget "X" '((0 . "TEXT")(1 . "F")))) (if ss (progn (setq ss (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))) (mapcar '(lambda (x) (setq e (entget x)) (entmake (append (list (cons 0 "INSERT") (cons 100 "AcDbEntity") (cons 100 "AcDbBlockReference") (cons 410 (cdr (assoc 410 e))) (cons 8 (cdr (assoc 8 e))) (cons 2 blk) (cons 10 (cdr (assoc 10 e))) (cons 41 (* (/ 32.0 3) (cdr (assoc 40 e)))) (cons 42 (* (/ 32.0 3) (cdr (assoc 40 e)))) (cons 50 (cdr (assoc 50 e)))) ) ) (entdel x)) ss) ) (princ "\nNo text entities found.") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
zride91 Posted June 15, 2010 Author Share Posted June 15, 2010 Freerefill, the new code runs and just deletes the the F's, the block does not get placed. I may be doing something wrong... I put the path of the block in line 3 as I did before. Was there anything else I had to do to the file prior to running it? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 15, 2010 Share Posted June 15, 2010 This is how I might code it [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:txt2ins [b][color=RED]([/color][/b] [b][color=BLUE]/[/color][/b] *error* blk ss [b][color=RED])[/color][/b] [i][color=#990099];; © Lee Mac ~ 15.06.10[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]vl-load-com[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] blk [b][color=RED]([/color][/b][b][color=BLUE]getfiled[/color][/b] [b][color=#a52a2a]"Select Block"[/color][/b] [b][color=#a52a2a]""[/color][/b] [b][color=#a52a2a]"dwg"[/color][/b] [b][color=#009900]16[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]ssget[/color][/b] [b][color=#a52a2a]"_X"[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=RED]([/color][/b][b][color=#009900]0[/color][/b] . [b][color=#a52a2a]"TEXT"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=#009900]1[/color][/b] . [b][color=#a52a2a]"F"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] blk [b][color=RED]([/color][/b]LM:ForceBlockDefinition blk[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b] i [b][color=BLUE]/[/color][/b] e eLst h [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]while[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] e [b][color=RED]([/color][/b][b][color=BLUE]ssname[/color][/b] ss [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] i [b][color=RED]([/color][/b][b][color=BLUE]1+[/color][/b] i[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] eLst [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] e[b][color=RED])[/color][/b] h [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]40[/color][/b] eLst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entmakex[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]append[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#009900]0[/color][/b] . [b][color=#a52a2a]"INSERT"[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]2[/color][/b] blk[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]LM:RemovePairs [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b] [b][color=#009900]0[/color][/b] [b][color=#009900]1[/color][/b] [b][color=#009900]7[/color][/b] [b][color=#009900]10[/color][/b] [b][color=#009900]11[/color][/b] [b][color=#009900]40[/color][/b] [b][color=#009900]41[/color][/b] [b][color=#009900]51[/color][/b] [b][color=#009900]71[/color][/b] [b][color=#009900]72[/color][/b] [b][color=#009900]73[/color][/b] [b][color=#009900]100[/color][/b] [b][color=#009900]102[/color][/b] [b][color=#009900]330[/color][/b] [b][color=#009900]360[/color][/b] [b][color=RED])[/color][/b] eLst[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]10[/color][/b] [b][color=RED]([/color][/b]LM:GetTextInsertion eLst[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]41[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] h [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] [b][color=#009999]32.[/color][/b] [b][color=#009999]3.[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]42[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]*[/color][/b] h [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] [b][color=#009999]32.[/color][/b] [b][color=#009999]3.[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]entdel[/color][/b] e[b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=#009900]-1[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] LM:ForceBlockDefinition [b][color=RED]([/color][/b] block [b][color=BLUE]/[/color][/b] path ext base [b][color=RED])[/color][/b] [i][color=#990099];; © Lee Mac ~ 15.06.10[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] path [b][color=RED]([/color][/b][b][color=BLUE]vl-filename-directory[/color][/b] block[b][color=RED])[/color][/b] ext [b][color=RED]([/color][/b][b][color=BLUE]vl-filename-extension[/color][/b] block[b][color=RED])[/color][/b] base [b][color=RED]([/color][/b][b][color=BLUE]vl-filename-base[/color][/b] block[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]eq[/color][/b] [b][color=#a52a2a]""[/color][/b] ext[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ext [b][color=#a52a2a]".dwg"[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cond[/color][/b] [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]tblsearch[/color][/b] [b][color=#a52a2a]"BLOCK"[/color][/b] base[b][color=RED])[/color][/b] base [b][color=RED])[/color][/b] [b][color=RED]([/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] block [b][color=RED]([/color][/b][b][color=BLUE]findfile[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]strcat[/color][/b] path [b][color=#a52a2a]"\\"[/color][/b] base ext[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b] [b][color=#a52a2a]"_.-insert"[/color][/b] block[b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]command[/color][/b][b][color=RED])[/color][/b] base [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] LM:RemovePairs [b][color=RED]([/color][/b] pairs lst [b][color=RED])[/color][/b] [i][color=#990099];; © Lee Mac ~ 15.06.10[/color][/i] [b][color=RED]([/color][/b][b][color=BLUE]vl-remove-if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]function[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]lambda[/color][/b] [b][color=RED]([/color][/b] pair [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-position[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b] pair[b][color=RED])[/color][/b] pairs[b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] lst [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] dxf [b][color=RED]([/color][/b] code lst [b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] code lst[b][color=RED])[/color][/b][b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] LM:GetTextInsertion [b][color=RED]([/color][/b] eList [b][color=RED])[/color][/b] [i][color=#990099];; © Lee Mac ~ 15.06.10[/color][/i] [b][color=RED]([/color][/b]dxf [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]vl-every[/color][/b] [b][color=DARKRED]'[/color][/b][b][color=BLUE]zerop[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]mapcar[/color][/b] [b][color=DARKRED]'[/color][/b]dxf [b][color=DARKRED]'[/color][/b][b][color=RED]([/color][/b][b][color=#009900]72[/color][/b] [b][color=#009900]73[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b][b][color=BLUE]list[/color][/b] elist elist[b][color=RED])[/color][/b][b][color=RED])[/color][/b] [b][color=RED])[/color][/b] [b][color=#009900]10[/color][/b] [b][color=#009900]11[/color][/b] [b][color=RED])[/color][/b] eList [b][color=RED])[/color][/b] [b][color=RED])[/color][/b] Quote Link to comment Share on other sites More sharing options...
zride91 Posted June 16, 2010 Author Share Posted June 16, 2010 Lee Mac, Thank you very much for your input! I have tried the code, and the scaling and rotation of the blocks come in great, but the location is not quite there. The insertion point of the blocks do not come in at the insertion points of the text. Lee Mac and Freerefill, thank you both so much! This is very cool. i'm looking forward to looking into this code in depth to see how it does what it does. Thanks Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 16, 2010 Share Posted June 16, 2010 Please try the updated code Quote Link to comment Share on other sites More sharing options...
zride91 Posted June 16, 2010 Author Share Posted June 16, 2010 Brilliant!! That worked Perfectly! Thank you so very much. I appreciate both of your time and efforts Freerefill and Lee Mac. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 16, 2010 Share Posted June 16, 2010 You're very welcome Quote Link to comment Share on other sites More sharing options...
bullah Posted July 6, 2012 Share Posted July 6, 2012 You're very welcome select pue for "block pue", put for "put block" puc for "puc DWG block" and so forth. can you help me. sorry Quote Link to comment Share on other sites More sharing options...
guigol Posted July 10, 2012 Share Posted July 10, 2012 Please try the updated code Thank you for your help. I'm trying to edit your code to obtain a result a little bit different. But it doesn't work. I have lot of plan with a lot of text scattered everywhere. I would like to replace text zone by this labelBARYCENTRE.dwg and text written in it. Do you see a solution? PS : Sorry for my poor english. Quote Link to comment Share on other sites More sharing options...
guigol Posted July 11, 2012 Share Posted July 11, 2012 Is anybody have a solution ? Quote Link to comment Share on other sites More sharing options...
asos2000 Posted July 12, 2012 Share Posted July 12, 2012 Thank you for your help. I'm trying to edit your code to obtain a result a little bit different. But it doesn't work. I have lot of plan with a lot of text scattered everywhere. Could you upload a file has both before and after Quote Link to comment Share on other sites More sharing options...
guigol Posted July 12, 2012 Share Posted July 12, 2012 here is 2 files before Test_Cad-1.dwg after Test_Cad-2.dwg block are _______placed at the same place _______the same color _______at the same size (or proportionnaly) 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.