daani-rika / Illustrator-scripts

Scripts for Adobe Illustrator, created or modified by me.
21 stars 2 forks source link

Replace-Objects.jsx #1

Closed jxyun99 closed 2 years ago

jxyun99 commented 3 years ago

Can you add a feature to let Replace-Objects.jsx support use top-level object replacement? Thank you! From Google Translate

daani-rika commented 3 years ago

Can you tell me in detail what script should do? Do you mean top object in group or in the layers or something else?

jxyun99 commented 3 years ago

Now the script uses ClipBoard to replace the object, I want to replace it with the top element in the document

jxyun99 commented 3 years ago

alexander-ladygin’s script can do this, but his script If the replaced element contains a stroke, the replacement will cause it to be out of center

QDhjG.png GTfUU.jpg
daani-rika commented 3 years ago

I made a version of the script that works with the top object. It seems to work correctly with objects with a stroke.

Do you want me to add a checkbox to select the original object or does a separate script fit you?

jxyun99 commented 3 years ago

use Top-object Replace can work, but even if ignore stroke is selected, the object is still not centered after replacement

Q6kaj.png
daani-rika commented 3 years ago

OK, I figured it out — it happens when your target object is a group. If you ungroup it, everything should work all right.

When you group an object, the script cannot detect the stroke and ignores it when calculating a new position. It is possible to make a workaround, but there may be side effects.

jxyun99 commented 3 years ago

no, i don't group it

Replace
jxyun99 commented 3 years ago

Replace.gif

daani-rika commented 3 years ago

No, I mean one object is group itself. Like this: 20-12-03_11-23

jxyun99 commented 3 years ago

It’s very strange, my rectangle is just a stroke, it is no group itself

daani-rika commented 3 years ago

Can you send me your illustrator file? I'll try to find out why the script doesn't work properly.

jxyun99 commented 3 years ago

I have put the file at https://github.com/jxyun99/test ,I don’t see anything special, it’s just that my AI version is Chinese

daani-rika commented 3 years ago

I think, this is a rounding error. Please try this version and tell me if it works.

jxyun99 commented 3 years ago

Now, even if the element is stroke, it can work, but I found other bugs. If the Replacement object is a compound path, it doesn’t work, and if the Replacement object is a group, it doesn’t work。

jxyun99 commented 3 years ago
20201205.gif
daani-rika commented 3 years ago

As always, I fixed something and broke something :) I rewrote half of the script, now it must work with most types of objects.

jxyun99 commented 3 years ago

Thank you. It can work now!

jxyun99 commented 3 years ago

Thank! Is there any way to use this script to replace the object by the name of the linked image? For example, I want use the selected objects to replace the linked images of selected,the the linked images named is “dog.jpg ”

daani-rika commented 3 years ago

I don't quite understand what you want to do, but you need a separate script to replace linked objects. You can try this script, it replaces all selected linked files with a new one.

jxyun99 commented 3 years ago

Today, when I tried to replace it with a mask object,I found If the object is a group and contains a mask, it will not work properly(Position error),I tried to modify it myself, but it didn't work。 I collected a function to get the size of the mask object. I wonder if you can try to fix it,thank you! I have put the file at https://github.com/jxyun99/test Including test files and GIF demo

daani-rika commented 3 years ago

Sorry for delay! I fixed this issue and added the option to scale strokes. I used your function to get the size of the mask. It was very helpful, thank you! New version of script is here