Quantcast
Channel: NX Journaling - Journaling / NXOpen API
Viewing all articles
Browse latest Browse all 783

Clone a part

$
0
0

I'm trying to create a simple program to clone a part and append some text to the file name. From what I've been able to put together from the chm files and what I have found on google, this is what I have so far.

I keep getting an error on the line that sets the name rule. The error is "Cannot perform runtime binding on a null reference..."

This is what I have so far:

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF 
Module Clone
    PublicSub Main()Dim ufs As UFSession = UFSession.GetUFSession()Dim theSession As Session = Session.GetSession()Dim workPart As Part = theSession.Parts.Work 
        Dim displayPart As Part = theSession.Parts.DisplayDim lw As ListingWindow = theSession.ListingWindowDim myAsm AsString= displayPart.FullPathDim myClone As NXOpen.UF.UFClone= ufs.Clone 
        lw.Open()
        lw.WriteLine("Assembly to Clone:  "& myAsm)
        myClone.Terminate()
        myClone.Initialise(NXOpen.UF.UFClone.OperationClass.CloneOperation)
        myClone.SetDefNaming(UFClone.NamingTechnique.NamingRule)
        myClone.SetDefDirectory("C:\NewFolder")
        myClone.AddAssembly(myAsm, Nothing) 
        Dim myNameRule As NXOpen.UF.UFClone.NameRuleDef
        myNameRule.type= UFClone.NameRuleType.AppendString
        myNameRule.base_string=""
        myNameRule.new_string="_AppendedText" 
        myClone.SetNameRule(myNameRule, Nothing)'This is the line that gives me the error
        myClone.SetDryrun(False)
        myClone.PerformClone(Nothing)
        myClone.Terminate()EndSubEndModule

I'm not really sure why I am getting the error that I am getting. Any thoughts would be much appreciated! Thanks.


Viewing all articles
Browse latest Browse all 783

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>