Macro copy part in assembly

I would like advice on how to copy a part in an assembly using a macro than I want to make the part unique and rename it.

I got stuck right at the beginning. I want to select the part and make a copy, but the part cannot be copied…

Can someone help me?

MACRO main

[vxGetEntity,"vyber","/comp/",EntList, EntCnt]
[vxSend,"~CdCopy"]
[vxSend,"~CdPaste"]

ENDMACRO

Why build a macro when the tool already exists?

Cheers, Paul

I want to make a macro that copies a part and creates the same one with position +1. You have to do the sequence select part + copy part + paste part + make unique part + rename part. The newly created part will of course be geometrically different from the one it was based on. For example, you have an aluminum profile and you want a different length, etc.

If you use this 100 times a day then I think the macro makes sense.

What do you mean the tool already exists?

I would really appreciate it if someone could give me an answer instead of me explaining why I actually need it.

Thank you

Open the part or assembly,
RMB of the Object Name in the Tree.
Choose Make All Copy
Add you suffix. (You have to re tick boxes to deselect.)
Pick the Objects, files you wish to rename or both.
Activate the renaming by suffix, by clicking buttons 3 or 4.
Save and Open Option.
Look at the Tab Title to check which item you are editing.
Use Change Component to swap the new names and length part into the assembly.
Constraints that make sense should still work.
image
For individual objects or Files Save As Takes you to an option to to do the same thing.
In 2024 we get this, which should be on the disrt page, less is better right,
image

But in 2025 we have improvements, like this.
image

Cheers, Paul

1 Like

Thank you Paul.

Can someone help me with this macro?

@Petrnejedly
code :point_down::point_down::point_down::point_down::point_down:


MACRO main
[vxGetEntity,"Hello","/comp/,empty_ok,limit=1",G_comp] 
[vxSend,G_comp,"~CdCopy"]
[vxSend,"~CdPaste"]
ENDMACRO

Thank you very much.

I have tried it in ZW3D 2025 and it show me this warning “WARNING: [538] is not a valid selection.” on the line below:

[vxSend,G_comp,"~CdCopy"]

Any idea what to do with it?

thank you

I copy the part, select the last one in the tree, mark it and create it as unique.

Last question, how can I rename the part?

[vxGetEntity,"select part","/comp/,empty_ok,limit=1",G_comp]
[vxEntName,G_comp,Out_name]
[Print,G_comp]
[Print,Out_name]

[vxSend,"~CdCopy",Out_name]
[vxSend,"~CdCopy"]
[vxSend,"~CdPaste"]

[vxEntList, "/comp/", EntityList, EntityCount]
count = 0
count = EntityCount-1

oName = EntityList[count]
[vxEntName,EntityList[count],Out_name]
[Print,Out_name]

[vxSend, "!CdEntSelect", Out_name]
[vxSend,"!CdPartClone"]
 

Below is the macro for renaming, but the last step doesn’t work. Any help?

GLOBAL SelectedPart = ""
[vxGetEntity, "Vyber dil pro prejmenovani", "/comp/,empty_ok,limit=1", SelectedPart, cnt]
SelectedPart = SelectedPart[0]

IF (cnt == 0)
    [Print, "Nebyl vybran zadný díl."]
    RETURN
ENDIF

GLOBAL NewName = ""
[StringInput, "Zadejte novy nazev dilu:","", NewName]
[Print,NewName]
a = 0
a=[StringIsBlank,NewName]

IF (a == -1)
    [Print, "Nebyl zadán žádný název."]
    RETURN
ENDIF

[vxSend, "!CdEntRename", SelectedPart, NewName]

@Petrnejedly
Maybe you need to learn how to debug.
image

Hello,
I know function [DebugOn] a I used it, I I know that is a problem with final line [vxSend, “!CdEntRename”, SelectedPart, NewName]

But I dont know how to solve it.

Any idea?

Hello,
how do I find the correct syntax of a command “CdRename”? it should be old name and new name, but that doesn’t work…

[vxSend,"~CdRename", old_name, new name]

If I tried [vxSend,"~CdRename"] it show me "There is no new object or file name to renema.

I am very frustrated by this.