How to create a clone object with a desired name?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
ChapaikinVA
Posts: 32
Joined: Fri Apr 10, 2015 1:56 am

How to create a clone object with a desired name?

Post by ChapaikinVA »

It's a very simple question from a beginner.

How to create a clone object with a desired name? I mean a name that can be used in form:
FreeCAD.ActiveDocument.<a clone's name>

Give a script example, pls.
Дедушка Мороз, (если ты есть) пусть в новом году FreeCAD не будет таким глюкодромом. Хотя бы для Part / PartDesign! Ну хотя бы чтобы булеаны не глючили! Кроме как на тебя надеяться, видимо, больше не на кого ... :cry:
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: How to create a clone object with a desired name?

Post by mario52 »

hi

Code: Select all

import Draft
sel = FreeCADGui.Selection.getSelection() 	# select object
obj = Draft.clone(sel[0])				# create a clone selected object
obj.Label = "tyty"					# give a Label


#Data
print App.activeDocument().getObjectsByLabel("tyty")[0].Scale					# search by label (Data)

#View
print App.activeDocument().getObjectsByLabel("tyty")[0].ViewObject.Visibility		# search by label (View)
see How to recognize Draft Clone objects?

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
ChapaikinVA
Posts: 32
Joined: Fri Apr 10, 2015 1:56 am

Re: How to create a clone object with a desired name?

Post by ChapaikinVA »

I need to choose a Name not Label for a clone. It is easy when create an object by addObject method. But I don't know how to choose name (not label) for a clone.
Дедушка Мороз, (если ты есть) пусть в новом году FreeCAD не будет таким глюкодромом. Хотя бы для Part / PartDesign! Ну хотя бы чтобы булеаны не глючили! Кроме как на тебя надеяться, видимо, больше не на кого ... :cry:
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: How to create a clone object with a desired name?

Post by yorik »

There is no way to do that at once, but you can simply mimmick the code inside Draft.clone (src/Mod/Draft/Draft.py line 2827), and first create the object yourself then apply _Clone to it.
Post Reply