ManiacalDigits Posted January 31 Posted January 31 I am trying to place some notes in my drawing. I have values and labels in a list that I make into a string. I am using MText because it has the columns property and I thought "that would be convenient". Yeah, not so much. (setq myTextInfo (list "Bays -" numbays "Baywidth -" baywidth "Spine -" spine "Hinge -" hinge "Little Spine -" lspine "Rib Bar -" ribbar "Rib Length -" riblength "Number of Ribs -" ribs "Propbars -" propbars)) (setq myTextStr (vl-princ-to-string myTextInfo)) (vl-load-com) ;; This example creates an MText object in model space. (setq myTextObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument myTextObj)) ;; Define the multiline text object (setq corner (vlax-3d-point 48 88 0) textwidth 30 text myTextStr) ;; Creates the mtext Object (setq modelSpace (vla-get-ModelSpace doc)) (setq MTextObj (vla-AddMText modelSpace corner textwidth text)) This works to display the string but of course its not 2 columns and the columns property cannot be changed from the properties tab. So after reading all day and trying a bunch of options I'm stuck. I guess if I have to make this with entmake I will but have had 0 success with it. I know the elist values I want to set are 75 and 76 but have no idea what to set them to. And what else must be defined? Really struggling with LISP syntax. Can anyone help? TIA! mtext_example.dwg Quote
pkenewell Posted January 31 Posted January 31 @ManiacalDigits Yep looks like you have to use entmake. Here is some old entmake code i have for making MTEXT that I altered to add columns. It kinda works, but I don't know how to set the column height and some other options. Feel free to hack it up as you see fit. I don't have full information on column creation because the DXF reference is not very informative on some things. I'll keep looking into it, but not finding much so far. Perhaps someone else may have more info on it. ;; Arguments: ;; pt = list; Insertion Point ;; wid = real: Mtext width ;; str = string; The text string to display ;; just = string; represents the justification, see options in (justcode) sub-function. ;; cols = integer; number of columns to display (defun Add-Mtext (pt wid str just cols / justcode lyr sty hgt strlst left len elst) ;; Sub-function to convert a string representing a justification into the actual enum. (defun justcode (just / ret) (setq just (strcase just)) (cond ((= just "LEFT") 1) ((= just "RIGHT") 3) ((= just "CENTER") 2) ((= just "TL") 2) ((= just "TC") 2) ((= just "TR") 3) ((= just "ML") 4) ((= just "MC") 5) ((= just "MR") 6) ((= just "BL") 7) ((= just "BC") 8) ((= just "BR") 9) (T nil) ) ) (setq lyr (getvar "clayer") sty (getvar "textstyle") hgt (getvar "textsize") just (if just (justcode just) 1) cols (if cols cols 1) wid (if wid wid 0.0) ) (if (and pt str) (progn (if (<= (strlen str) 250) (setq strlst (list (cons 1 str))) (progn (setq left 1 len (strlen str) strlst nil) (while (> len 250) (setq tstr (substr str left 250) strlst (append strlst (list (cons 3 tstr))) left (+ left 250) len (- len 250) ) ) (setq strlst (append strlst (list (cons 1 (substr str left))))) ) ) (setq elst (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 pt) (cons 40 hgt) (cons 7 sty) (cons 41 wid) (cons 71 just) (cons 72 5) (cons 11 (list 1.0 0.0 0.0)) (cons 50 0.0) (cons 8 lyr) (cons 75 1);; Column Type: Dynamic, Auto Height (cons 76 cols);; Number of Columns (cons 48 (if (> wid 0.0)(/ wid cols) 0.0));; Column width ) elst (append elst strlst) ) (entmake elst) ) ) ) Quote
BIGAL Posted January 31 Posted January 31 (edited) Are you trying to do this, if so just use strcat and a "\\P" for each newline. (setq myTextInfo "Bays -3 \\PBaywidth -10 \\PSpine -5 \\PHinge -6\\PLittle Spine -22\\PRib Bar -xx\\PRib Length - 56\\PNumber of Ribs -22\\PPropbars - 12") (setq myTextObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument myTextObj)) (setq corner (vlax-3d-point 48 88 0) textwidth 30) (setq modelSpace (vla-get-ModelSpace doc)) (setq MTextObj (vla-AddMText modelSpace corner textwidth mytextinfo)) Just change the mytextinfo to strcat your variables. Edited January 31 by BIGAL Quote
pkenewell Posted February 1 Posted February 1 (edited) @ManiacalDigits To add to what BIGAL noted, if that is what you are actually trying to do, you can also get "Columns" by using TAB codes or "\t" to align the text up into columns. You just have to figure out how many tabs are needed based on the length of the prefix. look at the following - it adds the proper number of tabs and a return code "\\P" into the string list. (setq myTextInfo (list "Bays -\t\t\t\\P" numbays "Baywidth -\t\t\\P" baywidth "Spine -\t\t\t\\P" spine "Hinge -\t\t\t\\P" hinge "Little Spine -\t\t\\P" lspine "Rib Bar -\t\t\\P" ribbar "Rib Length -\t\t\\P" riblength "Number of Ribs -\t\\P" ribs "Propbars -\t\t\\P" propbars ) ) Edited February 1 by pkenewell Quote
ManiacalDigits Posted February 1 Author Posted February 1 (edited) @BIGAL@pkenewellpfft! :< yes. ty. damn so if i wanted to be less stupid, and learn what you guys know where would be the best place to start? cuz... wow Edited February 1 by ManiacalDigits Quote
pkenewell Posted February 1 Posted February 1 18 minutes ago, ManiacalDigits said: @BIGAL@pkenewellpfft! :< yes. ty. damn so if i wanted to be less stupid, and learn what you guys know where would be the best place to start? cuz... wow There are tons of resources out there. Here are some links to get you started (not in order of complexity): https://www.cadtutor.net/tutorials/autolisp/quick-start.php https://www.lee-mac.com/tutorials.html https://lispexpert.blogspot.com/p/blog-page_16.html https://www.afralisp.net/autolisp/tutorials/index.php?category_id=1 https://www.jefferypsanders.com/autolisptut.html https://blog.draftsperson.net/good-autolisp-programming-techniques/ https://autolispcourse.com/category/tutorials/ 1 Quote
BIGAL Posted February 1 Posted February 1 It is not a overnight learning process but Google is your friend, there are many forums out there with a Lisp section and you will find so many examples to learn from. When googling ask question and add "Autocad Lisp" eg "export attributes to excel autocad lisp" I like many others support people having a go at coding rather than "do this for me". Avoid CHATGP as its not up to scratch and produces a lot of incorrect code. There are a lot of books out there also and these days are electronic so can copy code, I have books from Kindle very cheap. 2 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.