JerryFiedler Posted April 11, 2021 Posted April 11, 2021 Greetings, I am trying to create an MTEXT but I am getting an error "Bad group 10". I have tried various ways to enter the insertion point but I always get an error. (setq pt (getpoint "\nInsertion point: ")) (entmake '( (0 . "MTEXT") (1 . "test") (10 . (car pt)) (20 . (cadr pt)) (30 . 0.0) (41 . 1.5) ) ) I have tried to put x y z in group 10 but that also failed. How should the insertion point be entered? This is only one step toward my goal. What I actually want to do is: 1) Pick a point 2) Have the lisp insert a blank mtext 3) Have the lisp open the ddedit box 4) Let me enter my text So, my goal is with just one click I can begin to type in the edit box. Quote
rlx Posted April 11, 2021 Posted April 11, 2021 dont use quote , that is ' ( (0 . "MTEXT" but list. When you use the quote character something like (10 . (car pt)) is also quoted and not evaluated. you can use (list '(0 . "MTEXT") but use (cons 10 (car pt)) because (car pt) has to be evaluated first Quote
Lee Mac Posted April 11, 2021 Posted April 11, 2021 (edited) My tutorial on The Apostrophe and the Quote Function may help to illustrate the main source of the problem regarding the unevaluated expressions within your literal list, however, you should also only use DXF group 10 to define the 3D coordinates representing MText insertion point - DXF group codes 20 & 30 are only used by the DXF file format, in which only a single value is permitted to be associated with each DXF group. Edited April 11, 2021 by Lee Mac 1 Quote
BIGAL Posted April 11, 2021 Posted April 11, 2021 This is another example with some more options, including setting alignment. Note pt (defun AH:mtext (pt hgt str ang lr lor ) (entmake (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 8 ah:labellay) (cons 42 1) (cons 43 0) (cons 44 1) (cons 7 ah:txtsty) (cons 1 str) (cons 10 pt) (cons 11 (list 0.0 0.0 0.0)) (cons 210 (list 0.0 0.0 1.0)) (cons 40 hgt) (cons 50 ang) (cons 71 lr) (cons 72 lor) ) ) ) Adding a background mask (defun AH:BG (/ obj ent data elist mtwidth) (entmod (subst '(41 . 0.) (assoc 41 (setq data (entget (setq ent (entlast))))) data)) (setq obj (vlax-ename->vla-object ent)) (if (= (vlax-get-property obj 'BackgroundFill) :vlax-true) (vlax-put-property obj 'BackgroundFill :vlax-false) (progn (vlax-put-property obj 'BackgroundFill :vlax-true) (setq ent (vlax-vla-object->ename obj) elist (entget ent) elist (subst (cons 90 3)(assoc 90 elist) elist) ;Use drawing background color elist (subst (cons 45 1.5) (assoc 45 elist) elist) ;Set 'Border Offset Factor' to 1.5 mtwidth (* (cdr (assoc 42 elist))1.015) elist (subst (cons 41 mtwidth)(assoc 41 elist) elist) ;Trim excess width ) (entmod elist) ) ; progn ) (vl-cmdf "_draworder" ent "" "f") (princ) ) Quote
JerryFiedler Posted April 12, 2021 Author Posted April 12, 2021 rlx, Thank you for explaining the quote issue. Lee Mac, Thank you for your terrific tutorial. I read this maybe a year ago but I keep forgetting the single quote indicates a literal list and nothing is evaluated. Thanks for clearing up the group 10 20 30 issue. Big Al, Thank you for your example entmake. I have tried it, more or less, just as you have it written but mine does not work. Obviously it is the "more or less" that I screwed up. I get no errors with my code but the "entmake" does not appear to create anything so it must be returning a nil. The line of code following the entmake opens an MTEXT that I had previously entered manually, that is using the standard MTEXT command. What I want is the "Last" entity to be the one created by entmake. Why does my entmake fail? (setq pt (getpoint "\nInsertion point: ")) (entmake (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") ;Why two 100's? (cons 100 "AcDbMTEXT") (cons 8 "TD") (cons 42 1) ;Read only, ignored (cons 43 0) ;Read only, ignored (cons 44 1.0) (cons 7 "STANDARD") (cons 1 "test string") (cons 10 pt) (cons 11 (list 0.0 0.0 0.0)) ;Ignored when group 50 is used. (cons 210 (list 0.0 0.0 1.0)) ;Optional (cons 40 0.1) (cons 50 0.0) (cons 71 1) (cons 72 5) (cons 41 1.5) ;Width of box ) ) (command "TEXTEDIT" (ssget "_L")) Quote
rlx Posted April 12, 2021 Posted April 12, 2021 maybe try moving your 10 / 11 groups right after (cons 100 "AcDBMtext"). Often the order or dxf groups matters. just a random section from one of my app's (RlxMas to be exactly , posted here a couple of years ago) (setq elist (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 10 %pnt) (cons 1 msg) '(90 . 1) (cons 63 #bgc) (cons 40 (/ (getvar "VIEWSIZE") 30.0)) (cons 71 atc) '(72 . 5) '(441 . 0) )) (setq mobj (vlax-ename->vla-object (entmakex elist))) and thank you for adressing all who responded to your thread , not everybody is this polite anymore 2 Quote
JerryFiedler Posted April 12, 2021 Author Posted April 12, 2021 rlx, I tried rearranging the group codes by putting them in the order they are listed on the following website. http://docs.autodesk.com/ACD/2011/ENU/filesDXF/WS1a9193826455f5ff18cb41610ec0a2e719-79f8.htm I could not find a more recent date. Although I doubt things would be much different than in 2011. Even with the rearranged list I do not get a new entity. This seems like such a simple thing. Here is my latest version: (setq pt (getpoint "\nInsertion point: ")) (entmake (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMTEXT") (cons 10 pt) '(40 . 0.1) '(41 . 1.5) '(71 . 1) '(72 . 5) (cons 1 "x") '(50 . 0.0) '(44 . 1.0) ) ) (command "TEXTEDIT" (ssget "_L")) Thank you for helping me. Quote
Tharwat Posted April 12, 2021 Posted April 12, 2021 (edited) "AcDbMTEXT" must be "AcDbMText" Edit: all credits to @rlx for the good example he offered. Edited April 12, 2021 by Tharwat 1 1 Quote
rlx Posted April 12, 2021 Posted April 12, 2021 No Tharwat , I completly missed the upper / lower case issue , you eagle eyed genius! 1 Quote
JerryFiedler Posted April 13, 2021 Author Posted April 13, 2021 Tharwat, My code works with the upper/lower change you suggested!! Thank you so very much. I simply don't know when autolisp/AutoCAD is case sensitive. For me it is always trial-and-error; with the emphasis on "error". Have a good day! Quote
Steven P Posted April 13, 2021 Posted April 13, 2021 18 hours ago, JerryFiedler said: I tried rearranging the group codes by putting them in the order they are listed on the following website. http://docs.autodesk.com/ACD/2011/ENU/filesDXF/WS1a9193826455f5ff18cb41610ec0a2e719-79f8.htm I could not find a more recent date. Although I doubt things would be much different than in 2011. Even with the rearranged list I do not get a new entity. This seems like such a simple thing. Here is my latest version: When i have been doing this recently I drew the object type I wanted (in this case made up a piece of MText) and put this into the command line (entget(entlast)) which lists it all in the correct order and so you should be able to get the order correct from that. If it still doesn't work I use Lee Macs list had put out here somewhere of the minimum group codes needed to create the object and build it up from there, trial and error till I find what doesn't work (Mtext is 0, 100, 100, 10, 1).... appreciating that the eagle eyed above spotted the problem already, but this might help for the future. Quote
BIGAL Posted April 13, 2021 Posted April 13, 2021 (edited) I got this from somewhere and often refer to it, originally by Lee-Mac 2010 ; Entmake examples by Lee-mac 2010 (defun 3DFace (p1 p2 p3 p4) (entmakex (list (cons 0 "3DFACE") (cons 10 p1) (cons 11 p2) (cons 12 p3) (cons 13 p4)))) (defun Arc (cen rad sAng eAng) (entmakex (list (cons 0 "ARC") (cons 10 cen) (cons 40 rad) (cons 50 sAng) (cons 51 eAng)))) (defun AttDef (tag prmpt def pt hgt flag) (entmakex (list (cons 0 "ATTDEF") (cons 10 pt) (cons 40 hgt) (cons 1 def) (cons 3 prmpt) (cons 2 tag) (cons 70 flag)))) (defun Circle (cen rad) (entmakex (list (cons 0 "CIRCLE") (cons 10 cen) (cons 40 rad)))) (defun Ellipse (cen maj ratio) (entmakex (list (cons 0 "ELLIPSE") (cons 100 "AcDbEntity") (cons 100 "AcDbEllipse") (cons 10 cen) (cons 11 maj) (cons 40 ratio) (cons 41 0) (cons 42 (* 2 pi))))) (defun Insert (pt Nme) (entmakex (list (cons 0 "INSERT") (cons 2 Nme) (cons 10 pt)))) (defun Line (p1 p2) (entmakex (list (cons 0 "LINE") (cons 10 p1) (cons 11 p2)))) (defun LWPoly (lst cls) (entmakex (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 (length lst)) (cons 70 cls)) (mapcar (function (lambda (p) (cons 10 p))) lst)))) (defun M-Text (pt str) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 pt) (cons 1 str)))) (defun Point (pt) (entmakex (list (cons 0 "POINT") (cons 10 pt)))) (defun Polyline (lst) (entmakex (list (cons 0 "POLYLINE") (cons 10 '(0 0 0)))) (mapcar (function (lambda (p) (entmake (list (cons 0 "VERTEX") (cons 10 p))))) lst) (entmakex (list (cons 0 "SEQEND")))) (defun Solid (p1 p2 p3 p4) (entmakex (list (cons 0 "SOLID") (cons 10 p1) (cons 11 p2) (cons 12 p3) (cons 13 p4)))) (defun Text (pt hgt str) (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 40 hgt) (cons 1 str)))) (defun Trce (p1 p2 p3 p4) (entmakex (list (cons 0 "TRACE") (cons 10 p1) (cons 11 p2) (cons 12 p3) (cons 13 p4)))) (defun xLine (pt vec) (entmakex (list (cons 0 "XLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbXline") (cons 10 pt) (cons 11 vec)))) (defun Layer (Nme) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 Nme) (cons 70 0)))) (defun Layer (Nme Col Ltyp LWgt Plt) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 Nme) (cons 70 0) (cons 62 Col) (cons 6 Ltyp) (cons 290 Plt) (cons 370 LWgt)))) Edited April 15, 2021 by BIGAL 1 Quote
Lee Mac Posted April 14, 2021 Posted April 14, 2021 It's really old now and probably needs to be updated: 1 1 Quote
JerryFiedler Posted April 14, 2021 Author Posted April 14, 2021 Lee, Thanks for sharing your old post. Why is it that some entities do not have group 100 entry? While I wait for your answer I'll see what Google has to say. Quote
Lee Mac Posted April 14, 2021 Posted April 14, 2021 (edited) 2 hours ago, JerryFiedler said: Lee, Thanks for sharing your old post. Why is it that some entities do not have group 100 entry? While I wait for your answer I'll see what Google has to say. I believe entity types which predate R13 did not require or make use of the group 100 subclass markers, therefore (and per the documentation), for backwards compatibility, AutoCAD will ignore DXF group 100 for the following entities: Quote AcDbText AcDbAttribute AcDbAttributeDefinition AcDbBlockBegin AcDbBlockEnd AcDbSequenceEnd AcDbBlockReference AcDbMInsertBlock AcDb2dVertex AcDb3dPolylineVertex AcDbPolygonMeshVertex AcDbPolyFaceMeshVertex AcDbFaceRecord AcDb2dPolyline AcDb3dPolyline AcDbArc AcDbCircle AcDbLine AcDbPoint AcDbFace AcDbPolyFaceMesh AcDbPolygonMesh AcDbTrace AcDbSolid AcDbShape AcDbViewport As such, entity types which do not feature in the above list will require the appropriate DXF group 100 subclass markers to be present in the DXF data supplied to the entmake/entmakex functions - it is also worth noting that since the entmake/entmakex functions are capable of generating non-graphical entities (e.g. Layers, Dictionaries etc.) both subclass markers are required because not all entities will derive from the AcDbEntity class. Edited April 14, 2021 by Lee Mac 1 Quote
BIGAL Posted April 15, 2021 Posted April 15, 2021 Thanks Lee will add your name to the file and post. 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.