Participant
April 6, 2023
Question
Change the FillColor of a group
- April 6, 2023
- 1 reply
- 411 views
from win32com.client import GetActiveObject, Dispatch, constants
from pathlib import Path
app = GetActiveObject("Illustrator.Application")
docRef = app.ActiveDocument
fpath = Path('generates_test_modified_svg_file.svg').absolute()
current_item = docRef.GroupItems.Item("originalGroup0")
placedSVG = current_item.GroupItems.CreateFromFile(fpath)
placedSVG.Resize(90, 90)
#
placeholder = current_item.PageItems.Item("svgPlaceholder")
placeholder_bounds = placeholder.GeometricBounds
#
# # Set the position of the new object to match the placeholder
placedSVG.Left = placeholder_bounds[0]
placedSVG.Top = placeholder_bounds[1]
#
placedSVG.Name = "barcodeGroup"
current_item = docRef.GroupItems.Item("barcodeGroup")
internal_group = current_item.GroupItems.Item("barcode group")
pantoneSwatchName = "PANTONE Black"
pantoneSwatch = docRef.Swatches.Item(pantoneSwatchName)
rect = current_item.PageItems.Item("barcodeGroup")
original_barcode_group = rect.PageItems.Item("barcode group")
# Loop through all the items in the group
for item in original_barcode_group.PageItems:
if item.PageItemType == 5:
item.FillColor = pantoneSwatch.Color
else:
print(item.typename)
new_outlined_item = item.CreateOutline()
print("------------"+item.typename)
for compoundPath in new_outlined_item.PageItems:
for i in range(compoundPath.PathItems.Count):
compoundPath.PathItems[i].FillColor = pantoneSwatch.ColorI have an SVG file in which I want to change the colour of all its objects into Pantone colour and I have a simple placeholder in the document which I am replacing with the SVG one. After placing the SVG in the document it creates a group.
Now I want to change the FillColor of that group but "rect.FillColor = pantoneSwatch.Color" is not working that's why I try to loop through all of the objects in the group and change its colour but it's taking a long time almost 2 min to change the colour of the group. And there are only 18 objects in the layer. Is there any way to optimize this or set the colour of the group at once? Or while I am placing the SVG maybe change the colour of it at that time. I am kinda stuck here.
My Group structure:
originalGroup0
-> barcodeGroup
-> barcode group
-> All objects
