ktbjx Posted March 27, 2017 Posted March 27, 2017 im trying to make a lisp routine to make the texts i attached but i dont know how... so far these is what i got: (defun c:txtTest (/) (setq pt (getpoint "\nPick Point >")) (setq d (getString "\nEnter Distance >")) (setq Au (getString "\nEnter Au >")) (vl-cmdf "_Text" pt 2.5 "" (strcat "" d "m@")) (vl-cmdf "_Text" (mapcar '+ '(5.0 0.0 0.0) pt) 2.5 "" (strcat "" Au "g/t Au"))) while doing this i realized IDK how to get the length of the first text so i can know where to put the 2nd text. second realization is that i dont know how to put a line! lol! could someone help me? i have no idea about AUTOLISP, i'm trying to self learn though... TextTest.dwg Quote
Hippe013 Posted March 27, 2017 Posted March 27, 2017 (edited) There are different ways to create objects in AutoCAD. Two main ways to create objects is either AutoLISP or Visual LISP. I myself prefer using Visual LISP as it can be easier to understand. I'll post an example of creating text via Visual LISP. This example will create a piece of text in model space with the insertion at 0,0,0. (setq app (vlax-get-acad-object));Get the acad object (setq doc (vlax-get-property app 'ActiveDocument));Get the Active Document (setq ms (vlax-get-property doc 'ModelSpace));Get the Model Space (setq str "MyTextString");Define a String (setq pnt (vlax-3d-point 0 0 0));Define a Point, This example is 0,0,0 (setq ht 1.0);Define a text height (setq txtobj (vlax-invoke-method ms 'AddText str pnt ht));Add the Text to Model SpaceSpace Edited March 27, 2017 by Hippe013 error Quote
OMEGA-ThundeR Posted March 27, 2017 Posted March 27, 2017 i believe you need to define your variables (SETQ part) in the 'defun' line. so: (defun c:txtTest (/) Would become: (defun c:txtTest (/ pt d Au) Don't know if that is even necessary, but i see it in most LISP routines. On the rest of the code i can't offer any help. Quote
Hippe013 Posted March 27, 2017 Posted March 27, 2017 That is for making your declared variables to be local rather global variables. Good practice to do this, but it is not always necessary. Quote
ktbjx Posted March 31, 2017 Author Posted March 31, 2017 There are different ways to create objects in AutoCAD. Two main ways to create objects is either AutoLISP or Visual LISP. I myself prefer using Visual LISP as it can be easier to understand. I'll post an example of creating text via Visual LISP. This example will create a piece of text in model space with the insertion at 0,0,0. (setq app (vlax-get-acad-object));Get the acad object (setq doc (vlax-get-property app 'ActiveDocument));Get the Active Document (setq ms (vlax-get-property doc 'ModelSpace));Get the Model Space (setq str "MyTextString");Define a String (setq pnt (vlax-3d-point 0 0 0));Define a Point, This example is 0,0,0 (setq ht 1.0);Define a text height (setq txtobj (vlax-invoke-method ms 'AddText str pnt ht));Add the Text to Model SpaceSpace i didnt get what you mean, lol sorry Quote
OMEGA-ThundeR Posted March 31, 2017 Posted March 31, 2017 (edited) You want to know the 'length' of the text (i.e. "Thisline" is shorter than "Thislineislonger")?. Why not just justify the left text with 'right' and the right texts with an justify of 'left'? That way the text is never overlapping. But why not just make an block with attribute texts in it? Then when you insert the block it will ask to fill out the needed information and you can predefine the markup of the text. You can get the 'stringlength' however, so, depending on the width of your font you can calculate the lenght of the given text: (setq stringlength (strlen d)) Where 'd' is your variable for distance. If you enter '500' for distance, the stringlength is 3. If you enter 'longlineislonger' the stringlength is 16. You can then add an calculation to figure out how 'long' the text is: (setq textlength (* stringlength 2.5)) Where 2.5 is the width of 1 letter in the fontsize you are wanting to use. The length of the text may differ however. Typing in 'iiiiiiiiii' or 'wwwwwwwwww' is making an obvious difference, but the stringlength in both cases is 10. So i would say the right 'Justify' setting should work arround that problem. Edited March 31, 2017 by OMEGA-ThundeR Quote
BIGAL Posted March 31, 2017 Posted March 31, 2017 Looking at your dwg Omega-Thunder is correct left justified and remember the insertion point the next 3 texts make right justified, you need to make a decision use mtext or text either way you need to do a double "Polar" command to work the right hand text start point, you need to get the "textheight" and use a fuzzy factor so your line spacing looks right try 1.4 times the height. The advantage with mtext is it will do next line etc. Copy this into mtext "this is line1\nLine 2\n Line 3" As previously mentioned using a block would be the easiest as set it up once. 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.