Quick Select / Filter

Quick Select / Filter

Anonymous
Not applicable
3,632 Views
30 Replies
Message 1 of 31

Quick Select / Filter

Anonymous
Not applicable

Hi all!

 

I need to select all dimensions with certain style.
I did not find the specific DXF of the "dimension style", to be able to use in the filter.

 

   (setq sel (ssget "x" (list (cons 0 "dimension") (cons DXF### "dimension style"))))

 

How can I select all these dimensions with quick selection?

 

 

Ty.

0 Likes
Accepted solutions (3)
3,633 Views
30 Replies
Replies (30)
Message 21 of 31

Anonymous
Not applicable

Good Morning!

 

Look at me here again.

I found one more modification I had not noticed so far.

 

Leader's arrowhead is small, not visible, and Leader does not follow dimstyle and annotative scale.

 

Before.JPG

After.JPG

 

(defun c:UpdateDimensions25 ( / dimStyleMappings dimStyleMap sel cnt ent cannoscale-sav)
  ; Insert block and explode it
  (command "ddinsert" "s" "25" pause)
  (command "explode" (entlast))

  ;; Set the Dimension Style Mappings (old_style new_style)
  (setq dimStyleMappings (list '("UM_25.000000" "Unidade cm")
                               '("UM_20.000000" "Unidade cm")))

;; Change the current annotation scale
  (setq cannoscale-sav (getvar "cannoscale"))
  (setvar "cannoscale" "1:25 cm")
 
  ;; Step through the dimension style mappings
  (foreach dimStyleMap dimStyleMappings
    ;; Select the dimensions that use the old style in the current mapping
    (if (setq sel (ssget "X" (list (cons 0 "dimension") (cons 3 (nth 0 dimStyleMap)))))
      (progn
        (setq cnt 0)

        ;; Step through all select objects
        (while (< cnt (sslength sel))
          (setq ent (ssname sel cnt)
                  cnt (1+ cnt))
 
          ;; Change the style of the selected dimension
          (setpropertyvalue ent "DimensionStyle" (tblobjname "dimstyle" (nth 1 dimStyleMap)))
 
          ;; Change the Linear Scale Factor for "UM_25.000000" style only
          (if (= (nth 0 dimStyleMap) "UM_20.000000")
            (setpropertyvalue ent "Dimlfac" 0.80)
          )
        )
      )
    )
  )
 
  ;; Move the text of all dimensions Home
  (command "_.dimedit" "_Home" "_all" "")

  ;; Restore the previous annotation scale
  (setvar "cannoscale" cannoscale-sav)

 (princ)
)
0 Likes
Message 22 of 31

ambrosl
Autodesk
Autodesk

A leader object is similar to, but different from a dimension.  You can follow the same selection and looping process through based on the current code.

 

You can use the following code snippet to get the DXF Code 0 of an object in a drawing:

(assoc 0 (entget (car (entsel))))

Along the same lines, the following can be used to return the property names that can be used with the setpropertyvalue and its companion function getpropertyvalue:

(dumpallproperties (car (entsel)))

The following demonstrates how to select and modify a leader object, you might need to adjust the logic related to the Arrowhead Size if it should be applied to one or the other dimension style:

 

 

(defun c:UpdateDimensions25 ( / dimStyleMappings dimStyleMap sel cnt ent cannoscale-sav)
  ; Insert block and explode it
  (command "ddinsert" "s" "25" pause)
  (command "explode" (entlast))

  ;; Set the Dimension Style Mappings (old_style new_style)
  (setq dimStyleMappings (list '("UM_25.000000" "Unidade cm")
                               '("UM_20.000000" "Unidade cm")))

  ;; Change the current annotation scale
  (setq cannoscale-sav (getvar "cannoscale"))
  (setvar "cannoscale" "1:25 cm")
 
  ;; Step through the dimension style mappings
  (foreach dimStyleMap dimStyleMappings
    ;; Select the dimensions that use the old style in the current mapping
    (if (setq sel (ssget "X" (list (cons 0 "dimension") (cons 3 (nth 0 dimStyleMap)))))
      (progn
        (setq cnt 0)

        ;; Step through all select objects
        (while (< cnt (sslength sel))
          (setq ent (ssname sel cnt)
                  cnt (1+ cnt))
 
          ;; Change the style of the selected dimension
          (setpropertyvalue ent "DimensionStyle" (tblobjname "dimstyle" (nth 1 dimStyleMap)))
 
          ;; Change the Linear Scale Factor for "UM_25.000000" style only
          (if (= (nth 0 dimStyleMap) "UM_20.000000")
            (setpropertyvalue ent "Dimlfac" 0.80)
          )
        )
      )
    )

    ;; Select the leaders that use the old style in the current mapping
    (if (setq sel (ssget "X" (list (cons 0 "leader") (cons 3 (nth 0 dimStyleMap)))))
      (progn
        (setq cnt 0)

        ;; Step through all select objects
        (while (< cnt (sslength sel))
          (setq ent (ssname sel cnt)
                  cnt (1+ cnt))
 
          ;; Change the style of the selected dimension
          (setpropertyvalue ent "DimensionStyle" (tblobjname "dimstyle" (nth 1 dimStyleMap)))
 
          ;; Change the Arrowhead Size for "UM_25.000000" style only
          (if (= (nth 0 dimStyleMap) "UM_20.000000")
            (setpropertyvalue ent "Dimasz" 4.0)
          )
        )
      )
    )
  )
 
  ;; Move the text of all dimensions Home
  (command "_.dimedit" "_Home" "_all" "")

  ;; Restore the previous annotation scale
  (setvar "cannoscale" cannoscale-sav)

 (princ)
)

 



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

Anonymous
Not applicable

I added the code but there was no change from Leader, but no error occurred either.

 

The code to get the DXF and property names Useful, 
I did not know

0 Likes
Message 24 of 31

ambrosl
Autodesk
Autodesk

Looks like your leader is using the Standard style... you will need to change:

  ;; Set the Dimension Style Mappings (old_style new_style)
  (setq dimStyleMappings (list '("UM_25.000000" "Unidade cm")
                               '("UM_20.000000" "Unidade cm")))

to:

  ;; Set the Dimension Style Mappings (old_style new_style)
  (setq dimStyleMappings (list '("UM_25.000000" "Unidade cm")
                               '("UM_20.000000" "Unidade cm")
                               '("STANDARD" "Unidade cm")))

The above change will also affect dimension styles that are assigned the STANDARD dimension style.  Will the leaders that you want to convert only use the STANDARD dimension style?  If so, it would be better to move the leader code outside the FOREACH statement and select only leaders assigned the STANDARD dimension style.



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

Anonymous
Not applicable

Good Morning, Adding the new code did not change.

'("STANDARD" "Unidade cm")

All leaders as well as dimensions with DimStyle "Standard" can be converted to the same DimStyle (UM_25.000000). Also all the leaders I want to change are in the "Standard".

0 Likes
Message 26 of 31

ambrosl
Autodesk
Autodesk

Can you post a sample drawing with the leader object you are trying to convert?



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

Anonymous
Not applicable

Attached.

Bloco_Teste.dwg is the original file
Bloco_Teste_routine.dwg is the file applied to the routine.

The Bloco_Teste_routine.dwg should all leaders set to Dimstyle "Unidade cm" and arrow size 4.

0 Likes
Message 28 of 31

ambrosl
Autodesk
Autodesk

Below is the revised code, it does update the "Standard" to "Unidade cm" style for leader objects based on the sample drawing you posted and some of the properties for a leader.  The LEADER command uses settings from the current Dimension Style when creating a leader, but the leader created doesn't maintain a full relationship to the dimension style like a dimension object does.  So changing just the style doesn't necessarily update all values of a leader object using AutoLISP like it does for a dimension.  Updating leader objects will require some additional work, such as getting a value from the Dimension style and then updating the leader object with that value; you can see an example of that with the Arrowhead Block in the revised code.

 

(defun c:UpdateDimensions25 ( / dimStyleMappings dimStyleMap sel cnt ent) ; cannoscale-sav)
  ; Insert block and explode it
  (command "ddinsert" "s" "25" pause)
  (command "explode" (entlast))

  ;; Set the Dimension Style Mappings (old_style new_style)
  (setq dimStyleMappings (list '("UM_25.000000" "Unidade cm")
                               '("UM_20.000000" "Unidade cm")
			       '("Standard" "UM_25.000000")))

  ;; Change the current annotation scale
  ;;(setq cannoscale-sav (getvar "cannoscale"))
  (setvar "cannoscale" "1:25 cm")
 
  ;; Step through the dimension style mappings
  (foreach dimStyleMap dimStyleMappings
    ;; Select the dimensions that use the old style in the current mapping
    (if (setq sel (ssget "X" (list (cons 0 "dimension") (cons 3 (nth 0 dimStyleMap)))))
      (progn
        (setq cnt 0)

        ;; Step through all select objects
        (while (< cnt (sslength sel))
          (setq ent (ssname sel cnt)
                  cnt (1+ cnt))
 
          ;; Change the style of the selected dimension
          (setpropertyvalue ent "DimensionStyle" (tblobjname "dimstyle" (nth 1 dimStyleMap)))
 
          ;; Change the Linear Scale Factor for "UM_20.000000" style only
          (if (= (strcase (nth 0 dimStyleMap)) "UM_20.000000")
            (setpropertyvalue ent "Dimlfac" 0.80)
          )
        )
      )
    )
  )

  ;; Select the leaders that use the Standard style and change them to "Unidade cm"
  (if (setq sel (ssget "X" (list (cons 0 "leader") (cons 3 "Standard"))))
    (progn
      (setq cnt 0)

      ;; Step through all select objects
      (while (< cnt (sslength sel))
        (setq ent (ssname sel cnt)
                cnt (1+ cnt))
 
        ;; Change the style of the selected leader
        (setpropertyvalue ent "DimensionStyle" (tblobjname "dimstyle" "Unidade cm"))

	; Change the arrowhead block assigned to the leader
	(setq val (vl-catch-all-apply 'getpropertyvalue (list (tblobjname "dimstyle" "Unidade cm") "dimldrblk")))
	(if (vl-catch-all-error-p val)
          (setpropertyvalue ent "ArrowheadType" "_Closed")
          (setpropertyvalue ent "ArrowheadType" (getpropertyvalue val "Name"))
	)
	  
        ;; Change the Arrowhead Size
        (setpropertyvalue ent "Dimasz" 1.0)
      )
    )
  )
  
  ;; Move the text of all dimensions Home
  (command "_.dimedit" "_Home" "_all" "")

  ;; Restore the previous annotation scale
  ;;(setvar "cannoscale" cannoscale-sav)

 (princ)
)

I turned off the restoring of the Annotation Scale at the end because the leaders were disappearing since it was returning to 1:50 cm after each time it ran, and the leaders/dimensions were being assigned 1:25 cm.

 

Hope this helps you get closer to your goal.



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

Anonymous
Not applicable

Hello


The routine did not work for me.

 

On line 9, it is either correct "UM_25.000000" or "Unidade cm" ?

 

The value "name" of the line below, what function is it doing in the routine?
(setpropertyvalue ent "ArrowheadType" (getpropertyvalue val "Name"))

 

 

Quote:

"I turned off the restoring of the Annotation Scale at the end because the leaders were disappearing since it was returning to 1:50 cm after each time it ran, and the leaders/dimensions were being assigned 1:25 cm."

 

There is no problem about that.

0 Likes
Message 30 of 31

ambrosl
Autodesk
Autodesk

Sorry for the delayed response..

 

(setpropertyvalue ent "ArrowheadType" (getpropertyvalue val "Name")) changes the arrowhead of the leader to match the DimStyle it is being assigned. There is something with the leaders in your drawing that don't behave the same as those created in a new drawing.  It could be something related to property overrides but I didn't looked very closely into the problem.  When the DimStyle is changed via the code, the arrowheads didn't change as they should and do when you change the DimStyle of the leader from the ribbon.

 

As for Line 9, what is correct... it depends on which DimStyle should be assigned to the leader.

 

I can create a Screencast that demonstrates the routine does work on the sample drawings you posted, but whether it is performing all the changes you are expecting I am not sure.  I did notice that the DWG file appears to have been created by a non-Autodesk application which could be causing some problems but it is hard to say.



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

Anonymous
Not applicable

Good Morning!

Thanks for the feedback.

I was on a trip, I was able to check the forum today.

The file was created by third-party software.

I will continue using the first routines, leaving the changes of the leaders. Maybe do a routine to select the leaders to then apply the modifications.

0 Likes