Copying without losing links

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
marzof
Posts: 17
Joined: Sun Apr 23, 2017 5:22 pm

Copying without losing links

Post by marzof »

Hi,

I'd like to know if there is a way to duplicate an object without losing the links to that object.
Let me explain:
I have a Cube and a Torus that use some parameter from the cube
Torus points to Box(Cube)
Torus points to Box(Cube)
Screenshot from 2019-03-15 15-39-28.png (20.68 KiB) Viewed 1176 times
I need a new cube but instead of creating a new default cube I want to duplicate the existing one to use the same starting parameters.

No matter what tool I use (I tried Duplicate selection, Copy/Paste, Clone), the creation of the new Cube causes the Torus to point to the new object.
After copying Torus points to Box001(Cube001)
After copying Torus points to Box001(Cube001)
Screenshot from 2019-03-15 15-39-53.png (30.69 KiB) Viewed 1176 times
I don't know if I'm doing something wrong but I think it's very annoying not to be able to reuse parameters from existing objects (alternatively a "copy properties" command would be very useful).

Thanks for the help,
Marco

Code: Select all

OS: Ubuntu 18.04.2 LTS
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16093 (Git)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: 690774c0effe4fd7b8d2b5e2fb2b8c8d145e21ce
Python version: 2.7.15rc1
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
kisolre
Veteran
Posts: 4162
Joined: Wed Nov 21, 2018 1:13 pm

Re: Copying without losing links

Post by kisolre »

Same here:

Code: Select all

OS: Windows 8.1
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16078 (Git)
Build type: Release
Branch: master
Hash: 67df9f3a828fbb0fec29d039792d4baf3d9ee8e0
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Bulgarian/Bulgaria (bg_BG)
The weird thing is that it does the same even with 0.17. 0.17 Shows "Cyclic dependency error"but dependency graph does not show red links.
There is another bug with both versions.
1.New document
2.Create Part sphere
3.Create Part cube
4. Cube.Lenght=Sphere.Radius
CubeSphere.JPG
CubeSphere.JPG (65.32 KiB) Viewed 1165 times
5. Create Part sphere -> Cube is now linked to Sphere001
CubeSphereSphere001.JPG
CubeSphereSphere001.JPG (81.23 KiB) Viewed 1165 times
.
This is definitely a bug.
kisolre
Veteran
Posts: 4162
Joined: Wed Nov 21, 2018 1:13 pm

Re: Copying without losing links

Post by kisolre »

Since there was no responce after 40 views here is bump :)
I made some more experiments. It looks like if there is a expression link to the FIRST created primitive from some later created one when a new primitive like the FIRST one is created it replaces the one that the links point to:
LinkErr3.JPG
LinkErr3.JPG (103.93 KiB) Viewed 1133 times
LinkErr4.JPG
LinkErr4.JPG (187.12 KiB) Viewed 1133 times
.
With two links it would not recompute claiming the errors in the screelshot:

Code: Select all

App::Document::recompute(): cyclic dependency detected
Document::recompute(): Box002 still touched after recompute
I had to manualy reenter the Sphere.Radius expression no fix that.

Should a ticket be created or wait unil 0.18 is finalized?
Those screenshots are with the latest RC:

Code: Select all

OS: Windows 8.1
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16093 (Git)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: 690774c0effe4fd7b8d2b5e2fb2b8c8d145e21ce
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Bulgarian/Bulgaria (bg_BG)
But I tried the same even with 0.17 with same results so this is old...
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Copying without losing links

Post by DeepSOIC »

AFAIR there was a bug, where when copying both Box and Torus, the new torus would link to old Cube even though the cube is copied. If it was fixed, this problem might be a regression of the fix.
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Copying without losing links

Post by DeepSOIC »

maybe this one: issue #0002766
and it's not fixed, and seems related.
marzof
Posts: 17
Joined: Sun Apr 23, 2017 5:22 pm

Re: Copying without losing links

Post by marzof »

Thanks DeepSOIC,

now the reason of this odd behavior it's clear.

Indeed, linking to the internal name of the object is a way to avoid this pointing shift.
Unfortunately using just the objects' internal name in expressions is not a convenient way to operate.

I hope this bug will be fixed soon.
kisolre
Veteran
Posts: 4162
Joined: Wed Nov 21, 2018 1:13 pm

Re: Copying without losing links

Post by kisolre »

Yes that is the one. I wonder why is it marked as "minor"? Is @eivindkvedalen still active in development?

To clarify - creating an object with the same name as one that has something linked through expressions to it triggers "expression/object label" renaming and this mixup happens.

Here I created a Box and renamed it to Body. Then a Cylindder and made Cylinder.Height=Body.Length. Whan a new PD body was created this triggered the bug:
LinkErr5.JPG
LinkErr5.JPG (99.49 KiB) Viewed 1108 times
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: Copying without losing links

Post by GeneFC »

kisolre wrote: Sat Mar 16, 2019 10:23 am I wonder why is it marked as "minor"?
Probably because there is a workaround that may not be the most convenient, but does indeed work correctly.

Gene
marzof
Posts: 17
Joined: Sun Apr 23, 2017 5:22 pm

Re: Copying without losing links

Post by marzof »

It seems that the copyObject() method works correctly and no relinking towards the new objects occurs.
So I quickly wrote a very simple macro to implement a duplicate command that maintains the existing link.
It needs to be tested yet but, in the meanwhile, I think it could be useful to share it here.

Code: Select all

# -*- coding: utf-8 -*-
import FreeCAD, FreeCADGui

selection = FreeCADGui.Selection.getSelection()
new_objects = [App.ActiveDocument.copyObject(obj) for obj in selection]

for no in new_objects:
	FreeCADGui.Selection.addSelection(no)
for ob in selection:
	FreeCADGui.Selection.removeSelection(ob)

App.ActiveDocument.recompute()
Post Reply