Cancel
Showing results for 
Search instead for 
Did you mean: 

Error while attempting to clone

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Hello everyone!

I need a little hepl. I'm trying to write a routine to clone a file with the name rule set to replace. But I get the following error message: NXOpen.NXException: Naming application failures occurred during this operation.

The code in question is this:

            string fullPath = dispPart.FullPath;
            string folder = System.IO.Path.GetDirectoryName(fullPath);
            string fileName = System.IO.Path.GetFileName(fullPath);

            theUFSession.Clone.Initialise(UFClone.OperationClass.CloneOperation);

            theUFSession.Clone.AddPart(dispPart.FullPath);
            theUFSession.Clone.SetDefDirectory(folder);
            theUFSession.Clone.SetDefAction(UFClone.Action.Clone);

            theUFSession.Clone.SetDefNaming(UFClone.NamingTechnique.NamingRule);
            UFClone.NameRuleDef nameRule;
            nameRule.type = UFClone.NameRuleType.ReplaceString;
            nameRule.base_string = "Seed";
            nameRule.new_string = "Cloned";

            UFClone.NamingFailures naming_failures;
            theUFSession.Clone.InitNamingFailures(out naming_failures);
            theUFSession.Clone.ApplyDefaults(ref naming_failures);

            theUFSession.Clone.PerformClone(ref naming_failures);
            
            theUFSession.Clone.Terminate();

Apparently the problem is within the section that deals with name rule. But I can't see it. Any ideas?

2 REPLIES

Re: Error while attempting to clone

Valued Contributor
Valued Contributor

Hello Scaffold,

 

The replace naming rule is case sensitive, maybe thats a problem.

 

I suggest to use ".Clone.Iterate()" to get the required parts in the clone process.

try
{
	string path = Strnig.Empty;
	...
	ufs.Clone.Initialise(NXOpen.UF.UFClone.OperationClass.CloneOperation);
	...
    ufs.Clone.StartIteration();

    do
    {
        ufs.Clone.Iterate(out path);
        if (!path.IsEmpty())
        {
			...
			YOUR CODE
			...
		}
    } while (!path.IsEmpty());
	...
}
catch (System.Exception ex)
{
    ...
}
finally
{
    ufs.Clone.Terminate();
}

 

 

Hope this hint helps

Herbert Macho
EBNER Industrieofenbau
AUSTRIA

NX10.0.3.5 (TeamCenter10 and Native)

Betreff: Error while attempting to clone

Experimenter
Experimenter
Dim wp As Part = Application.NXApp.NXSess.Parts.Work
Dim partsToClone As New Generic.Dictionary(Of Part, String)
Dim workDir As IO.DirectoryInfo = New IO.DirectoryInfo("C:\Temp\YourFolder")
Dim newName As String = String.Format("{0}\{1}.{2}", workDir.FullName, "SUCCESS","prt")
Dim cloneOp As UFClone.OperationClass = New UFClone.OperationClass()
Dim fail As New UFClone.NamingFailures()
Dim namingRule As New UFClone.NameRuleDef()
Dim options As UFClone.ExLogOpts = New UFClone.ExLogOpts
Dim cloneLogfile As String = IO.Path.Combine(workDir.FullName, "CloneRecords.txt")

partsToClone.Add(wp, newName)

                    With options
                        .allow_missing_components = False
                        .allow_out_of_sync_bvrs = False
                    End With

                    With NXApp.NXUfSess.Clone
                        .Initialise(cloneOp) 
                        .SetLogfile(cloneLogfile) 
                        .InitNamingFailures(fail) 
                        .SetDefAction(UFClone.Action.Retain)
                        .SetDefAssocFileCopy(False) 
                        .SetDefDirectory(workDir.FullName) 
                        .SetDefNaming(UFClone.NamingTechnique.UserName)
                        .SetDryrun(False) 
                        For Each kvp As KeyValuePair(Of Part, String) In PartsToClone
                            .AddPart(kvp.Key.FullPath)
                            .SetAction(kvp.Key.FullPath, UFClone.Action.Clone, "")
                            .SetNameRule(namingRule, fail)
                            .SetNaming(kvp.Key.Leaf, UFClone.NamingTechnique.UserName, kvp.Value)
                        Next
                        .GenerateReport()
                        .PerformClone(fail)
                    End With
...

 

 

 Hello Scaffold,

 

this code example works fine for my needs. Normally I use something like this to deal with assemblies but it also works for single parts.

 

PS: Used with NX10

 

best regards

Markus