elfert Posted February 1, 2012 Posted February 1, 2012 (edited) Hello Forum members i have made this routine that change the layer of object that the user select to layer AM_6_UK it also make the layer if it isn't on the drawing. But i wont it to be able to change the layer to bylayer of the mtext object and inside it and set the a single line text to bylayer. If the user select another object other then a mtext or single line text the routine should give a warning and start over again (loop) that could be a while function i think. ;Uk2 makes a layer AM_6_UK and moves a objekt from its current layer to layer AM_6_UK (defun C:uk2 (/ gp glag) (setvar "cmdecho" 0) ;;setting cmdecho zero (command "-color" "BYLAYER") (setq glag (getvar "clayer")) ;;Getting current Layer (if (not (tblsearch "LAYER" "AM_6_UK")) ;;checks if there is layer AM_6_UK in the drawing (Command "-layer" "n" "AM_6_UK" "c" "4" "AM_6_UK" "s" "AM_6_UK" "P" "P" "AM_6_UK" "LW" "0.35" "")) ;;Making of Layer AM_6_UK (setq gp (ssget)) ;; Get a objeckt and save in a selection set called gp (command "change" gp "" "P" "LA" "AM_6_UK" "C" "BYLAYER" "") ;; changing the object to layer "AM_6_UK". (command "-layer" "s" glag "" ) ;; changing back to start layer (princ "The last object that you selected has moved to layer AM_6_UK") (setvar "cmdecho" 1) ;;setting cmdecho one ) Yes i have looked at this routine: http://www.cadtutor.net/forum/showthread.php?40849-how-to-globally-change-text-color-to-by-layer-in-autocad-2008 but it is eating the last letter of the text and it also change the text globally. I only want to change the mtext that the user select. Any suggestions, help? Thx in advance. Edited February 1, 2012 by elfert Mis leading Quote
MSasu Posted February 2, 2012 Posted February 2, 2012 Not sure that understand what you are looking for - is about allowing the user to select only TEXT and MTEXT entities? If this is the case, please adjust your code as below: (setq gp (ssget '((0 . "TEXT,MTEXT")))) Regards, Mircea Quote
BlackBox Posted February 2, 2012 Posted February 2, 2012 (edited) Consider disallowing the user to select text entities on locked layers: (defun c:FOO ( / ss) (if (setq ss (ssget [color=red]"_:L"[/color] '((0 . "MTEXT,TEXT")))) ;; <-- Do something (prompt "\n** Nothing selected ** ")) (princ)) Edited February 2, 2012 by BlackBox Quote
elfert Posted February 2, 2012 Author Posted February 2, 2012 Sorry maybe i wasn't clear. When a Mtext is made inside of AC there is 2 places you can change the color to be bylayer 'Outside' of the mtext object and inside. Some of the drawings that we have made mtext objects on the color is bylayer but not inside. And thats i crap because we control the lineweight on the color henc the ctb.file and the color is control by the layer. This means when a user use routine it has to change the color to bylayer in mtext both inside and outside and color on text/dtext objects to bylayer. Hope this clearing some light what i need. thx. in advance. Quote
elfert Posted February 2, 2012 Author Posted February 2, 2012 (edited) I made the this revision: Basede on error message you wrote about. ;Uk2 moves a selected a mtext and text objekt to layer AM_6_UK if it is in the drawing (defun C:uk2 (/ gp glag) (setvar "cmdecho" 0) ;;setting cmdecho zero (command "-color" "BYLAYER") (setq glag (getvar "clayer")) ;;Getting current Layer (if (not (tblsearch "LAYER" "AM_6_UK")) ;;checks if there is layer AM_6_UK in the drawing (prompt "\n** No LAYER AM_6_UK is in drawing ** ");; gives a warning to the user. (command "-layer" "S" "AM_6_UK" ""));;setting to layer AM_6_UK (if (setq gp (ssget "_:L" '((0 . "MTEXT,TEXT")))) (command "change" gp "" "P" "LA" "AM_6_UK" "C" "BYLAYER" "") ;; changing the objects that was in selection set gp to layer "AM_6_UK". (Prompt "\n** Nothing selected **")) ;; Tel the user that that it wasen't a Mtext and text object they selected. (command "-layer" "s" glag "" ) ;; changing back to start layer (Prompt "\nThe last object that you selected has moved to layer AM_6_UK") (setvar "cmdecho" 1) ;;setting cmdecho one (princ) ) when there is no Layer AM_6_UK on the drawing It tells the user , but it still continues where it should stop. what to do? thx. in advance. Edited February 2, 2012 by elfert Mis leading Quote
MSasu Posted February 2, 2012 Posted February 2, 2012 If the color was set from inside the MText editor you can find that setting along the text content under DXF code 1 in associated list. You will find there one or more tag(s) like "\\C?;" where "?" is the index of the color. To set the string content to ByLayer you should remove those tags. (1 . "{\\C1;abc}") --> [color=red]abc[/color] (1 . "{\\C1;a\\C5;b\\C1;c}") --> [color=red]a[color=blue]b[/color]c[/color] Regards, Mircea Quote
elfert Posted February 2, 2012 Author Posted February 2, 2012 Sorry can't follow you can you give some example. A understood what Render man wrote. thx. in advance. Quote
MSasu Posted February 2, 2012 Posted February 2, 2012 Please check the topics under "Using AutoLISP to Manipulate AutoCAD Objects" in help. Regards, Mircea Quote
elfert Posted February 2, 2012 Author Posted February 2, 2012 I think i getting af clue now, i have seen that that if you change the color inside the mtext to other than bylayer it change something similar that you write. But if it is set to bylayer it only contains the raw text nothing like {\C2;text}. But how do i filter out the text only and put it in again so the color will be set to bylayer??? Maybe its possible to put it in a setq variable not sure!!??? Quote
MSasu Posted February 3, 2012 Posted February 3, 2012 If I were in your shoes, I will check if there are color tags in the string with WCMATCH function and if this is true I will parse it to locate and remove them - one solution is to add to a new string only the non color tag parts. Don't forget that the color may be stored on 1, 2 or 3 characters. Please take care to don't affect other tags (bold, italic, alignment...). Post here your progress and will try to help you debug it if case. This may get you started: (if (wcmatch MyMTextString "*\\C#*") [color=green]...your action here...[/color]) Regards, Mircea Quote
irneb Posted February 4, 2012 Posted February 4, 2012 I understand your pain, the colour set while editing the mtext actually modifies the text string to include some format code - like someone previously mentioned. This isn't a simple matter to undo. I think what you're after is a mtext format clearing routine, there's several out there. One I like is StripMText. After you've run it to clean up the color format codes inside the MText, you can then adjust their "outer" colour properties through the properties palette / SetBylayer command / any other way. Quote
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.