Ranjit's code - help

Ranjit's code - help

F.Camargo
Advisor Advisor
1,052 Views
8 Replies
Message 1 of 9

Ranjit's code - help

F.Camargo
Advisor
Advisor

Hi guys,

 

Based on this thread: 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/ga-lsp-is-it-possible-to-insert-tilt...

 

@Ranjit_Singh built that excellent code!

 

I'm trying to understand the code, and I need some help with this.

That code insert the text as a field and I'd like to change to text.

 

;;Ranjit Singh
;;8/22/17
(defun c:sf  (/ ent ang dat)
(setq o_layer (getvar 'CLAYER))
  (setq o_echo (getvar 'CMDECHO))
  (setvar 'CMDECHO 0)
  (command "_.layer" "_T" "-AREA-LOTE" "_M" "-AREA-LOTE" "c" "1" "" ""
	   "_.layer" "_T" "-AREA-LOTE" "_U" "-AREA-LOTE" "_M" "-AREA-LOTE" "c" "2" "" "")

  (setq fmt "%lu6%qf1%ps[,m²]%ds44%th46")
  
    ;; Text height
 (if
    (setq h (getdist (strcat "\nSpecify text height <" (rtos (getvar 'textsize)) ">: ")))
 (setvar 'textsize h)
 (setq h (getvar 'textsize))
 )
 (mapcar '(lambda (x)
           (entmakex
            (list '(0 . "TEXT")
                  '(10 0 0 0)
                  (cons 40 h)
                  ;(cons 1
                       ;(strcat "%<\\AcObjProp Object(%<\\_ObjId "
                      ;(itoa (vla-get-objectid (vlax-ename->vla-object (setq ent x))))
                                   ;">%).Area \\f \""
		   ;fmt
		   ;"\">%"))
		  (cons 1
              (strcat
                     (vl-string-translate "." "," (rtos (getpropertyvalue (setq ent (car (entsel "\nSeleciona Polilinha: "))) "Area") 2 2)) "m²"))
                  (cons 50
                        (+ (setq ang (progn (setq dat (cdr (reverse (vl-remove-if-not 'listp (mapcar 'cdr (entget ent))))))
                                            (apply 'angle
                                                   (cdar (vl-sort (mapcar '(lambda (x y) (cons (distance x y) (list x y))) dat (cdr dat))
                                                                  '(lambda (x y) (> (car x) (car y))))))))
                           (if (and (>= (* 1.5 pi) ang) (> ang (* 0.5 pi)))
                            pi
                            0)))
                  '(72 . 1)
                  (cons 11 (mapcar '/ (mapcar '+ (car dat) (caddr dat)) '(2 2)))
                  '(73 . 2))))
         (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "LWPOLYLINE")))))))
(setvar 'CLAYER o_layer)
(setvar 'CMDECHO o_echo)
(PRINC)
)

Anybody could explain to me how to do that, please?

 

Thank in advance

Fabricio

0 Likes
Accepted solutions (1)
1,053 Views
8 Replies
Replies (8)
Message 2 of 9

braudpat
Mentor
Mentor

Hello

Maybe you can only explode the Fields ?!

Regards, Patrice

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 3 of 9

F.Camargo
Advisor
Advisor

@braudpat wrote:
Hello

Maye you can only explode the Fields ?!

Regards, Patrice

Thanks for replay,

 

But I'm studing autolisp and I'd like to know how to modify the code.

 

I'm trying to do that.

 

Fabricio

0 Likes
Message 4 of 9

ambrosl
Autodesk
Autodesk

What part of the code are you having difficulty understanding?

 

When I run the function, it creates a TEXT object with a text value and not a field.  For example, when running the function and selecting a closed polyline I got the a TEXT object with the "212,17m²" in it.



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
0 Likes
Message 5 of 9

F.Camargo
Advisor
Advisor

@ambrosl wrote:

What part of the code are you having difficulty understanding?

 

When I run the function, it creates a TEXT object with a text value and not a field.  For example, when running the function and selecting a closed polyline I got the a TEXT object with the "212,17m²" in it.

 

 

I noticed the code ask me to select the polyline two times before insert the text.

That's not right!

 

After invoke the code, I have to select all polyline that I want to. And them put the text in all polylines.

 

I'd like to fix it. 🙂

 

Thanks

Fabricio

0 Likes
Message 6 of 9

Ranjit_Singh
Advisor
Advisor

I have modified code from the original post. It should be pretty easy now to add any custom layers etc. per your above code.

;;Ranjit Singh
;;8/22/17
(defun c:somefunc  (/ ent ang dat)
 (mapcar '(lambda (x)
           (entmakex
            (list '(0 . "TEXT")
                  '(10 0 0 0)
                  (cons 40 (getvar 'textsize))
                  (cons 1
                        (strcat "%<\\AcObjProp.16.2 Object(%<\\_ObjId "
                                (itoa (vla-get-objectid (vlax-ename->vla-object (setq ent x))))
                                ">%).Area \\f \"%lu2%pr2%ps[,m²]%ds44%th46\">%"))
                  (cons 50
                        (+ (setq ang (progn (setq dat (cdr (reverse (vl-remove-if-not 'listp (mapcar 'cdr (entget ent))))))
                                            (apply 'angle
                                                   (cdar (vl-sort (mapcar '(lambda (x y) (cons (distance x y) (list x y))) dat (cdr dat))
                                                                  '(lambda (x y) (> (car x) (car y))))))))
                           (if (and (>= (* 1.5 pi) ang) (> ang (* 0.5 pi)))
                            pi
                            0)))
                  '(72 . 1)
                  (cons 11 (mapcar '/ (mapcar '+ (car dat) (caddr dat)) '(2 2)))
                  '(73 . 2))))
         (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "LWPOLYLINE"))))))))

Label_mult_rec_m2.gif

 

0 Likes
Message 7 of 9

F.Camargo
Advisor
Advisor

Hi @Ranjit_Singh

 

Could you give a support in the code that I've posted?

 

Actually I could change the code, field text to a normal text. But isn't working properly.

 

After run the code I have to select the closed polylines and insert the text.

The code is ask me 2 times to select the objects, and it isn't right.

 

Fabricio

0 Likes
Message 8 of 9

Ranjit_Singh
Advisor
Advisor
Accepted solution

See below changes

;;Ranjit Singh
;;8/22/17
(defun c:sf  (/ ent ang dat)
(setq o_layer (getvar 'CLAYER))
  (setq o_echo (getvar 'CMDECHO))
  (setvar 'CMDECHO 0)
  (command "_.layer" "_T" "-AREA-LOTE" "_M" "-AREA-LOTE" "c" "1" "" ""
	   "_.layer" "_T" "-AREA-LOTE" "_U" "-AREA-LOTE" "_M" "-AREA-LOTE" "c" "2" "" "")

  (setq fmt "%lu6%qf1%ps[,m²]%ds44%th46")
  
    ;; Text height
 (if
    (setq h (getdist (strcat "\nSpecify text height <" (rtos (getvar 'textsize)) ">: ")))
 (setvar 'textsize h)
 (setq h (getvar 'textsize))
 )
 (mapcar '(lambda (x)
           (entmakex
            (list '(0 . "TEXT")
                  '(10 0 0 0)
                  (cons 40 h)
                  ;(cons 1
                       ;(strcat "%<\\AcObjProp Object(%<\\_ObjId "
                      ;(itoa (vla-get-objectid (vlax-ename->vla-object (setq ent x))))
                                   ;">%).Area \\f \""
		   ;fmt
		   ;"\">%"))
		  (cons 1
              (strcat
                     (vl-string-translate "." "," (rtos (getpropertyvalue x "Area") 2 2)) "m²"))
                  (cons 50
                        (+ (setq ang (progn (setq dat (cdr (reverse (vl-remove-if-not 'listp (mapcar 'cdr (entget x))))))
                                            (apply 'angle
                                                   (cdar (vl-sort (mapcar '(lambda (x y) (cons (distance x y) (list x y))) dat (cdr dat))
                                                                  '(lambda (x y) (> (car x) (car y))))))))
                           (if (and (>= (* 1.5 pi) ang) (> ang (* 0.5 pi)))
                            pi
                            0)))
                  '(72 . 1)
                  (cons 11 (mapcar '/ (mapcar '+ (car dat) (caddr dat)) '(2 2)))
                  '(73 . 2))))
         (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "LWPOLYLINE")))))))
(setvar 'CLAYER o_layer)
(setvar 'CMDECHO o_echo)
(PRINC)
)

Label_mult_rec_txt_m2.gif 

Message 9 of 9

F.Camargo
Advisor
Advisor

@Ranjit_Singh wrote:

See below changes

;;Ranjit Singh
;;8/22/17
(defun c:sf  (/ ent ang dat)
(setq o_layer (getvar 'CLAYER))
  (setq o_echo (getvar 'CMDECHO))
  (setvar 'CMDECHO 0)
  (command "_.layer" "_T" "-AREA-LOTE" "_M" "-AREA-LOTE" "c" "1" "" ""
	   "_.layer" "_T" "-AREA-LOTE" "_U" "-AREA-LOTE" "_M" "-AREA-LOTE" "c" "2" "" "")

  (setq fmt "%lu6%qf1%ps[,m²]%ds44%th46")
  
    ;; Text height
 (if
    (setq h (getdist (strcat "\nSpecify text height <" (rtos (getvar 'textsize)) ">: ")))
 (setvar 'textsize h)
 (setq h (getvar 'textsize))
 )
 (mapcar '(lambda (x)
           (entmakex
            (list '(0 . "TEXT")
                  '(10 0 0 0)
                  (cons 40 h)
                  ;(cons 1
                       ;(strcat "%<\\AcObjProp Object(%<\\_ObjId "
                      ;(itoa (vla-get-objectid (vlax-ename->vla-object (setq ent x))))
                                   ;">%).Area \\f \""
		   ;fmt
		   ;"\">%"))
		  (cons 1
              (strcat
                     (vl-string-translate "." "," (rtos (getpropertyvalue x "Area") 2 2)) "m²"))
                  (cons 50
                        (+ (setq ang (progn (setq dat (cdr (reverse (vl-remove-if-not 'listp (mapcar 'cdr (entget x))))))
                                            (apply 'angle
                                                   (cdar (vl-sort (mapcar '(lambda (x y) (cons (distance x y) (list x y))) dat (cdr dat))
                                                                  '(lambda (x y) (> (car x) (car y))))))))
                           (if (and (>= (* 1.5 pi) ang) (> ang (* 0.5 pi)))
                            pi
                            0)))
                  '(72 . 1)
                  (cons 11 (mapcar '/ (mapcar '+ (car dat) (caddr dat)) '(2 2)))
                  '(73 . 2))))
         (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "LWPOLYLINE")))))))
(setvar 'CLAYER o_layer)
(setvar 'CMDECHO o_echo)
(PRINC)
)

Label_mult_rec_txt_m2.gif 


@Ranjit_Singh

Very nice!

 

I've wasted a couple of hours trying to understand how to do that. but no success.

 

Thank you very much
Fabricio

0 Likes