cl082000 Posted August 18, 2009 Share Posted August 18, 2009 I want a code that spits out calcs into MTEXT. Does not seem very hard but I cant seem finish it. Here is what I have so far. (defun c:davitcal (DAV) (setq Z (getreal "Enter pipe section modulus:" )) (setq W (getreal "Enter est. dead weight (FLG. + parts):" )) (setq L (getreal "Enter length of moment arm:" )) (setq S (getreal "Enter stress value for davit arm:" )) (setq a (getreal "Enter mtext corner:" )) (command "mtext" 0 a Z W L S) and it spits it out but it does not close mtext how do I fix that? also I if at all possible I would like the mtext to read as in its final form Z= (whatever the setq Z number is) W= (whatever the setq W number is) L= (whatever the setq L number is) S= (whatever the setq S number is) ie: Z=12.22 W=3800 L=45.3869 S=17100 as of right now it just spits out numbers If I have butchered anything I am sorry. This is all totally new to me. Thank you for your time and efforts. Any response is greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 18, 2009 Share Posted August 18, 2009 Not butchered too much - just misguided When it comes to creating text, I would not use a command method, but rather opt for either using entmake to create the text, or, even vla-addMText to create the text. Let me know if you need further advice in either of these methods. Lee Quote Link to comment Share on other sites More sharing options...
cl082000 Posted August 18, 2009 Author Share Posted August 18, 2009 Lee thank you so much for trying to help and also for not ripping my head off yes I would love some help on either one which ever is easiest to code. I will try to use them both before you respond. Thank you for your help. Quote Link to comment Share on other sites More sharing options...
cl082000 Posted August 18, 2009 Author Share Posted August 18, 2009 no luck at all using those commands you suggested help me out Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 18, 2009 Share Posted August 18, 2009 No problem - happy to help Ok, I shall explain a bit more. The reason that I veer away from the command-call methods is that, not only can they be affected by the drafting settings (i.e. OSnaps etc), but also, they prompts (especially for text/attdef/mtext commands) can be inconsistent from time to time, causing the program to crash half the time. Also, imo it is better programming not to use them Also, lets not forget that these methods are 10x faster than any command-call. Ok, so the alternatives... The entmake is probably the easiest route for you to follow, as it doesn't require any knowledge of Visual LISP, and you can use a DXF reference to help you. You will need to supply the entmake function with a list of dotted pairs, and with enough information for the entity to be created. To give you an example of what I mean by "dotted pairs", run this and click on some existing MTEXT: (defun c:test (/ ent) (if (setq ent (car (entsel "\nSelect MTEXT: "))) (foreach x (entget ent) (print x))) (textscr) (princ)) You will see a list of dotted pairs, containing all the information about that MTEXT Object. You can see what each item in the list refers to by looking here. So, to create the MTEXT using this method, you will need to construct yourself a list of dotted pairs. Most of the information is standard and won't change from object to object, but you can alter things like the insertion point, text height, content etc etc. Something like this for example: (entmake (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 410 "Model") (cons 8 "0") (cons 100 "AcDbMText") (cons 10 '(0 0 0)) (cons 40 2.5) (cons 71 1) (cons 72 5) (cons 1 "Lee Mac") (cons 7 "Verdana") (cons 11 '(1.0 0.0 0.0)))) You can see what each code is used for by looking at the reference supplied in the link above. As I have said, there is a minimum amount of infomation you have to provide for the entity to be created, but you can supply more, depending on how much you want to stray from the defaults. As for the vla-addMtext method, I won't go into this unless you want to use this method, as it is a lot more typing and needs a lot more background knowledge of the Visual LISP structures. Hope this helps, but if you are still stuck, just shout and I'll explain some more. Cheers, Lee Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 18, 2009 Share Posted August 18, 2009 no luck at all using those commands you suggested help me out Easy on there... a please wouldn't go a miss.. :wink: Quote Link to comment Share on other sites More sharing options...
cl082000 Posted August 18, 2009 Author Share Posted August 18, 2009 PLEASE PRETTY PLEASE !!!!!!! AND THANK YOU TOO So I understand the paired dots. how do i get the setq variable numerical value I set in the start of the routine into the MTEXT? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 18, 2009 Share Posted August 18, 2009 PLEASE PRETTY PLEASE !!!!!!! AND THANK YOU TOO So I understand the paired dots. how do i get the setq variable numerical value I set in the start of the routine into the MTEXT? Sorry, I just thought your last reply was pretty blunt, 's all. Ok, to construct the MTEXT how you want it, something like this perhaps: (defun c:davitcal (/ z w l s a) (setq Z (getreal "Enter pipe section modulus:")) (setq W (getreal "Enter est. dead weight (FLG. + parts):")) (setq L (getreal "Enter length of moment arm:")) (setq S (getreal "Enter stress value for davit arm:")) (setq a (getreal "Enter mtext corner:")) (entmake (list (cons 0 "MTEXT") ;; Entity Name (cons 100 "AcDbEntity") ;; Subclass Marker (cons 410 "Model") ;; Space (cons 8 "0") ;; Layer (cons 100 "AcDbMText") ;; Subclass Marker (cons 10 '(0 0 0)) ;; Insertion Point (cons 40 2.5) ;; Text Height (cons 71 1) ;; Attachment Point (top-left) (cons 1 (rtos Z)) ;; Text Content (cons 7 "Verdana"))) ;; Text Style (princ)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 18, 2009 Share Posted August 18, 2009 No, DAV means that the function requires 1 argument to be supplied when invoked. The keyboard syntax is the string that follows (defun c:... Have a good read of this: http://www.afralisp.net/lispa/lisp5.htm Quote Link to comment Share on other sites More sharing options...
cl082000 Posted August 18, 2009 Author Share Posted August 18, 2009 Thank you for the read. Help me understand that a tab bit more. run this code: (defun c:davitcal (/ z w l s) (setq Z (getreal "Enter pipe section modulus:")) (setq W (getreal "Enter est. dead weight (FLG. + parts):")) (setq L (getreal "Enter length of moment arm:")) (setq S (getreal "Enter stress value for davit arm:")) (entmake (list (cons 0 "MTEXT") ;; Entity Name (cons 100 "AcDbEntity") ;; Subclass Marker (cons 410 "Model") ;; Space (cons 8 "0") ;; Layer (cons 100 "AcDbMText") ;; Subclass Marker (cons 10 '(5.0 3.0 0)) ;; Insertion Point (cons 40 0.1) ;; Text Height (cons 71 5) ;; Attachment Point (Mid-Cent) (cons 1 "Z=(rtos Z)IN\\PW=(rtos W)#\\PL=(rtos L)IN\\PS=(rtos S)PSI") ;; Text Content (cons 7 "STANDARD"))) ;; Text Style (princ)) Notice that when the text is formed( which you are awesome my frined for getting me this far) that its formatted exactly how I want it BUT, the (rtos) values do not show up? Can you get the values to show up with the other text infront and behind it still reading? That should be the last fix.... Thank you again so much for helping me thru this. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 18, 2009 Share Posted August 18, 2009 Not a problem mate, You need to remember that functions won't evaluate within string literals - hence strcat is needed to concatenate the strings: (defun c:davitcal (/ z w l s) (setq Z (getreal "Enter pipe section modulus:")) (setq W (getreal "Enter est. dead weight (FLG. + parts):")) (setq L (getreal "Enter length of moment arm:")) (setq S (getreal "Enter stress value for davit arm:")) (entmake (list (cons 0 "MTEXT") ;; Entity Name (cons 100 "AcDbEntity") ;; Subclass Marker (cons 410 "Model") ;; Space (cons 8 "0") ;; Layer (cons 100 "AcDbMText") ;; Subclass Marker (cons 10 '(5.0 3.0 0)) ;; Insertion Point (cons 40 0.1) ;; Text Height (cons 71 5) ;; Attachment Point (Mid-Cent) (cons 1 (strcat "Z="(rtos Z)"IN\\PW="(rtos W)"#\\PL="(rtos L)"IN\\PS="(rtos S)"PSI")) ;; Text Content (cons 7 "STANDARD"))) ;; Text Style (princ)) Quote Link to comment Share on other sites More sharing options...
cl082000 Posted August 18, 2009 Author Share Posted August 18, 2009 DUDE YOU ARE THE MAN!!!!!!!! Thank you I got what I want I am sure I will be calling on you again real soon Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 18, 2009 Share Posted August 18, 2009 Happy to help mate Quote Link to comment Share on other sites More sharing options...
cl082000 Posted August 19, 2009 Author Share Posted August 19, 2009 Lee my friend, routine is working well. I have added some more things to it. I ventured off course and got lost again. Do you mind taking a look please Sir. (defun c:davittext () (setq D (getstring 1 "Enter davit arm material:")) (entmake (list (cons 0 "MTEXT") ;; Entity Name (cons 100 "AcDbEntity") ;; Subclass Marker (cons 410 "Layout") ;; Space (cons 8 "Text") ;; Layer (cons 100 "AcDbMText") ;; Subclass Marker (cons 10 '(5.0 1.0 0)) ;; Insertion Point (cons 40 0.125) ;; Text Height (cons 71 5) ;; Justify (Mid-Cent) (cons 1 (strcat (rtos D)" {\\ADEQUATE}")) ;; Text ConteT (cons 7 "STANDARD"))) ;; Text Style (princ)) It will not spitout the MTEXT. It should read if setq d= 6" S/80 PIPE: 6" S/80 PIPE ADEQUATE Please tell me where I am going wrong? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 19, 2009 Share Posted August 19, 2009 The variable "D" is not a number, but a string, so no need for rtos: (defun c:davittext (/ d) (setq D (getstring t "Enter davit arm material:")) (entmake (list (cons 0 "MTEXT") ;; Entity Name (cons 100 "AcDbEntity") ;; Subclass Marker (cons 410 "Layout") ;; Space (cons 8 "Text") ;; Layer (cons 100 "AcDbMText") ;; Subclass Marker (cons 10 '(5.0 1.0 0)) ;; Insertion Point (cons 40 0.125) ;; Text Height (cons 71 5) ;; Justify (Mid-Cent) [color=Red][b] (cons 1 (strcat D " {\\LADEQUATE}")) ;; Text ConteT[/b][/color] (cons 7 "STANDARD"))) ;; Text Style (princ)) Quote Link to comment Share on other sites More sharing options...
cl082000 Posted August 19, 2009 Author Share Posted August 19, 2009 Thank you kindly Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 19, 2009 Share Posted August 19, 2009 Not a problem 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.