LAY DIMENSION

LAY DIMENSION

rolisonfelipe
Collaborator Collaborator
1,160 Views
13 Replies
Message 1 of 14

LAY DIMENSION

rolisonfelipe
Collaborator
Collaborator
 
rolisonfelipe_3-1715824702323.png

 

 

THIS IS A LEE MAC LSP. BUT I CANNOT ADJUST:

1- TO CONTROL THE SIZE OF THE FONT, AND NOT CO-RELATE THE LAYER THAT THE DIMENSION WILL BE.

2 - INSERT THE LAYER NAME AND EACH INSERTED DIMENSION OF EACH SELECTED ELEMENT

 

 

 

;;----------------------=={ Length at Midpoint }==----------------------;;
;;                                                                      ;;
;;  This program prompts the user for a selection of objects to be      ;;
;;  labelled and proceeds to generate an MText object located at        ;;
;;  the midpoint of each object displaying a Field Expression           ;;
;;  referencing the length of the object.                               ;;
;;                                                                      ;;
;;  The program is compatible for use with Arcs, Circles, Lines,        ;;
;;  LWPolylines, 2D & 3D Polylines, and under all UCS & View settings.  ;;
;;                                                                      ;;
;;  The program will generate MText objects positioned directly over    ;;
;;  the midpoint of each object, and aligned with the object whilst     ;;
;;  preserving text readability. The MText will have a background mask  ;;
;;  enabled and will use the active Text Style and Text Height settings ;;
;;  at the time of running the program.                                 ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Version 1.0    -    2013-11-12                                      ;;
;;                                                                      ;;
;;  - First release.                                                    ;;
;;----------------------------------------------------------------------;;
;;  Version 1.1    -    2016-01-16                                      ;;
;;                                                                      ;;
;;  - Modified LM:objectid function to account for 64-bit AutoCAD 2008. ;;
;;----------------------------------------------------------------------;;
 
(defun c:midlen ( / *error* ent fmt idx ins ocs par sel spc txt typ uxa )
 
    (setq fmt "%lu6") ;; Field Formatting
 
    (defun *error* ( msg )
        (LM:endundo (LM:acdoc))
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )
    
    (if
        (setq sel
            (ssget
                (list
                   '(0 . "ARC,CIRCLE,LINE,*POLYLINE")
                   '(-4 . "<NOT")
                       '(-4 . "<AND")
                           '(0 . "POLYLINE")
                           '(-4 . "&")
                           '(70 . 80)
                       '(-4 . "AND>")
                   '(-4 . "NOT>")
                    (if (= 1 (getvar 'cvport))
                        (cons 410 (getvar 'ctab))
                       '(410 . "Model")
                    )
                )
            )
        ) 
        (progn
            (setq spc
                (vlax-get-property (LM:acdoc)
                    (if (= 1 (getvar 'cvport))
                        'paperspace
                        'modelspace
                    )
                )
            )
            (setq ocs (trans '(0.0 0.0 1.0) 1 0 t)
                  uxa (angle '(0.0 0.0) (trans (getvar 'ucsxdir) 0 ocs t))
            )
            (LM:startundo (LM:acdoc))
            (repeat (setq idx (sslength sel))
                (setq ent (ssname sel (setq idx (1- idx)))
                      par (vlax-curve-getparamatdist ent (/ (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent)) 2.0))
                      ins (vlax-curve-getpointatparam ent par)
                      typ (cdr (assoc 0 (entget ent)))
                )
 
 
=========================================================================================================================================================
(if (= (tblsearch "LAYER" "TOPO-SINAL COTA")) ; SEARCH IF THE LAYER IS ACTIVE, BY RFR
(command "-LAYER" "M" "TOPO-SINAL COTA" "c" "7" "" "LT" "Continuous" "" "LW" "0.00" "" "")) ; DEFINE THE TEXT LAYER TO BE INSERTED, BY RFR
(setq ESCALA (\n SCALE 1:)) ; REQUEST WORK SCHEDULE, BY RFR
(setq Htxt (* .1 ( / 50  ESCALA ))) ; ADJUSTS WORKING SCALE TO TXT SIZE 0.10 AT 1/50 SCALE, BY RFR
=========================================================================================================================================================
    (setq txt
(vlax-invoke spc 'addmtext ins 0.0
                (strcat "%<\\AcObjProp Object(%<\\_ObjId " (LM:objectid (vlax-ename->vla-object ent)) ">%)."
                (cond
                        (   (= "CIRCLE" typ) "Circumference")
                        (   (= "ARC"    typ) "ArcLength")
                        (   "Length"   ))
                        " \\f \"" fmt "\">%")))
                (vla-put-backgroundfill  txt :vlax-true)
                (vla-put-attachmentpoint txt acattachmentpointmiddlecenter)
                (vla-put-insertionpoint  txt (vlax-3D-point ins))
                (vla-put-rotation txt (LM:readable (- (angle '(0.0 0.0 0.0) (trans (vlax-curve-getfirstderiv ent par) 0 ocs t)) uxa)))
            )
            (LM:endundo (LM:acdoc))
        )
    )
    (princ)
)
 
;; Readable  -  Lee Mac
;; Returns an angle corrected for text readability.
 
(defun LM:readable ( a )
    (   (lambda ( a )
            (if (and (< (* pi 0.5) a) (<= a (* pi 1.5)))
                (LM:readable (+ a pi))
                a
            )
        )
        (rem (+ a pi pi) (+ pi pi))
    )
)
 
;; ObjectID  -  Lee Mac
;; Returns a string containing the ObjectID of a supplied VLA-Object
;; Compatible with 32-bit & 64-bit systems
 
(defun LM:objectid ( obj )
    (eval
        (list 'defun 'LM:objectid '( obj )
            (if (wcmatch (getenv "PROCESSOR_ARCHITECTURE") "*64*")
                (if (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
                    (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
                   '(LM:ename->objectid (vlax-vla-object->ename obj))
                )
               '(itoa (vla-get-objectid obj))
            )
        )
    )
    (LM:objectid obj)
)
 
;; Entity Name to ObjectID  -  Lee Mac
;; Returns the 32-bit or 64-bit ObjectID for a supplied entity name
 
(defun LM:ename->objectid ( ent )
    (LM:hex->decstr
        (setq ent (vl-string-right-trim ">" (vl-prin1-to-string ent))
              ent (substr ent (+ (vl-string-position 58 ent) 3))
        )
    )
)
 
;; Hex to Decimal String  -  Lee Mac
;; Returns the decimal representation of a supplied hexadecimal string
 
(defun LM:hex->decstr ( hex / foo bar )
    (defun foo ( lst rtn )
        (if lst
            (foo (cdr lst) (bar (- (car lst) (if (< 57 (car lst)) 55 48)) rtn))
            (apply 'strcat (mapcar 'itoa (reverse rtn)))
        )
    )
    (defun bar ( int lst )
        (if lst
            (if (or (< 0 (setq int (+ (* 16 (car lst)) int))) (cdr lst))
                (cons (rem int 10) (bar (/ int 10) (cdr lst)))
            )
            (bar int '(0))
        )
    )
    (foo (vl-string->list (strcase hex)) nil)
)
 
;; Start Undo  -  Lee Mac
;; Opens an Undo Group.
 
(defun LM:startundo ( doc )
    (LM:endundo doc)
    (vla-startundomark doc)
)
 
;; End Undo  -  Lee Mac
;; Closes an Undo Group.
 
(defun LM:endundo ( doc )
    (while (= 8 (logand 8 (getvar 'undoctl)))
        (vla-endundomark doc)
    )
)
 
;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object
 
(defun LM:acdoc nil
    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:acdoc)
)
 
(vl-load-com)
(princ
    (strcat
        "\n:: MidLen.lsp | Version 1.1 | \\U+00A9 Lee Mac "
        (menucmd "m=$(edtime,0,yyyy)")
        " www.lee-mac.com ::"
        "\n:: Type \"midlen\" to Invoke ::"
    )
)
(princ)
 
;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;
0 Likes
Accepted solutions (2)
1,161 Views
13 Replies
Replies (13)
Message 2 of 14

komondormrex
Mentor
Mentor

@rolisonfelipe wrote:

2 - INSERT THE LAYER NAME AND EACH INSERTED DIMENSION OF EACH SELECTED ELEMENT


which layer name exactly? 

 

the code below

 

(setq ESCALA (\n SCALE 1:)) ; REQUEST WORK SCHEDULE, BY RFR
(setq Htxt (* .1 ( / 50  ESCALA ))) ; ADJUSTS WORKING SCALE TO TXT SIZE 0.10 AT 1/50 SCALE, BY RFR

 

 should go like

 

(setq ESCALA (getint "\n SCALE 1:")) ; REQUEST WORK SCHEDULE, BY RFR
(setq Htxt (* 0.1 ( / 50.0  ESCALA ))) ; ADJUSTS WORKING SCALE TO TXT SIZE 0.10 AT 1/50 SCALE, BY RFR

 

 

Message 3 of 14

rolisonfelipe
Collaborator
Collaborator

The objective is to place the created text within a layer, with a standardized size.
and along with this text enter the name of the layer and selected object.

I already saw an LSP like this here in the group, at the time I couldn't find an application

0 Likes
Message 4 of 14

komondormrex
Mentor
Mentor
Accepted solution

just like that?

 

;**************************************************************************************************************************************************************************

(defun c:layer_length (/ ename_sset escala htxt mtext insertion_point text_angle)
	(if (setq ename_sset (ssget '((0 . "line,lwpolyline,arc"))))
		(progn
			(if (null escala_saved) (setq escala_saved 1))
			(if (= (tblsearch "LAYER" "TOPO-SINAL COTA")) 													; SEARCH IF THE LAYER IS ACTIVE, BY RFR
		  		(command "-LAYER" "M" "TOPO-SINAL COTA" "c" "7" "" "LT" "Continuous" "" "LW" "0.00" "" "") 	; DEFINE THE TEXT LAYER TO BE INSERTED, BY RFR
		    )
		    (if (null (setq ESCALA (getint (strcat "\n SCALE 1:<" (itoa escala_saved) ">"))))        		; REQUEST WORK SCHEDULE, BY RFR
				(setq escala escala_saved)
				(setq escala_saved escala) 															
			)
		    (setq Htxt (* 0.1 ( / 50.0  ESCALA ))) 															; ADJUSTS WORKING SCALE TO TXT SIZE 0.10 AT 1/50 SCALE, BY RFR

			(foreach object (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ename_sset))))
				(setq mtext (vla-addmtext (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
						        	      (vlax-3d-point (trans (setq insertion_point 
										  								(vlax-curve-getpointatdist 
																			object 
																			(* 0.5 (vlax-curve-getdistatparam 
																						object 
																						(vlax-curve-getendparam object))
																			)
																		)
																) 
																1 0
														  )
										  )
						        	      0
						        	      (strcat (vla-get-layer object) " "
				;				            	  "%<\\AcObjProp Object(%<\\_ObjId " 						;	make length field
				;				            	  (itoa (vla-get-objectid line))                            ;	make length field
				;				            	  ">%).Length \\f \"%lu2%pr2\">%"                           ;	make length field
						        	    		  (rtos (vlax-curve-getdistatparam object (vlax-curve-getendparam object)) 2 2)
						        	      )
						    )
				)
		  		(vla-put-attachmentpoint mtext 8)
		  		(vla-put-height mtext htxt)
;				(vlax-put mtext 'backgroundfill 1)															 
				(vla-put-rotation mtext (if (< (* 0.5 pi) 
											   (setq text_angle (angle '(0 0) 
																   		(vlax-curve-getfirstderiv 
																   				object 
																   				(vlax-curve-getparamatpoint object insertion_point)
																   		)
																)
											   ) 
											   (* 1.5 pi)
											)
											   (+ pi text_angle (- (angle '(0 0) (getvar 'ucsxdir))))
											   (+ text_angle (- (angle '(0 0) (getvar 'ucsxdir))))
											)
				)
				(vla-put-insertionpoint mtext (vlax-3d-point insertion_point))
		    )
		)
  	)
	(princ)
)

;**************************************************************************************************************************************************************************

 

updated_2

Message 5 of 14

rolisonfelipe
Collaborator
Collaborator

IT'S WORKING BEAUTIFULLY, IT'S JUST MISSING THIS SMALL DETAIL

 

 

;;----------------------=={ Length at Midpoint }==----------------------;;
;;                                                                      ;;
;;  This program prompts the user for a selection of objects to be      ;;
;;  labelled and proceeds to generate an MText object located at        ;;
;;  the midpoint of each object displaying a Field Expression           ;;
;;  referencing the length of the object.                               ;;
;;                                                                      ;;
;;  The program is compatible for use with Arcs, Circles, Lines,        ;;
;;  LWPolylines, 2D & 3D Polylines, and under all UCS & View settings.  ;;
;;                                                                      ;;
;;  The program will generate MText objects positioned directly over    ;;
;;  the midpoint of each object, and aligned with the object whilst     ;;
;;  preserving text readability. The MText will have a background mask  ;;
;;  enabled and will use the active Text Style and Text Height settings ;;
;;  at the time of running the program.                                 ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright © 2013  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Version 1.0    -    2013-11-12                                      ;;
;;                                                                      ;;
;;  - First release.                                                    ;;
;;----------------------------------------------------------------------;;
;;  Version 1.1    -    2016-01-16                                      ;;
;;                                                                      ;;
;;  - Modified LM:objectid function to account for 64-bit AutoCAD 2008. ;;
;;----------------------------------------------------------------------;;
 
(defun c:midlen ( / *error* ent fmt idx ins ocs par sel spc txt typ uxa )
 
    (setq fmt "%lu6") ;; Field Formatting
 
    (defun *error* ( msg )
        (LM:endundo (LM:acdoc))
        (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
            (princ (strcat "\nError: " msg))
        )
        (princ)
    )
    
    (if
        (setq sel
            (ssget     ;  SOME TYPE OF SELECTION THAT CAN SELECT MULTIPLE LINES AT ONCE
                (list
                   '(0 . "ARC,CIRCLE,LINE,*POLYLINE")
                   '(-4 . "<NOT")
                       '(-4 . "<AND")
                           '(0 . "POLYLINE")
                           '(-4 . "&")
                           '(70 . 80)
                       '(-4 . "AND>")
                   '(-4 . "NOT>")
                    (if (= 1 (getvar 'cvport))
                        (cons 410 (getvar 'ctab))
                       '(410 . "Model")
                    )
                )
            )
        ) 
        (progn
            (setq spc
                (vlax-get-property (LM:acdoc)
                    (if (= 1 (getvar 'cvport))
                        'paperspace
                        'modelspace
                    )
                )
            )
            (setq ocs (trans '(0.0 0.0 1.0) 1 0 t)
                  uxa (angle '(0.0 0.0) (trans (getvar 'ucsxdir) 0 ocs t))
            )
            (LM:startundo (LM:acdoc))
            (repeat (setq idx (sslength sel))
                (setq ent (ssname sel (setq idx (1- idx)))
                      par (vlax-curve-getparamatdist ent (/ (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent)) 2.0))
                      ins (vlax-curve-getpointatparam ent par)
                      typ (cdr (assoc 0 (entget ent)))
                )
 (setq NAMELAYER (vlax-ename->vla-object sel)); SEARCH FOR THE LAYER NAME OF THE SELECTED OBJECT
 
=========================================================================================================================================================
(if (= (tblsearch "LAYER" "TOPO-SINAL COTA")) ; SEARCH IF THE LAYER IS ACTIVE, BY RFR
(command "-LAYER" "M" "TOPO-SINAL COTA" "c" "7" "" "LT" "Continuous" "" "LW" "0.00" "" "")) ; DEFINE THE TEXT LAYER TO BE INSERTED, BY RFR
(setq ESCALA (getint "\n SCALE 1:")) ; REQUEST WORK SCHEDULE, BY RFR
(setq Htxt (* 0.1 ( / 50.0  ESCALA ))) ; ADJUSTS WORKING SCALE TO TXT SIZE 0.10 AT 1/50 SCALE, BY RFR
=========================================================================================================================================================
 (setq txt
(vlax-invoke spc 'addmtext ins 0.0
 
                (strcat " NAMELAYER " " " ;INSERT THE LAYER NAME OF THE SELECTED OBJECT
"%<\\AcObjProp Object(%<\\_ObjId " (LM:objectid (vlax-ename->vla-object ent)) ">%)."
                (cond
                        (   (= "CIRCLE" typ) "Circumference")
                        (   (= "ARC"    typ) "ArcLength")
                        (   "Length"   ))
                        " \\f \"" fmt "\">%")))
                (vla-put-backgroundfill  txt :vlax-true)
                (vla-put-attachmentpoint txt acattachmentpointmiddlecenter)
                (vla-put-insertionpoint  txt (vlax-3D-point ins))
                (vla-put-rotation txt (LM:readable (- (angle '(0.0 0.0 0.0) (trans (vlax-curve-getfirstderiv ent par) 0 ocs t)) uxa)))
(vla-put-height txt Htxt)
(vla-put-layer txt "TOPO-SINAL COTA")  
            )
            (LM:endundo (LM:acdoc))
        )
    )
    (princ)
)
 
 
 
 
 
 
;; Readable  -  Lee Mac
;; Returns an angle corrected for text readability.
 
(defun LM:readable ( a )
    (   (lambda ( a )
            (if (and (< (* pi 0.5) a) (<= a (* pi 1.5)))
                (LM:readable (+ a pi))
                a
            )
        )
        (rem (+ a pi pi) (+ pi pi))
    )
)
 
;; ObjectID  -  Lee Mac
;; Returns a string containing the ObjectID of a supplied VLA-Object
;; Compatible with 32-bit & 64-bit systems
 
(defun LM:objectid ( obj )
    (eval
        (list 'defun 'LM:objectid '( obj )
            (if (wcmatch (getenv "PROCESSOR_ARCHITECTURE") "*64*")
                (if (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
                    (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
                   '(LM:ename->objectid (vlax-vla-object->ename obj))
                )
               '(itoa (vla-get-objectid obj))
            )
        )
    )
    (LM:objectid obj)
)
 
;; Entity Name to ObjectID  -  Lee Mac
;; Returns the 32-bit or 64-bit ObjectID for a supplied entity name
 
(defun LM:ename->objectid ( ent )
    (LM:hex->decstr
        (setq ent (vl-string-right-trim ">" (vl-prin1-to-string ent))
              ent (substr ent (+ (vl-string-position 58 ent) 3))
        )
    )
)
 
;; Hex to Decimal String  -  Lee Mac
;; Returns the decimal representation of a supplied hexadecimal string
 
(defun LM:hex->decstr ( hex / foo bar )
    (defun foo ( lst rtn )
        (if lst
            (foo (cdr lst) (bar (- (car lst) (if (< 57 (car lst)) 55 48)) rtn))
            (apply 'strcat (mapcar 'itoa (reverse rtn)))
        )
    )
    (defun bar ( int lst )
        (if lst
            (if (or (< 0 (setq int (+ (* 16 (car lst)) int))) (cdr lst))
                (cons (rem int 10) (bar (/ int 10) (cdr lst)))
            )
            (bar int '(0))
        )
    )
    (foo (vl-string->list (strcase hex)) nil)
)
 
;; Start Undo  -  Lee Mac
;; Opens an Undo Group.
 
(defun LM:startundo ( doc )
    (LM:endundo doc)
    (vla-startundomark doc)
)
 
;; End Undo  -  Lee Mac
;; Closes an Undo Group.
 
(defun LM:endundo ( doc )
    (while (= 8 (logand 8 (getvar 'undoctl)))
        (vla-endundomark doc)
    )
)
 
;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object
 
(defun LM:acdoc nil
    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:acdoc)
)
 
(vl-load-com)
(princ
    (strcat
        "\n:: MidLen.lsp | Version 1.1 | \\U+00A9 Lee Mac "
        (menucmd "m=$(edtime,0,yyyy)")
        " www.lee-mac.com ::"
        "\n:: Type \"midlen\" to Invoke ::"
    )
)
(princ)
 
;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;

 

 

0 Likes
Message 6 of 14

komondormrex
Mentor
Mentor

multiple lines - what are they? mlines?

0 Likes
Message 7 of 14

sigmmadesigner
Advocate
Advocate

It would be a multiple selection, selection of several simultaneous objects, in this lsp it is necessary to select object by object, and then it changes the extension of each object even though it has several segments

0 Likes
Message 8 of 14

komondormrex
Mentor
Mentor

it is already. and it needs not. have you checked the code?

0 Likes
Message 9 of 14

Kent1Cooper
Consultant
Consultant

@sigmmadesigner wrote:

It would be a multiple selection, selection of several simultaneous objects, in this lsp it is necessary to select object by object, and then it changes the extension of each object even though it has several segments


As mentioned already, it allows selection of multiple objects simultaneously.  I may be misinterpreting, but it sounds like you want to be able to select multiple Line [and also possibly Arc?] objects and if they touch at their ends, have the total length of all of them labeled as if they were a single object [Polyline].  Is that correct?  Should a JOIN command be applied to a multiple selection before the length labeling?

 

If I misunderstood, show us an example of what you mean, with before and after conditions.

Kent Cooper, AIA
0 Likes
Message 10 of 14

rolisonfelipe
Collaborator
Collaborator

PICTURE

0 Likes
Message 11 of 14

komondormrex
Mentor
Mentor

and which entities you want to mark and measure?

0 Likes
Message 12 of 14

rolisonfelipe
Collaborator
Collaborator

THE OBJECTS TO BE QUOTED AND NAMED WILL ONLY BE LINE, POLYLINE AND ARCHES

0 Likes
Message 13 of 14

komondormrex
Mentor
Mentor
Accepted solution

check rewritten code in message 4.

Message 14 of 14

rolisonfelipe
Collaborator
Collaborator

@komondormrex, I had tested it another time and it didn't work! and testing again, you got it right the first time!!!!
it is perfect!!! tailor made!
My best regards

0 Likes