Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Quick Select / Filter

30 REPLIES 30
SOLVED
Reply
Message 1 of 31
Anonymous
3155 Views, 30 Replies

Quick Select / Filter

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.

30 REPLIES 30
Message 2 of 31
ambrosl
in reply to: Anonymous

A dimension style is assigned the DXF Code 3.  The following selects all dimensions with the Standard style:

 

(setq sel (ssget "x" (list (cons 0 "dimension") (cons 3 "Standard"))))



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
Message 3 of 31
Kent1Cooper
in reply to: Anonymous

3

Kent Cooper, AIA
Message 4 of 31
Kent1Cooper
in reply to: ambrosl


@ambrosl wrote:

.... 

(setq sel (ssget "x" (list (cons 0 "dimension") (cons 3 "Standard"))))


Or, since all values are known/fixed, you can simply use a "quoted" list without the (cons) functions:

 

(setq sel (ssget "x" '((0 . "dimension") (3 . "Standard"))))

Kent Cooper, AIA
Message 5 of 31
Anonymous
in reply to: ambrosl


@ambrosl wrote:

A dimension style is assigned the DXF Code 3.  The following selects all dimensions with the Standard style:

 

(setq sel (ssget "x" (list (cons 0 "dimension") (cons 3 "Standard"))))


Works fine! Ty

 

I'm not aware of lisp, I'm trying to make my job easier by creating a routine.

That is why these simple questions appear.

If you can help me, how can I make these dimensions that have been selected to be changed to another style dimension, and I can also modify the scale factor.

 

Yves

Message 6 of 31
ambrosl
in reply to: Anonymous

Here is what a very quick and basic AutoLISP program might look like to change the selected dimensions from the Standard style to a style named MyStandards:

 

(defun c:ChangeDimStyle ( / sel cnt ent ed)
  (if (setq sel (ssget '((0 . "dimension") (3 . "Standard"))))
    (progn
      (setq cnt 0)
      (while (< cnt (sslength sel))
        (setq ent (ssname sel cnt)
                ed (entget ent)
                ed (subst '(3 . "MyStandards") (assoc 3 ed) ed)
                cnt (1+ cnt))
        (entmod ed)
        (entupd ent)
      )
    )
  )
 (princ)
)

 

You mention scale factor, are you referring to the Dimension Scale of the dimension?



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
Message 7 of 31
Anonymous
in reply to: ambrosl

I want to thank you for helping me so quickly.

 

Yes, I referred to the "Dim Scale Linear"

For you to understand, I will explain what I have to always do manually.

1 - Insert a block.
2 - Change the scale to 50.
3 - Explode.


For this I already create:
(defun c:scviga()
(command "ddinsert" "s" "50" pause)
(setq vge (entlast))
(command "explode" vge)

 

4 - Select all dimensions with dim style "UM_50.000000" and change to "Unidade cm"
5 - Select all dimensions with dim style "UM_25.000000" and change to "Unidade cm", and also change the Dim Scale Linear to "0.5"
6 - Select all dimensions and apply ai_dim_texthome

This is the first routine I'm trying to create.

 

 

 

The second routine I'll need is to just change step 4.
- Select all dimensions with dim style "UM_50.000000" and change to "Unidade cm", and also change the Annotative Scale (example: from 1:50cm to 1:25cm)

Message 8 of 31
Kent1Cooper
in reply to: ambrosl


@ambrosl wrote:

....
  (if (setq sel (ssget '((0 . "dimension") (3 . "Standard"))))
....

 


Don't forget the "_X" if you want it to find all of them:

 

....
  (if (setq sel (ssget "_X" '((0 . "dimension") (3 . "Standard"))))
....

 

If you don't use that, and you're going to select them yourself, you could just use the Properties box to make the changes [whichever meaning of "scale" you intend], without the need for a routine.

Kent Cooper, AIA
Message 9 of 31
ambrosl
in reply to: Kent1Cooper

Yes, I re-read part of the original posting and it mentioned the "selected dimensions" so I removed the "X" but your point is valid.



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
Message 10 of 31
Anonymous
in reply to: Anonymous

I just answered the wrong message, it was supposed to be for ambrosl

 

defun c:ChangeDimStyle ( / sel cnt ent ed)
  (if (setq sel (ssget '((0 . "dimension") (3 . "Standard"))))
    (progn
      (setq cnt 0)
      (while (< cnt (sslength sel))
        (setq ent (ssname sel cnt)
                ed (entget ent)
                ed (subst '(3 . "MyStandards") (assoc 3 ed) ed)
                cnt (1+ cnt))
        (entmod ed)
        (entupd ent)
      )
    )
  )
 (princ)
)
 

 

I did the test did not work, maybe because I did not talk about the annotative.

 

The dim style "UM_50.000000" is not annotative.
The dim style "Unidade cm" is annotative

 

 

The Image 01 is the default when the block is imported. (Dim Style UM_50.000000 / No Annotative)

 


In Image 02 the ChangeDimStyle command was used, the Dim Style changed to "Unidade cm", but the Annotative option was not changed to yes. (When I manually change the dim style from "UM_50.000000" to "Unidade cm", the Annotative option automatically switches to YES

 

 

Image 03, is how the properties of dimensions must be.
Dim Style "Unidade cm"
Annotative: Yes
Annotative Scale: 1:50cm

 

 

img01.JPG

 

img02.JPG

 

img03.JPG

 

 

"You mention scale factor, are you referring to the Dimension Scale of the dimension?"

Yes, I referred to the "Dim Scale Linear"

 

 

 

For you to understand, I will explain what I have to always do manually.

1 - Insert a block.
2 - Change the scale to 50.
3 - Explode.


For this I already create:
(defun c:scviga()
(command "ddinsert" "s" "50" pause)
(setq vge (entlast))
(command "explode" vge)

 

4 - Select all dimensions with dim style "UM_50.000000" and change to "Unidade cm"
5 - Select all dimensions with dim style "UM_25.000000" and change to "Unidade cm", and also change the Dim Scale Linear to "0.5"
6 - Select all dimensions and apply ai_dim_texthome

This is the first routine I'm trying to create.

 

 

Message 11 of 31
ambrosl
in reply to: Anonymous

Yes, a bit more code is needed to mark a dimension as annotative.  I'll update the first sample shortly for that as it requires some Xdata to be attached to the dimension object.



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
Message 12 of 31
Anonymous
in reply to: ambrosl

Thank you Ambrosl.

 

I already understood that it is not something that easy what I need, I noticed that more items were not modified. I will attach a file that has the dimensions of how it should be and how it is getting.

 

 

Yves

Message 13 of 31
ambrosl
in reply to: Anonymous

This version of the code should allow you to switch between two dimension styles and how it switch the Annotative property of the dimension.

 

(defun c:ChangeDimStyle ( / oldDimStyle newDimStyle sel cnt ent)

  (setq oldDimStyle "Standard" newDimStyle "Annotative")
  (if (setq sel (ssget "X" (list (cons 0 "dimension") (cons 3 oldDimStyle))))
    (progn
      (setq cnt 0)
      (while (< cnt (sslength sel))
        (setq ent (ssname sel cnt)
                cnt (1+ cnt))
        (setpropertyvalue ent "DimensionStyle" (tblobjname "dimstyle" newDimStyle))
      )
    )
  )
 (princ)
)



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
Message 14 of 31
ambrosl
in reply to: ambrosl

Here you go... this seems like it should be pretty close to what you are looking for to update your dimensions:

 

(defun c:UpdateDimensions ( / dimStyleMappings dimStyleMap sel cnt ent)
  ;; Set the Dimension Style Mappings (old_style new_style)
  (setq dimStyleMappings (list '("UM_50.000000" "Unidade cm")
                                              '("UM_25.000000" "Unidade 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_25.000000")
            (setpropertyvalue ent "Dimlfac" 0.50)
          )
        )
      )
    )
  )

 

  ;; Move the text of all dimensions Home
  (command "_.dimedit" "_Home" "_all" "")

 (princ)
)



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
Message 15 of 31
Anonymous
in reply to: ambrosl

Thanks again for the help.
As soon as possible I will test and give you a return.

Message 16 of 31
Anonymous
in reply to: ambrosl

Worked perfectly!

To finish the process it is necessary to join the two routines:

 

   Routine 01

(defun c:scviga()
(command "ddinsert" "s" "50" pause)
(setq vge (entlast))
(command "explode" vge)
)

   Routine 02

(defun c:UpdateDimensions ( / dimStyleMappings dimStyleMap sel cnt ent)
  ;; Set the Dimension Style Mappings (old_style new_style)
  (setq dimStyleMappings (list '("UM_50.000000" "Unidade cm")
                                              '("UM_25.000000" "Unidade 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_25.000000")
            (setpropertyvalue ent "Dimlfac" 0.50)
          )
        )
      )
    )
  )
 
  ;; Move the text of all dimensions Home
  (command "_.dimedit" "_Home" "_all" "")

 (princ)
)

Routine 01 must be joined with Routine 02 because routine 02, has to be applied to the inserted block, there are other dimensions in the project that can not be changed.

 

For example, some dimensions that are in the style size "UM_25.000000" will have to be updated to the Style dimension "unidade cm", but keep Dim Scale Linear in "1".

 

After Routine 01 and Routine 02 are in a single routine, the new routine that was created will be used and only the modification will be done to not change the linear dim scale of the inserted block.

 

So I'll work with two routines:

Routine A = Routine 01 + Routine 02
Routine B = Routine 01 + Routine 02 with dim Scale linear 1

Message 17 of 31
ambrosl
in reply to: Anonymous

The two routines merged might look something like the following:

 

(defun c:UpdateDrawing ( / dimStyleMappings dimStyleMap sel cnt ent)
  ; Insert block and explode it
  (command "ddinsert" "s" "50" pause)
  (command "explode" (entlast))

  ;; Set the Dimension Style Mappings (old_style new_style)
  (setq dimStyleMappings (list '("UM_50.000000" "Unidade cm")
                               '("UM_25.000000" "Unidade 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_25.000000")
            (setpropertyvalue ent "Dimlfac" 0.50)
          )
        )
      )
    )
  )
 
  ;; Move the text of all dimensions Home
  (command "_.dimedit" "_Home" "_all" "")

 (princ)
)

 

If you only want the changes to apply to specific objects, you could remove "X" from the statement:

(setq sel (ssget "X" (list (cons 0 "dimension") (cons 3 (nth 0 dimStyleMap)))))

This would allow you to select only the objects that are added to the drawing upon the insertion and explosion of the block, or other objects in the drawing that might need to be converted.

 



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
Message 18 of 31
Anonymous
in reply to: ambrosl

Ambrosl, thank you for your patience, and thank you very much for the routine, it will help me a lot!

 

 

Working perfectly! Smiley Happy

Message 19 of 31
Anonymous
in reply to: Anonymous

Ambrosl,

 

I need help again.

 

The Annotation Scale is always in "1:50 cm".
I made a change in the routine you did to insert blocks with 1:25 scales, so I need to insert in the routine that she change the Annotation Scale to "1:25 cm" and if possible go back to the Annotation Scale that was "1: 50 cm." So I will not need to change manually every time, I found the command (CANNOSCALE) but I could not use it.

 

 

(defun c:UpdateDrawing25 ( / dimStyleMappings dimStyleMap sel cnt ent)
  ; 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")))
 
  ;; 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" "")

 (princ)
)

I tried to insert in the routine the command below, but error message appears.

(command "cannonscale" "1:50cm" "")

 

Ty

Yves

 

Message 20 of 31
ambrosl
in reply to: Anonymous

The CANNOSCALE system variable allows you to set an annotation scale current, this scale is applied to all new annotative annotation objects.  So you could set the scale to 1:25 cm or 1:1 as needed.  If you set the value prior to changing the dimension style in your routine, the dimensions will inherit the current annotation scale.

 

 

(defun c:UpdateDimensions ( / dimStyleMappings dimStyleMap sel cnt ent cannoscale-sav)
  ;; Set the Dimension Style Mappings (old_style new_style)
  (setq dimStyleMappings (list '("UM_50.000000" "Unidade cm")
			       '("UM_25.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

...

  ;; 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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report