How to change the style of annotations of several blocks with Python?

Hi,

I’m working on a cleaning script.
My goal is to associate every annotation of my drawing to the “Default” style.

This is the part of the script for simple objects (not in block):

def clean_annotations(annotations):
    annotations_nb=len(annotations)
    for i in range(0, annotations_nb):
        rs.DimensionStyle(annotations[i], "Default")

clean_annotations(dim)

It works : dimensions, texts and leaders style become “Default”.

I want to apply the same thing inside blocks :

blocks_names=rs.BlockNames(sort=False)
blocks_count=rs.BlockCount()

for i in range (0, blocks_count):
    objs_block_id=rs.BlockObjects(blocks_names[i])
    objs_block_nb=len(objs_block_id)
    for j in range(0, objs_block_nb):
        rs.DimensionStyle(objs_block_id[j], "Default")

This one doesn’t work and I don’t know why.

When I debug :

print objs_block_id[j]

… display the GUID (it’s good)…

print rs.DimensionStyle(objs_block_id[j])

… display the style (it’s good) but…

rs.DimensionStyle(objs_block_id[j], "Default")

doesn’ modify the style (it’s not good!).

Thank you!

Not behind a pc right now but I think you need to get into the block and pick the dimension objects in that block and change their style

Hi @David_B, you might try if below helps, tested in V6 (Windows):

SetAnnotationDimStyleInBlock.py (1.2 KB)
SetAnnotationDimStyleInBlock.3dm (54.8 KB)

Note that this is the simplest case only, no nested blocks, no referenced blocks from other files etc.

@Alain, could you add something like above to RhinoScriptSyntax maybe ?

_
c.

1 Like

Thank you @Gijs, thank you @clement!

The script works picked block by picked block.
My goal is to apply script to several blocks in the same time.

@clement, I tried to modify the script you shared but I failed.
I actually keep trying.

:S

Hi @David_B, try this with above example 3dm: SetAnnotationDimStyleInAllBlocks.py (1.4 KB)

_
c.

1 Like

Thank you @clement !!! It works!

I just added two lines to create “Default style”.

import rhinoscriptsyntax as rs
rs.AddDimStyle(dimstyle_name="Default")

There are two scripts now :

Cleaning.py “frees” every object except dimensions in blocks.
Warning : every objects in blocks goes to “0” layer

Cleaning.py (983 Bytes)

SetAnnotationDimStyleInAllBlocks.py “frees” dimensions in blocks.

SetAnnotationDimStyleInAllBlocks.py (1.5 KB)

:slight_smile:

1 Like