Author Topic: help with calculation lisp  (Read 326 times)

0 Members and 1 Guest are viewing this topic.

PM

  • Newt
  • Posts: 127
help with calculation lisp
« on: September 09, 2020, 04:19:05 AM »
Hi .i use a simple lisp code to do a calculation. In this code i have to gine the 2 areas

Code - Auto/Visual Lisp: [Select]
  1. (defun C:test ()
  2. (setq area1 (getreal "\ngive area1: "))
  3. (setq area2 (getreal "\ngive area2: "))
  4.        (initget 7)
  5.        (textpage)
  6.       (strcat "\n calculate"
  7.               "\n -----------------------"
  8.               (strcat "\n Calculate  = " (rtos (* 1000 (/ area2 area1)) 2 2) " \U+2030")
  9.  
  10.     )
  11.     )
  12.    
  13.   (princ)
  14. )
  15.  
  16.  

I want to update this code to

1) select the polyline of area1
2)select the polyline of area2
3) pick insert point, and isert text    Calculate  = "    " \U+2030

Code - Auto/Visual Lisp: [Select]
  1. (COMMAND "_layer" "_m" "_Calculate" "_c" "6""" "")
  2.   (command "_.-style" "_Calculate" "arial.ttf" "_annotative" "_yes" "_no" 3 1.0 0.0 "_no" "_no" "_no")
  3.  


thanks

HOSNEYALAA

  • Newt
  • Posts: 53
Re: help with calculation lisp
« Reply #1 on: September 09, 2020, 04:38:42 AM »
HI

Code: [Select]
(defun C:test ()
  (IF(AND
 (setq ent1 (car (entsel "\nSelect Closed LWPolyline1 : "))
          obj1 (vlax-ename->vla-object ent1)
    );end_setq
 (setq ent2 (car (entsel "\nSelect Closed LWPolyline2 : "))
          obj2 (vlax-ename->vla-object ent2)
    );end_setq
 )
    (PROGN
       (setq ipt (getpoint "\nSelect TEXT Insertion Point: "))
       


 (command "text" "_mc"
     ipt
     1
     "0"
     (strcat "\n calculate"
              "\n -----------------------"
              (strcat "\n Calculate  = " (rtos (* 1000 (/ (vlax-curve-getarea ent1) (vlax-curve-getarea ent2))) 2 2) " \U+2030")
 
    )
    )
     ))         
   
  (princ)
)

PM

  • Newt
  • Posts: 127
Re: help with calculation lisp
« Reply #2 on: September 09, 2020, 09:53:23 AM »
Hi  HOSNEYALAA. I test your code but the results is 0 . I think somethig missing. I add same more things in the code. I possible the export text be mtext because the export  text will have 5 lines ?

Code - Auto/Visual Lisp: [Select]
  1. (defun C:test ()
  2. (COMMAND "_layer" "_m" "_Calculate" "_c" "6""" "")
  3. (command "-style" "_TopoCad" "arial.ttf" "_annotative" "_yes" "_no" 2.5 1.0 0.0 "_no" "_no" "_no")
  4.   (IF(AND
  5.  (setq ent1 (car (entsel "\nSelect Closed LWPolyline1 : "))
  6.           obj1 (vlax-ename->vla-object ent1)
  7.     );end_setq
  8.  (setq ent2 (car (entsel "\nSelect Closed LWPolyline2 : "))
  9.           obj2 (vlax-ename->vla-object ent2)
  10.     );end_setq
  11.  )
  12.     (PROGN
  13.        (setq ipt (getpoint "\nSelect TEXT Insertion Point: "))
  14.        
  15.  
  16.  
  17.  (command "text" "_mc"
  18.              ipt
  19.              1
  20.              "0"
  21.              (strcat "\n calculate"
  22.               "\n -----------------------"
  23.               (strcat "\n area 2= " (rtos (vlax-curve-getarea ent2) 2 2) " sq.m")
  24.               (strcat "\n area 1= " (rtos (vlax-curve-getarea ent1) 2 2) " sq.m")
  25.               (strcat "\n Calculate  = " (rtos (* 1000 (/ (vlax-curve-getarea ent2) (vlax-curve-getarea ent1))) 2 2) " \U+2030")
  26.  
  27.     )
  28.     )
  29.      ))        
  30.    
  31.   (princ)
  32. )
  33.  
  34.  

Thanks

HOSNEYALAA

  • Newt
  • Posts: 53
Re: help with calculation lisp
« Reply #3 on: September 09, 2020, 10:20:51 AM »
Code: [Select]
;;;https://www.cadtutor.net/forum/topic/70120-idea-to-determinating-location-lengths-for-polyline/page/2/#comments

;;dlanorh

(defun rh:em_mtxt (pt txt lyr)
  (entmakex (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText")
                  (cons 8 lyr) '(50 . 0.0) (cons 7 (getvar 'textstyle))
                  (cons 1 txt)(cons 10 pt) (cons 40 0.5)
            );end_list
  );end_entmakex
);end_defun

(defun C:test ( / A_TXT ENT1 ENT2 ESTR IPT NSTR OBJ1 OBJ2 SSTR)
(COMMAND "_layer" "_m" "_Calculate" "_c" "6""" "")
(command "-style" "_TopoCad" "arial.ttf" "_annotative" "_yes" "_no" 2.5 1.0 0.0 "_no" "_no" "_no")
  (IF(AND
 (setq ent1 (car (entsel "\nSelect Closed LWPolyline1 : "))
          obj1 (vlax-ename->vla-object ent1)
       
    );end_setq
 (= :vlax-true (vlax-get-property obj1 'closed))
 (setq ent2 (car (entsel "\nSelect Closed LWPolyline2 : "))
          obj2 (vlax-ename->vla-object ent2)
    );end_setq
 (= :vlax-true (vlax-get-property obj2 'closed))
 )
    (PROGN
       (setq ipt (getpoint "\nSelect TEXT Insertion Point: ")
             nstr (strcat "\n Area 2= " (rtos (vlax-curve-getarea ent2) 2 2) " sq.m")
              estr(strcat "\n Area 1= " (rtos (vlax-curve-getarea ent1) 2 2) " sq.m")
              sstr(strcat "\n Calculate  = " (rtos (* 1000 (/ (vlax-curve-getarea ent2) (vlax-curve-getarea ent1))) 2 2) " \U+2030"))
       
   

(setq a_txt (strcat nstr "\\P" estr "\\P" sstr ))
    (rh:em_mtxt ipt a_txt (getvar 'clayer))
 
 
     )
    (alert "NOT a CLOSED LWPolyline")

    )         
   
  (princ)
)
 
 



PM

  • Newt
  • Posts: 127
Re: help with calculation lisp
« Reply #4 on: September 09, 2020, 10:49:18 AM »
Hi HOSNEYALAA. With this line

Code - Auto/Visual Lisp: [Select]
  1. (cons 40 0.5)
  2.  

The text height is 0.5 and is not working as annotative !!!

Thanks

HOSNEYALAA

  • Newt
  • Posts: 53
Re: help with calculation lisp
« Reply #5 on: September 09, 2020, 10:57:42 AM »
change  to


Code: [Select]


;;dlanorh

(defun rh:em_mtxt (pt txt lyr)
  (entmakex (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText")
                  (cons 8 lyr) '(50 . 0.0) (cons 7 (getvar 'textstyle))
                  (cons 1 txt)(cons 10 pt) (cons 40 (* 2.5 (getvar 'textsize)))
            );end_list
  );end_entmakex
);end_defun


PM

  • Newt
  • Posts: 127
Re: help with calculation lisp
« Reply #6 on: September 09, 2020, 11:13:01 AM »
Code - Auto/Visual Lisp: [Select]
  1. (command "-style" "_TopoCad" "arial.ttf" "_annotative" "_yes" "_no" 2.5 1.0 0.0 "_no" "_no" "_no")
  2.  

Is still not annotative

PM

  • Newt
  • Posts: 127
Re: help with calculation lisp
« Reply #7 on: September 09, 2020, 12:25:11 PM »
any idea ?

thanks

BIGAL

  • Swamp Rat
  • Posts: 516
  • 30 + years of using Autocad
Re: help with calculation lisp
« Reply #8 on: September 09, 2020, 08:22:38 PM »
Extra "No" ?
A man who never made a mistake never made anything

PM

  • Newt
  • Posts: 127
Re: help with calculation lisp
« Reply #9 on: September 10, 2020, 12:21:53 AM »
Hi bigal. I will check it but i use the same text style in othe lisp codes and is exactly the same

PM

  • Newt
  • Posts: 127
Re: help with calculation lisp
« Reply #10 on: September 10, 2020, 11:11:15 AM »
I try to add an extra "_no"  and i try to delete an extra "_no" but nothing. The mtext is not annotative. Any other option?

Tharwat

  • Swamp Rat
  • Posts: 553
  • Hypersensitive
Re: help with calculation lisp
« Reply #11 on: September 10, 2020, 04:40:51 PM »
The mtext is not annotative. Any other option?
Hi,
I am not a fan of using command calls unless it is the only or the best way to go with but here I am paying your attention to the easiest way that you can go with other than involving into codes to do so.
HINT:


BIGAL

  • Swamp Rat
  • Posts: 516
  • 30 + years of using Autocad
Re: help with calculation lisp
« Reply #12 on: September 10, 2020, 09:59:35 PM »
I tested on Bricscad maybe the caps Yes No.

(command "-style" "_TopoCad" "arial.ttf" "_annotative" "_Yes" "_No" 2.5 1.0 0.0 "_No" "_No")
A man who never made a mistake never made anything

PM

  • Newt
  • Posts: 127
Re: help with calculation lisp
« Reply #13 on: September 11, 2020, 12:45:45 AM »
I try everything. Creates the _TopoCad text style.in format->text style the _Topocad text style is annotative. Insert  the mtext in _Topocad text style but the mtext is not annotative !!!


 :idea: :idea: :idea: :idea:


Thanks

PM

  • Newt
  • Posts: 127
Re: help with calculation lisp
« Reply #14 on: September 11, 2020, 01:41:01 AM »
I did this change

Code - Auto/Visual Lisp: [Select]
  1. '(7 . "_TopoCad")
  2.  

but nothing

 :idea: :idea: :idea: