Makkc Posted July 18, 2017 Share Posted July 18, 2017 Dear lisp advanced users, please be generous and help me to automatize the following operations step 1: User select the polyline step 2: User select the dimension step 3: User insert 2 values: value 1 and value 2 step 4: User pick a point were the 4 different separate text elements appears: value 1; polyine length; (dimension measurement value/value2)+1; 5*pline length*(value1)^2 the color of the text should depend from value1, so the text with the same value1 should have the same color. Unfortunately I have not found any solutions on forum bat this lisp may be helpful http://www.cadtutor.net/forum/showthread.php?36659-lisp-to-put-text-with-pline-leangth-above-line/page2 . Thank you Lee Mac. Thank you very much in advance Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted July 18, 2017 Share Posted July 18, 2017 I'm not sure what you mean with value 1 and the color. Do you mean, for example: if value1=10 => the text is given color red; value1=90 => green; ...? Is value1 an int; is value2 a floating point ? Quote Link to comment Share on other sites More sharing options...
Makkc Posted July 18, 2017 Author Share Posted July 18, 2017 I'm not sure what you mean with value 1 and the color. Do you mean, for example: if value1=10 => the text is given color red; value1=90 => green; ...? Is value1 an int; is value2 a floating point ? Dear Emmanuel Delay, yes I mean that if value1=10 => the text is given color red; value1=90 => green; value 1 can be only 6-8-10-12-14-16-18-20-22-25-28-32-36-40 and value 2 can be any number. Also the (dim measurement)/value2+1 should be round to the closest maximum integer number Thank you in advance Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted July 18, 2017 Share Posted July 18, 2017 (edited) I think I got it. Please check if this was the demand. Any features missing? Well, I don't do all the checks, like the list of possible values of value1 Command is "P", feel free to change this, and also the settings on top of the code Oh yes, the ^2, is that only powering the value? Else you need to change the position of (expt ;; [url]http://www.cadtutor.net/forum/showthread.php?101221-Lisp-to-get-length-of-a-pline-and-dim-value-and-put-it-to-the-several-text-elements[/url] ;; step 1: User select the polyline ;; step 2: User select the dimension ;; step 3: User insert 2 values: value 1 and value 2 ;; step 4: User pick a point were the 4 different separate text elements appears: ;; value 1; polyine length; (dimension measurement value/value2)+1; 5*pline length*(value1)^2 ;; the color of the text should depend from value1, so the text with the same value1 should have the same color. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; @see [url]https://www.theswamp.org/index.php?topic=32148.0[/url] (defun Text (pt hgt str) (entmakex (list (cons 0 "TEXT") (cons 10 pt) (cons 40 hgt) (cons 1 str)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; settings (setq text_height 10 text_spacing 14 ;; vertical distance between the lines ) (defun c:p ( / ss_pline pline_length ss_dim dim_measurement entitylist value1 value2 pt text1 text2 text3 text4 val3) (vl-load-com) ;; step 1: User select the polyline (princ "\nSelect Polyline: ") (setq ss_pline (ssget ":S" (list (cons 0 "LWPOLYLINE")) )) (setq pline_length (vla-get-length (vlax-ename->vla-object (ssname ss_pline 0)))) ;; step 2: User select the dimension (princ "\nSelect Dim: ") (setq ss_dim (ssget ":S" (list (cons 0 "DIMENSION")) )) ;; (setq entitylist (cdr (entget (ssname ss_dim 0)))) (setq dim_measurement (cdr (assoc 42 entitylist) )) ;; step 3: User insert 2 values: value 1 and value 2 (setq value1 (getint "\nValue1 (int): ") value2 (getreal "\nValue2 (float): ") ) ;; step 4: User pick a point were the 4 different separate text elements appears: (setq pt (getpoint "\nGet Point: ")) ;; Make text ;; value 1 (setq text1 (Text pt text_height (itoa value1))) ;; polyine length (setq text2 (Text (list (nth 0 pt) (- (nth 1 pt) text_spacing )) text_height (rtos pline_length)) ) ;; (dimension measurement value/value2)+1 (setq val3 (fix (+ 0.5 (+ 1 (/ (float dim_measurement) value2))) )) (setq text3 (Text (list (nth 0 pt) (- (nth 1 pt) (* 2 text_spacing) )) text_height (rtos val3)) ) ;; 5*pline length*(value1)^2 (setq val4 (* (* 5 pline_length) (expt value1 2) ) ) (setq text4 (Text (list (nth 0 pt) (- (nth 1 pt) (* 3 text_spacing) )) text_height (rtos val4)) ) ;; the color of the text should depend from value1 (vla-put-Color (vlax-ename->vla-object text1) value1) (vla-put-Color (vlax-ename->vla-object text2) value1) (vla-put-Color (vlax-ename->vla-object text3) value1) (vla-put-Color (vlax-ename->vla-object text4) value1) ) Edited July 18, 2017 by Emmanuel Delay (vl-load-com) Quote Link to comment Share on other sites More sharing options...
Makkc Posted July 19, 2017 Author Share Posted July 19, 2017 Dear Emmanuel Delay, thank you very much! Your skills and knowledge are great! The program works perfectly well. Could I ask you about small update: 1. Arrange text elements in a row 2. add 5th element: val4*val3 3. make the program remember the last values of val1 and val2 Again thank you very much for your time and effort, Maxim Quote Link to comment Share on other sites More sharing options...
Emmanuel Delay Posted July 19, 2017 Share Posted July 19, 2017 Yes. I'll try to do this tomorrow. 2. is not a problem. 3: When the client pushes enter, the previous value is set. I have a test program that shows the principle. By the way, if anybody does this in a more elegant way, please show me. The issue is that I have to check if variables are a string or a number, ... It will take me some time ;; global vars, these will remember the last chosen values (setq pickvalue1 0 pickvalue2 0 ) ;; (defun c:test ( / value1 value2 promprstring ) (setq promprstring (strcat "\nEnter Value 1 <" (rtos pickvalue1) ">: " )) (setq value1 (getstring promprstring)) (if (= value1 "") (progn) (setq pickvalue1 (atof value1)) ) (setq promprstring (strcat "\nEnter Value 2 <" (rtos pickvalue2) ">: " )) (setq value2 (getstring promprstring)) (if (= value2 "") (progn) (setq pickvalue2 (atof value2)) ) (princ "\n") (princ pickvalue1) (princ " - ") (princ pickvalue2) (princ) ) 1: The nice thing about a column: you don't need to know the length (size) of a text element. In a row you do. Any ideas about the font size and the max width of each element? 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.