Jamesclark64 Posted February 21, 2023 Posted February 21, 2023 Bit of a weird one as I already have a solution to my original question thanks to Steven P. However whilst I was looking elyosua suggested a bit of code that would be a really elegant solution, however I could never quite get it to work. Instead of creating the text in my drawing it just creates the text in the command line. Can anyone help me as its really been bugging me (DEFUN c:test (/ op height mens) (SETVAR "cmdecho" 0) (IF op0 () (SETQ op0 "USB") ) (SETQ mens (STRCAT "\nSelect option [USB/Wall/Fence] <" op0 ">: " ) ) (INITGET "USB Wall Fence") (IF (SETQ op (GETKWORD mens)) () (SETQ op op0) ) (SETQ op0 op) (IF height0 () (SETQ height0 0.05) ) (SETQ mens (STRCAT "\nEnter height <" (RTOS height0 2 2) ">: " ) ) (INITGET (+ 2 4)) (IF (SETQ height (GETDIST mens)) () (SETQ height height0) ) (SETQ height0 height) (PRINC (STRCAT "\nText = " op " " (RTOS height 2 2) "m")) (SETVAR "cmdecho" 1) (PRIN1) ) Quote
Tharwat Posted February 21, 2023 Posted February 21, 2023 You did not mention what you are trying to achieve but anyway here is a decent way to tidy your codes up in another way with a clearer reading method for newbies. (defun c:test nil (and (or usb (setq usb "USB")) (or hgt (SETQ hgt 0.05)) (or (initget "USB Wall Fence") (setq usb (cond ((getkword (strcat "\nSelect option [USB/Wall/Fence] <" usb ">: "))) (usb))) ) (or (initget 6) (setq hgt (cond ((getdist (strcat "\nEnter height <" (rtos hgt 2 2) ">: "))) (hgt))) ) (princ (strcat "\nText = " usb " " (rtos hgt 2 2) " m")) ) (princ) ) Quote
Steven P Posted February 21, 2023 Posted February 21, 2023 If I remember the code I gave had a sub-function, make text, fairly standard stuff and maybe worth copying to be a LISP on its own. You'll need a command to tell the LISP to make text. (defun MakeText ( MyText TextPoint textHeight / ) ; Sub Function (entmake (list '(0 . "TEXT") '(100 . "AcDbEntity") '(8 . "0") '(100 . "AcDbText") (cons 10 TextPoint) (cons 40 textheight) ;; '(46 . 0.0) (cons 1 MyText) '(50 . 0.0) '(41 . 1.0) '(51 . 0.0) ;; (cons 7 font) '(71 . 0) '(72 . 0) '(11 0.0 0.0 0.0) '(210 0.0 0.0 1.0) '(100 . "AcDbText") '(73 . 0) ));end list, entmake ) Then for your last line: (PRINC (STRCAT "\nText = " op " " (RTOS height 2 2) "m")) make this into a variable for example, and use that to make the text as above. Perhaps this. The 2.5 is the text height you can change that to suit you. (SETQ MYTEXT (STRCAT "\nText = " op " " (RTOS height 2 2) "m")) (SETQ MYPT (GETPOINT "SELECT TEXT POSITION")) (MakeText MYTEXT MYPT 2.5) (PRINC MYTEXT) This should let you make text in the drawing You can modify and add that to the last part of Tharwats code to make text in the drawing 1 Quote
Jamesclark64 Posted February 21, 2023 Author Posted February 21, 2023 5 hours ago, Steven P said: If I remember the code I gave had a sub-function, make text, fairly standard stuff and maybe worth copying to be a LISP on its own. You'll need a command to tell the LISP to make text. (defun MakeText ( MyText TextPoint textHeight / ) ; Sub Function (entmake (list '(0 . "TEXT") '(100 . "AcDbEntity") '(8 . "0") '(100 . "AcDbText") (cons 10 TextPoint) (cons 40 textheight) ;; '(46 . 0.0) (cons 1 MyText) '(50 . 0.0) '(41 . 1.0) '(51 . 0.0) ;; (cons 7 font) '(71 . 0) '(72 . 0) '(11 0.0 0.0 0.0) '(210 0.0 0.0 1.0) '(100 . "AcDbText") '(73 . 0) ));end list, entmake ) Then for your last line: (PRINC (STRCAT "\nText = " op " " (RTOS height 2 2) "m")) make this into a variable for example, and use that to make the text as above. Perhaps this. The 2.5 is the text height you can change that to suit you. (SETQ MYTEXT (STRCAT "\nText = " op " " (RTOS height 2 2) "m")) (SETQ MYPT (GETPOINT "SELECT TEXT POSITION")) (MakeText MYTEXT MYPT 2.5) (PRINC MYTEXT) This should let you make text in the drawing You can modify and add that to the last part of Tharwats code to make text in the drawing Okay I'm lost. I tried a separate lisp for the make text section but it resulted in (; error: too few arguments) so I tried adding your code to Tharwats and I got (; error: bad argument type: numberp: nil) I think it goes without saying my lisp skills are very basic. Quote
Tharwat Posted February 22, 2023 Posted February 22, 2023 Something like this ? (defun c:test ( / ins ) ;;----------------------------------------------------;; ;; Author : Tharwat Al Choufi ;; ;; website: https://autolispprograms.wordpress.com ;; ;;----------------------------------------------------;; (and (or usb (setq usb "USB")) (or hgt (setq hgt 0.05)) (or (initget "USB Wall Fence") (setq usb (cond ((getkword (strcat "\nSelect option [USB/Wall/Fence] <" usb ">: "))) (usb))) ) (or (initget 6) (setq hgt (cond ((getdist (strcat "\nEnter height <" (rtos hgt 2 2) ">: "))) (hgt))) ) (princ (strcat "\nText = " usb " " (rtos hgt 2 2) " m")) (setq ins (getpoint "\nSpecify text insertion point : ")) (entmake (list '(0 . "TEXT") (cons 10 ins) (cons 40 hgt) (cons 1 (strcat "Text = " usb " " (rtos hgt 2 2) " m")) '(50 . 0.0) )) ) (princ) ) Quote
Jamesclark64 Posted February 22, 2023 Author Posted February 22, 2023 49 minutes ago, Tharwat said: Something like this ? (defun c:test ( / ins ) ;;----------------------------------------------------;; ;; Author : Tharwat Al Choufi ;; ;; website: https://autolispprograms.wordpress.com ;; ;;----------------------------------------------------;; (and (or usb (setq usb "USB")) (or hgt (setq hgt 0.05)) (or (initget "USB Wall Fence") (setq usb (cond ((getkword (strcat "\nSelect option [USB/Wall/Fence] <" usb ">: "))) (usb))) ) (or (initget 6) (setq hgt (cond ((getdist (strcat "\nEnter height <" (rtos hgt 2 2) ">: "))) (hgt))) ) (princ (strcat "\nText = " usb " " (rtos hgt 2 2) " m")) (setq ins (getpoint "\nSpecify text insertion point : ")) (entmake (list '(0 . "TEXT") (cons 10 ins) (cons 40 hgt) (cons 1 (strcat "Text = " usb " " (rtos hgt 2 2) " m")) '(50 . 0.0) )) ) (princ) ) This is really cool! and getting very close to what I'm trying to achieve. I don't want it to scale the text size to whatever the input is I normally have my textsize set to 0.14. The only other thing is I don't need "Text =" to be in the final output but I reckon I could figure that last one out myself Quote
Tharwat Posted February 22, 2023 Posted February 22, 2023 Simply replace the text height with your desired one and delete the prefix from the text string as follows: (defun c:test ( / ins ) ;;----------------------------------------------------;; ;; Author : Tharwat Al Choufi ;; ;; website: https://autolispprograms.wordpress.com ;; ;;----------------------------------------------------;; (and (or usb (setq usb "USB")) (or hgt (setq hgt 0.05)) (or (initget "USB Wall Fence") (setq usb (cond ((getkword (strcat "\nSelect option [USB/Wall/Fence] <" usb ">: "))) (usb))) ) (or (initget 6) (setq hgt (cond ((getdist (strcat "\nEnter height <" (rtos hgt 2 2) ">: "))) (hgt))) ) (princ (strcat "\nText = " usb " " (rtos hgt 2 2) " m")) (setq ins (getpoint "\nSpecify text insertion point : ")) (entmake (list '(0 . "TEXT") (cons 10 ins) (cons 40 0.14) (cons 1 (strcat usb " " (rtos hgt 2 2) " m")) '(50 . 0.0) )) ) (princ) ) Quote
Jamesclark64 Posted February 22, 2023 Author Posted February 22, 2023 21 minutes ago, Tharwat said: Simply replace the text height with your desired one and delete the prefix from the text string as follows: (defun c:test ( / ins ) ;;----------------------------------------------------;; ;; Author : Tharwat Al Choufi ;; ;; website: https://autolispprograms.wordpress.com ;; ;;----------------------------------------------------;; (and (or usb (setq usb "USB")) (or hgt (setq hgt 0.05)) (or (initget "USB Wall Fence") (setq usb (cond ((getkword (strcat "\nSelect option [USB/Wall/Fence] <" usb ">: "))) (usb))) ) (or (initget 6) (setq hgt (cond ((getdist (strcat "\nEnter height <" (rtos hgt 2 2) ">: "))) (hgt))) ) (princ (strcat "\nText = " usb " " (rtos hgt 2 2) " m")) (setq ins (getpoint "\nSpecify text insertion point : ")) (entmake (list '(0 . "TEXT") (cons 10 ins) (cons 40 0.14) (cons 1 (strcat usb " " (rtos hgt 2 2) " m")) '(50 . 0.0) )) ) (princ) ) You absolute genius! How can I gift you a few beers? what's the best place for me to learn this stuff for myself so i don't have to keep hassling everyone with all the simple stuff. Quote
Tharwat Posted February 22, 2023 Posted February 22, 2023 (edited) Thanks, I am glad you got it the way you want it, and here is my website if you would like to deliver any bills. https://autolispprograms.wordpress.com/send-payment-2/ Edited February 22, 2023 by Tharwat Quote
devitg Posted February 22, 2023 Posted February 22, 2023 2 hours ago, Jamesclark64 said: what's the best place for me to learn this stuff for myself so i don't have to keep hassling everyone with all the simple stuff. My first LISp handbook . RON LEIGH CURSO LISP.doc 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.