Dimensions text list by X direction

Dimensions text list by X direction

avinash00002002
Collaborator Collaborator
571 Views
16 Replies
Message 1 of 17

Dimensions text list by X direction

avinash00002002
Collaborator
Collaborator

Hi !

 

I have some dimensions which is selected by window and get list by x direction.

 

Any Idea how to do it.

 

Thanks,

 

Avinash Patil

0 Likes
Accepted solutions (2)
572 Views
16 Replies
Replies (16)
Message 2 of 17

komondormrex
Mentor
Mentor

a function (get_dims) for getting selected dim overrides, left to right sorted

(defun get_dims (/ dim_sset)
	(if (setq dim_sset (ssget '((0 . "dimension"))))
		(mapcar 'cdr
				(vl-sort (mapcar '(lambda (dim) (cons (car (vlax-get dim 'textposition)) 
													  (vla-get-textoverride dim)
												)
								  ) 
								  (mapcar 'vlax-ename->vla-object 
										   (vl-remove-if 
												'listp 
												(mapcar 'cadr (ssnamex dim_sset))
										   )
								  )
						 )
						 '(lambda (dim_1 dim_2) (< (car dim_1) (car dim_2)))
				)
	   )
	)
)

 

0 Likes
Message 3 of 17

avinash00002002
Collaborator
Collaborator

Hi!

Thanks for reply it works.

 

if instead of Dimensions I have texts same as dimension so, what will be the code.

 

Thanks,

Avinash

0 Likes
Message 4 of 17

komondormrex
Mentor
Mentor
Accepted solution

hey,

it will be as this

 

(defun get_texts (/ text_sset)
	(if (setq text_sset (ssget '((0 . "text"))))
		(mapcar 'cdr
				(vl-sort (mapcar '(lambda (text) (cons (car (vlax-get text 'insertionpoint)) 
													  (vla-get-textstring text)
												)
								  ) 
								  (mapcar 'vlax-ename->vla-object 
										   (vl-remove-if 'listp 
												(mapcar 'cadr (ssnamex text_sset))
										   )
								  )
						 )
						 '(lambda (text_1 text_2) (< (car text_1) (car text_2)))
				)
	   )
	)
)

 

0 Likes
Message 5 of 17

avinash00002002
Collaborator
Collaborator

Hi!

 

I have required that select all dimensions, sort it by X-direction, then sumation of 1st dim to second, second dim to 3rd , like text written in the below section but text is already exist, first have to select dimensions and then text and it will change the text.

0 Likes
Message 6 of 17

komondormrex
Mentor
Mentor

hi,

check the custom command put_successive_sum_text.

 

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

(defun successive_sum (_list / sum_list)
  	(setq _list (reverse _list))
	(while _list (setq sum_list (cons (apply '+ _list) sum_list))
		(setq _list (cdr _list))
  	)
  	sum_list
)

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

(defun c:put_successive_sum_text (/ sset)
  	(prompt "\nSelect all dimensions and all corresponding texts...")
	(if (setq sset (ssget '((0 . "dimension,text"))))
		  (mapcar '(lambda (text_object successive_sum) (vla-put-textstring text_object (itoa successive_sum)))
			  (vl-sort (vl-remove-if-not '(lambda (object) (= "AcDbText" (vla-get-objectname object)))
				     	     (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex sset))))
		    	 	   )
				   '(lambda (text_1 text_2) (< (car (vlax-get text_1 'insertionpoint)) (car (vlax-get text_2 'insertionpoint))))
			  )
			  (successive_sum
				  (mapcar 'atoi
					  (mapcar 'cdr
						(vl-sort (mapcar '(lambda (dim) (cons (car (vlax-get dim 'textposition)) (vla-get-textoverride dim))) 
								  (vl-remove-if-not '(lambda (object) (= "AcDbRotatedDimension" (vla-get-objectname object)))
										     (mapcar 'vlax-ename->vla-object 
											     (vl-remove-if 'listp (mapcar 'cadr (ssnamex sset)))
										     )
							    	  )
							 )
							 '(lambda (dim_1 dim_2) (< (car dim_1) (car dim_2)))
						)
					)
				   )
			  )
		)
  	)
  	(princ)
)

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

 

 

0 Likes
Message 7 of 17

avinash00002002
Collaborator
Collaborator

Instead of dims I have text in both sides?

0 Likes
Message 8 of 17

avinash00002002
Collaborator
Collaborator

I have attached sample dwg.

0 Likes
Message 9 of 17

avinash00002002
Collaborator
Collaborator

help required

0 Likes
Message 10 of 17

komondormrex
Mentor
Mentor
Accepted solution

check this one

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

(defun successive_sum (_list / sum_list)
    (setq _list (reverse _list))
  (while _list (setq sum_list (cons (apply '+ _list) sum_list))
    (setq _list (cdr _list))
    )
    sum_list
)

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

(defun c:put_successive_sum_text (/ sset line_point_list selected_objects text_to_sum_list)
  (vl-catch-all-apply 'setvar (list 'textgapselection 1))
    (prompt "\nSelect two rows of texts with remnant hor line of dimensions...")
  (if (setq sset (ssget '((0 . "text,line"))))
      (mapcar '(lambda (successive_sum text_object) (vla-put-textstring text_object (itoa successive_sum)))
          (successive_sum
          (mapcar 'atoi
                 (mapcar '(lambda (text) (vla-get-textstring text))
                     (progn
                         (setq line_point_list
                             (apply 'append
                                (mapcar '(lambda (line) (list (vlax-get line 'startpoint) (vlax-get line 'endpoint)))
                                     (vl-remove-if '(lambda (object) (or (= "AcDbText" (vla-get-objectname object)) 
                                                       (and (not (equal 0 (vla-get-angle object) 1e-4))
                                                          (not (equal pi (vla-get-angle object) 1e-4))
                                                       )
                                                     )
                                            )
                                            (setq selected_objects 
                                           (mapcar 'vlax-ename->vla-object 
                                                 (vl-remove-if 'listp (mapcar 'cadr (ssnamex sset)))
                                           )
                                      )
                                       )
                                ) 
                             )
                         )
                         (setq text_to_sum_list 
                      (vl-sort (mapcar 'vlax-ename->vla-object 
                                    (vl-remove-if 'listp 
                                        (mapcar 'cadr 
                                              (ssnamex (ssget "_f" 
                                                      (list 
                                                      (list (apply 'min 
                                                             (mapcar 'car line_point_list)
                                                          ) 
                                                          (cadar line_point_list)
                                                      )
                                                                (list (apply 'max 
                                                             (mapcar 'car line_point_list)
                                                          ) 
                                                          (cadar line_point_list)
                                                      )
                                                                )
                                                               '((0 . "text"))
                                                              )
                                                       )
                                                )
                                    )           
                                 )       
                                '(lambda (text_1 text_2) (< (car (vlax-get text_1 'insertionpoint)) 
                                          (car (vlax-get text_2 'insertionpoint))
                                        )
                            )
                           )
                         )
                     )
                )
           )
           )

(vl-sort (vl-remove-if '(lambda (object) (or (= "AcDbLine" (vla-get-objectname object)) 
                                   (member object text_to_sum_list)
                                 )
                        )
                      selected_objects
                 )
                '(lambda (text_1 text_2) (< (car (vlax-get text_1 'insertionpoint)) (car (vlax-get text_2 'insertionpoint))))
           )
    )
    )
    (princ)
)
0 Likes
Message 11 of 17

Kent1Cooper
Consultant
Consultant

The drawing clearly does not represent reality at all:

Kent1Cooper_0-1756920236398.png

[The 40-unit space is clearly not only half the 80-unit space, nor is the 178-unit space more than twice the 80-unit space as it would be if it were "real."]

BUT IF you had them drawn at the actual spacings, you could just set the UCS origin at the left-end position, and use ORDINATE DIMENSIONS to get the cumulative-distance result you want:  AND IF you also use actual linear DIMENSIONS for the distances between, then when you alter positions by for example Stretching, both the affected intermediate-spacing linear Dimensions and the cumulative-distance Ordinate Dimensions would correct themselves accordingly, without your needing to do anything about it.  As you have it, if you change any positions, you would need to alter the Text for any spacings that changed, wipe out the now-invalid cumulative-distance numbers, and run the routine all over again to get new cumulative numbers.

Kent Cooper, AIA
0 Likes
Message 12 of 17

avinash00002002
Collaborator
Collaborator

No, its a text only not a dimension

0 Likes
Message 13 of 17

avinash00002002
Collaborator
Collaborator

It gives error , ; error: too many arguments

0 Likes
Message 14 of 17

komondormrex
Mentor
Mentor

post a file which gives an error. 

0 Likes
Message 15 of 17

avinash00002002
Collaborator
Collaborator

It required lines always? If lines are not present only text present this routine is not work.

0 Likes
Message 16 of 17

komondormrex
Mentor
Mentor

here is simple one code with two step selection of intervals texts and texts for intervals sums.

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

(defun successive_sum (_list / sum_list)
    (setq _list (reverse _list))
  (while _list (setq sum_list (cons (apply '+ (mapcar 'atoi _list)) sum_list))
    (setq _list (cdr _list))
    )
    sum_list
)

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

(defun c:put_successive_sum_text (/ sset_intervals sset_succ_sum)
    (prompt "\nSelect texts with intervals...")
  (if (setq sset_intervals (ssget '((0 . "text"))))
    (progn
        (prompt "\nSelect texts for successive sums...")
      (if (setq sset_succ_sum (ssget '((0 . "text"))))
          (mapcar '(lambda (text_object successive_sum) (vla-put-textstring text_object (itoa successive_sum)))
                (vl-sort (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex sset_succ_sum))))
                      '(lambda (text_1 text_2) (< (car (vlax-get text_1 'insertionpoint)) 
                                 (car (vlax-get text_2 'insertionpoint))
                                )
                    )
              )
             (successive_sum
              (mapcar '(lambda (text) (vla-get-textstring text))
                      (vl-sort (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex sset_intervals))))
                            '(lambda (text_1 text_2) (< (car (vlax-get text_1 'insertionpoint)) 
                                         (car (vlax-get text_2 'insertionpoint))
                                     )
                         )
                      )
              )
             )
          )
      )
    )
  )
  (princ)
)

;************************************************************************************************************************************
0 Likes
Message 17 of 17

avinash00002002
Collaborator
Collaborator

Yes, when lines are present then it works fine, when lines are not present like dimension lines it gives error.

0 Likes