Notifications
Clear all

[Closed] Exception when copying

I have a script which calls for a copy of an object. Works fine in most cases but I had a file recently where it threw a system exception on attempt to copy one object. Can’t for the life of me figure out why. Does anyone know under what conditions an attempt to run the line ”copy $ ‘’ throws such an error? I mean if the mesh object exists why shouldn’t it copy?
I don’t care about this particular case – my only concern is that it suspends the script flow and exposes the code which I don’t want happening unexpectedly. I need to allow for exceptions.

9 Replies

If you are only interested in the geometry you can try using the mesh methods.


NewMesh = Mesh mesh:$.mesh
NewMesh.transform = $.transform

Alternatively you can use try/catch.


try
(
	copy $
)
catch
(
	msg = getCurrentException()
	format "Object: % failed to copy.
	%
" $.name msg
)

Hmm even the mesh solution isn’t working. Have to get to the bottom of this. I try to avoid try catch clauses – its a sign of poor programming skills

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

i can give many samples where using of try/catch is a sing of master programming skills.

‘$’ means current selection. in case of multiple selection it might be a situation where cross-dependent nodes can be copied only in specific order. a random copy order can cause failure.
the clone function always resolves this situation.

The problem arises when atttempting to copy mesh with morpher modifier. Clone doesnt solve prob…clone as what? If copy, then system exception, I don’t want an instance or reference clone.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

did you try to clone with expandHierarchy ON?

Well that seemed to work. Is it to do with whether or not dependencies of the children are carried forward or not? If so, why isn’t this on by default? Thnx once again denis.

by default a list of nodes for copy has to be sorted by ‘dependency’. btw it’s a good challenge. does anyone know how to sort nodes by dependency? i do.

Something like:

(
	clearListener()
	
	fn sortByDependency node1 node2 nds: =
	(
		local pos1 = findItem nds node1
		local s = 0
		for i = pos1+1 to nds.count do
		(
			if (findItem (refs.dependentNodes node1 firstOnly:false baseObjectOnly:false) nds[i] !=0) do s = 1
			if (findItem (refs.dependentNodes nds[i] firstOnly:false baseObjectOnly:false) node1 !=0) do s = -1
		)
		s
	)

	sel = getCurrentSelection()
	format "unsorted:
%
" sel
	qSort sel sortByDependency nds:sel
	format "sorted:
%
" sel
)

It could probably be optimized but you get the idea…