Quick Select Lisp to select all dimensions with same value

Quick Select Lisp to select all dimensions with same value

Anonymous
Not applicable
4,616 Views
21 Replies
Message 1 of 22

Quick Select Lisp to select all dimensions with same value

Anonymous
Not applicable

Need to select all the same dimensions with the same dimension style, layer, and value; and then prompt me to override the dimension, which is not necessary a numeric value.

 

I have been using Quick Select for this task but in most cases I have to work with a lot of dimensions in drawings and is time consuming and repetitive. I have tried the Action recorder and does not go past the command and does not select object type and properties; and I have to enter the numeric value to select all similar dimensions.

 

Can any help me out with a AutoLisp command that can do all this?

0 Likes
4,617 Views
21 Replies
Replies (21)
Message 2 of 22

dbhunia
Advisor
Advisor

@Anonymous wrote:

Need to select all the same dimensions with the same dimension style, layer, and value; and then prompt me to override the dimension, which is not necessary a numeric value.

 

I have been using Quick Select for this task but in most cases I have to work with a lot of dimensions in drawings and is time consuming and repetitive. I have tried the Action recorder and does not go past the command and does not select object type and properties; and I have to enter the numeric value to select all similar dimensions.

 

Can any help me out with a AutoLisp command that can do all this?


 

Try this......(Roughly Tested in AutoCAD 2007)

 

(defun c:valc (/ detail style layer value valchange N);put temp variables
(setq detail (entget (car (entsel "\nPick a Dimension to get Dimension Layer, Style & value: "))))
(setq style (cdr (assoc 3 detail)))
(setq layer (cdr (assoc 8 detail)))
(setq value (cdr (assoc 42 detail)))
(setq valchange (getstring "\nEnter new Value to override the dimension value: "))
(Setq sset (ssget "_A" (list '(0 . "DIMENSION") (cons 3 style) (cons 8 layer) (cons 42 value))))
(repeat (setq N (sslength sset))
	(setq Data (ssname sset (setq N (- N 1))))
	(setq EData (entget Data))
	(entmod(subst (cons 1 valchange) (assoc 1 EData) EData))
)
)

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 22

Kent1Cooper
Consultant
Consultant

That approach may give you trouble, because real-number values like the measured distance of a Dimension can have tiny differences way down in far-off decimal places that will cause them to not  be considered equal in (ssget) selection or in an (=) function.  But assuming they're drawn in such a way that they are  truly equal so you don't have that problem, you can simplify that code.  It has unnecessary separations and re-associations in it.  For example, for the Style, it extracts the value from its association with a 3, and then re-associates it with a 3 to put into the (ssget) filter.  You can simply leave it in its association with that 3 the whole time, and use that pairing directly, without  ever extracting the value out of it, and similarly with the others:

 

....
(setq detail (entget (car (entsel "\nPick a Dimension to get Dimension Layer, Style & value: "))))
;; eliminate style, layer and value variables entirely ;; (setq valchange (getstring "\nEnter new Value to override the dimension value: ")) (Setq sset (ssget "_A" (list (assoc 0 detail) (assoc 3 detail) (assoc 8 detail) (assoc 42 detail)))) (repeat ....
Kent Cooper, AIA
Message 4 of 22

dbhunia
Advisor
Advisor

Yes @Kent1Cooper you are right unnecessarily I am extracting the values and then re-associating those values..... where I can directly use those properties to make filter...... like this...

 

(defun c:valc (/ detail valchange sset N Data EData)
(setvar 'cmdecho 0) (setq detail (entget (car (entsel "\nPick a Dimension to get Dimension Layer, Style & value: ")))) (setq valchange (getstring T "\nEnter new Value to override the dimension value: ")) (setq sset (ssget "_A" (list (assoc 0 detail) (assoc 3 detail) (assoc 8 detail) (assoc 42 detail)))) (repeat (setq N (sslength sset)) (setq Data (ssname sset (setq N (- N 1)))) (setq EData (entget Data)) (entmod (subst (cons 1 valchange) (assoc 1 EData) EData)) )
(setvar 'cmdecho 1)
(princ) )

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 22

Anonymous
Not applicable

I need to learn AutoLisp! This is nearly perfect.

 

I forgot to mention that Quick Select shows the quantity AND value (by drawing unit). Is there a way to show the selected changes quantity and value somewhere, like on the command line?

0 Likes
Message 6 of 22

devitg
Advisor
Advisor

It would be easy , if you upload a sample.dwg , and ask the whole task to do.

0 Likes
Message 7 of 22

dbhunia
Advisor
Advisor

@Anonymous wrote:

I need to learn AutoLisp! This is nearly perfect.

 

I forgot to mention that Quick Select shows the quantity AND value (by drawing unit). Is there a way to show the selected changes quantity and value somewhere, like on the command line?


 

Try this....

 

(defun c:valc (/ detail valchange sset N Data EData CDS CDP)
(vl-load-com)
(setvar 'cmdecho 0)
(setq detail (entget (car (entsel "\nPick a Dimension to get Dimension Layer, Style & value: "))))
(setq CDS (getvar 'dimstyle))
(setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-put-activeDimstyle acdoc (vla-item (vla-get-Dimstyles acdoc) (cdr (assoc 3 detail))))
(setq CDP (getvar 'dimdec))
(vla-put-activeDimstyle acdoc (vla-item (vla-get-Dimstyles acdoc) CDS))
(setq sset (ssget "_A" (list (assoc 0 detail) (assoc 3 detail) (assoc 8 detail) (assoc 42 detail))))
(princ (strcat "\n" (rtos (sslength sset) 2 0) " item(s) selected."))
(sssetfirst nil sset)
(setq valchange (getstring T "\nEnter new Value to override the dimension value: "))
   (repeat (setq N (sslength sset))
	(setq Data (ssname sset (setq N (- N 1))))
	(setq EData (entget Data))
	(entmod (subst (cons 1 valchange) (assoc 1 EData) EData))
   )
(princ (strcat "\n" (rtos (sslength sset) 2 0) " selected item(s) " "Value has been changed from (" (rtos (cdr (assoc 42 detail)) 2 CDP) ") To (" valchange ")..."))
;;;(sssetfirst nil nil)
(setvar 'cmdecho 1)
(princ)
)

If you want not to get selected the Changed Dimensions then just remove the RED semicolons from the Code....

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 8 of 22

Anonymous
Not applicable

This works great when it works but for some reason it sometimes leaves one of the grouped duplicates out. For example, it would select all 6 out of 7, or 10 out of 11 duplicates. Sometimes it doesn't work at all.

0 Likes
Message 9 of 22

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... it sometimes leaves one of the grouped duplicates out. .... Sometimes it doesn't work at all.


 

That is most likely because of the issue described at the beginning of Message 3.  To overcome that, I think you would need to remove the 42-code entry from the selection-set filter, and just find all Dimensions of the same type and Style and Layer [no matter what their measured distance].  Then step through that set, and for each one, compare its measured distance using an (equal) function with a fuzz factor  to allow it to be different down at the 11th decimal place or something, and if it matches within the tolerance, assign the override text to it.

Kent Cooper, AIA
0 Likes
Message 10 of 22

dbhunia
Advisor
Advisor

can you post your drawing in AutoCAD 2007 format......


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 11 of 22

devitg
Advisor
Advisor

as ditto 

 

 

 The same as stated above or before.
0 Likes
Message 12 of 22

Anonymous
Not applicable

I have attached the drawing in 2007 format. You will see all the polylines dimensioned but I would like to isolate all the common values together and relabel them.

 

I was wrong about the Quick Select command displaying the quantity and measurement of the selected dimension; it is the properties box that I have open that shows me this but the dimension still needs to be selected.

0 Likes
Message 13 of 22

devitg
Advisor
Advisor

It is because some dim are not the same style , despite it have the same value 

 

not all the same value -have same style.GIF

0 Likes
Message 14 of 22

Anonymous
Not applicable

I don't think so. There is only the "standard" dim style and the one I created "DIM_LABEL".

I isolated the layer and selected all and they are all the same dim style and layer.

0 Likes
Message 15 of 22

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:
....
That is most likely because of the issue described at the beginning of Message 3.  ... you would need to ... just find all Dimensions of the same type and Style and Layer [no matter what their measured distance].  Then step through that set....

 

Something like this [untested]:

....
(setq sset (ssget "_A" (list (assoc 0 detail) (assoc 3 detail) (assoc 8 detail)))); without value
(princ (strcat "\n" (rtos (sslength sset) 2 0) " item(s) selected."))
(sssetfirst nil sset)
(setq valchange (getstring T "\nEnter new Value to override the dimension value: "))
(repeat (setq N (sslength sset))
  (setq Data (ssname sset (setq N (- N 1))))
  (setq EData (entget Data))
  (if (equal (cdr (assoc 42 detail)) (cdr (assoc 42 EData)) 1e-4); same within tolerance
    (entmod (subst (cons 1 valchange) (assoc 1 EData) EData)); then
  ); if
); repeat
....
Kent Cooper, AIA
Message 16 of 22

dbhunia
Advisor
Advisor

Hi @Kent1Cooper I would like to rearrange the line sequence.... like this....

 

 

(defun c:valc (/ detail valchange sset N Data EData CDS CDP SS)
(vl-load-com)
(setvar 'cmdecho 0)
(setq detail (entget (car (entsel "\nPick a Dimension to get Dimension Layer, Style & value: "))))
(setq CDS (getvar 'dimstyle))
(setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-put-activeDimstyle acdoc (vla-item (vla-get-Dimstyles acdoc) (cdr (assoc 3 detail))))
(setq CDP (getvar 'dimdec))
(vla-put-activeDimstyle acdoc (vla-item (vla-get-Dimstyles acdoc) CDS))
(setq sset (ssget "_A" (list (assoc 0 detail) (assoc 3 detail) (assoc 8 detail)))); without value
(setq SS (ssadd))
(repeat (setq N (sslength sset))
  (setq Data (ssname sset (setq N (- N 1))))
  (setq EData (entget Data))
  (if (equal (cdr (assoc 42 detail)) (cdr (assoc 42 EData)) 1e-4); same within tolerance
      (ssadd Data ss)
  ); if
); repeat
(princ (strcat "\n" (rtos (sslength SS) 2 0) " item(s) selected."))
(sssetfirst nil ss)
(setq valchange (getstring T "\nEnter new Value to override the dimension value: "))
(repeat (setq N (sslength SS))
  (setq Data (ssname SS (setq N (- N 1))))
  (setq EData (entget Data))
  (entmod (subst (cons 1 valchange) (assoc 1 EData) EData)); then
)
(princ (strcat "\n" (rtos (sslength ss) 2 0) " selected item(s) " "Value has been changed from (" (rtos (cdr (assoc 42 detail)) 2 CDP) ") To (" valchange ")..."))
;;;(sssetfirst nil nil)
(setvar 'cmdecho 1)
(princ)
)

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 17 of 22

Kent1Cooper
Consultant
Consultant

@dbhunia wrote:

Hi @Kent1Cooper I would like to rearrange the line sequence....


 

That makes sense, to neither report the number of nor highlight any Dimensions until after they have been narrowed down to the ones of the same [within tolerance] measurement.

Kent Cooper, AIA
0 Likes
Message 18 of 22

Anonymous
Not applicable

Thank you! I really appreciate all the help!

 

I've tried out the lisp routine and there is one more minor detail that would be helpful; which is to be able to deselect object(s) you don't want to change. At the moment, you're stuck in the prompt mode and can't deselect until you have entered a value.

 

0 Likes
Message 19 of 22

dbhunia
Advisor
Advisor

Hi @Kent1Cooper I am sorry my intention was not to hearts you, only thing was to complete the sequence.

 

I am really sorry ... 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 20 of 22

dbhunia
Advisor
Advisor

For......

 


@Anonymous wrote:

Thank you! I really appreciate all the help!

 

I've tried out the lisp routine and there is one more minor detail that would be helpful; which is to be able to deselect object(s) you don't want to change. At the moment, you're stuck in the prompt mode and can't deselect until you have entered a value.

 


 

Try this........

 

(defun c:valc (/ detail valchange sset N Data EData CDS CDP SS)
(vl-load-com)
(setvar 'cmdecho 0)
(setq detail (entget (car (entsel "\nPick a Dimension to get Dimension Layer, Style & value: "))))
(setq CDS (getvar 'dimstyle))
(setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-put-activeDimstyle acdoc (vla-item (vla-get-Dimstyles acdoc) (cdr (assoc 3 detail))))
(setq CDP (getvar 'dimdec))
(vla-put-activeDimstyle acdoc (vla-item (vla-get-Dimstyles acdoc) CDS))
(setq sset (ssget "_A" (list (assoc 0 detail) (assoc 3 detail) (assoc 8 detail)))); without value
(setq SS (ssadd))
(repeat (setq N (sslength sset))
  (setq Data (ssname sset (setq N (- N 1))))
  (setq EData (entget Data))
  (if (equal (cdr (assoc 42 detail)) (cdr (assoc 42 EData)) 1e-4); same within tolerance
      (ssadd Data ss)
  ); if
); repeat
(princ (strcat "\n" (rtos (sslength SS) 2 0) " item(s) selected to Change the dimension Values(s)..."))
(princ "\nPress Enter to Continue with Selected iteam(s) or Select/Deselect the dimension(s) you want to Add/Remove from Selection(s)...")
(command "select" ss)
(while (> (getvar 'cmdactive) 0) (command pause))
(sssetfirst nil (setq ss (ssget "_P" '((0 . "DIMENSION")))))
(setq valchange (getstring T (strcat "\nEnter new Value to override the dimension value of " (rtos (sslength SS) 2 0) " selected item(s): ")))
(repeat (setq N (sslength SS))
  (setq Data (ssname SS (setq N (- N 1))))
  (setq EData (entget Data))
  (entmod (subst (cons 1 valchange) (assoc 1 EData) EData)); then
)
(princ (strcat "\n" (rtos (sslength ss) 2 0) " selected item(s) " "Value has been changed from (" (rtos (cdr (assoc 42 detail)) 2 CDP) ") To (" valchange ")..."))
;;;(sssetfirst nil nil)
(setvar 'cmdecho 1)
(princ)
)

 

Hopefully these are all of your Needs.....

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes