Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ or Python Journal 1

Status
Not open for further replies.

SiW979

Mechanical
Nov 16, 2007
804
Hi

I want to be able to create a journal that creates a Surface through points by importing an external .dat file. I can do it via a macro, but wondered if anyone would be able to help with a journal.

Insert Surface through points
Select points file (.dat) from a specified folder (my documents)
OK

Surface created.

Many thanks in advance, I have attached a points file as an example.

Best regards

Simon

NX7.5 NX8.5 NX9 NX10
NX Consultant
www.team-eng.com
 
 http://files.engineering.com/getfile.aspx?folder=04895919-34a7-490b-9781-5408bc4e3e85&file=input_data.dat
Replies continue below

Recommended for you

Do you always use the same options in the through points dialog and if so, what are they?
Also, I see 4 versions of NX listed in your signature. Which version will this journal be for?

download.aspx


www.nxjournaling.com
 
Hi Cowski

Yes, the dialog box looks the same always, we are using NX10. We are actually trying to run the journal from outside NX if that makes sense, without using the NX GUI.

Best regards

Simon

NX7.5 NX8.5 NX9 NX10
NX Consultant
 
Does the resulting surface become usable when you do this ?
I would be quite careful with this, there is no tolerance on this feature, I have seen examples where the resulting surface was , "useless".
( it had 1200 x 1200 patches and was as smooth as sandpaper...)

I.e if you feed it with many points, the result becomes heavy . and wavy.

Regards,
Tomas
 
Below is some Python code that, when run as a journal, will import info from a text file and create the surface through points. The input file path is hard coded; you will at least need to modify the code to point to your input file. It could be improved upon by adding some logic to pass in or choose the file location.

Code:
import NXOpen
import NXOpen.UF

theSession = NXOpen.Session.GetSession()
theLw = theSession.ListingWindow
theUfSession = NXOpen.UF.UFSession.GetUFSession()

def isBlank (myString):
    if myString and myString.strip():
        #myString is not None AND myString is not empty or blank
        return False
    #myString is None OR myString is empty or blank
    return True
    
    
def main(): 

    workPart = theSession.Parts.Work
    displayPart = theSession.Parts.Display
    
    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "surface thru points")
    theLw.Open()
    
    #input file with row and point data
    fname = "C:\\temp\\input_data.dat"
    with open(fname) as f:
        content = f.readlines()
    
    # initialize list to hold row information
    rowInfo = []
    
    for x in content:
        #theLw.WriteLine(x)
        
        # skip any blank lines
        if isBlank(x):
            continue
        
        if x.strip().upper() == "ROW":
            # append an empty list to use for the next row point data
            rowInfo.append([])
            # nothing else to do for a ROW entry
            continue
        
        # get last entry in rowInfo list (the list of point information for the row)
        ptInfo = rowInfo[-1]
        
        # point data is three float values separated by spaces
        try:
            pt = x.strip().split()
            for item in pt:
                ptInfo.append(float(item))
        except:
            # skip this entry, move to next
            continue
        
    # debug
    '''
    for x in rowInfo:
        str1 = ''.join(str(e) for e in x)
        theLw.WriteLine(str1)
    '''
    
    bSurfInfo = []
    for x in rowInfo:
        temp = NXOpen.UF.Modl.BsurfRowInfo()
        temp.NumPoints = len(x)//3
        temp.Points = x
        temp.Weight = [1.0 for n in range(len(x)//3)]
        bSurfInfo.append(temp)
        #theLw.WriteLine("number of points: " + str(len(x)))
    
    #theLw.WriteLine("bSurfInfo length: " + str(len(bSurfInfo)))
    surfTag = NXOpen.UF.Tag()
    surfTag = theUfSession.ModlGeneral.CreateBsurfThruPts(1,0,0,3,3,len(bSurfInfo),bSurfInfo)
    
    theLw.Close()
    
    
if __name__ == '__main__':
    main()

www.nxjournaling.com
 
Cowski,
of curiosity,: Why Python ?

Regards,
Tomas
 
The title of the thread specifically asked for C++ or Python. I don't have a C++ compiler currently installed, so I went the Python route.

www.nxjournaling.com
 
ah.
the title.
that little detail...

:)
 
python only on NX11 or prior right?

NX8.5 - NX9 - NX 10 - NX11
 
what u think of it cowski ? is a way to go over VB (working with NX)?

NX8.5 - NX9 - NX 10 - NX11
 
It is just another option; as a programming language, I wouldn't say it is either better or worse than VB. Python would be the obvious choice if you are already familiar with the language. It is also a good choice if you are working with NX on Linux, as .net is not yet usable with Linux on NX. If you are working on Windows and looking to learn a language, either is good as both are widely used (you can easily find documentation, tutorials, example code, and forum support online).

www.nxjournaling.com
 
im working with VB atm but im still very fresh on journaling, during the next months i will try to go deeper on it. i will stick with VB atm, and then maybe move to python coz at work we didnt make the upgrade yet we are still on the 9 afraid with the changes on 11 x) so because 9 dont use python i will go for VB.

NX8.5 - NX9 - NX 10 - NX11
 
python is easier and more powerful then vba and much easier then c++, it's a very good choice.
 
the problem is that python is only for nx10+

anyway thanks :)

NX8.5 - NX9 - NX 10 - NX11
 
loki3000 said:
python is easier and more powerful then vba and much easier then c++, it's a very good choice.

For the record, NX uses VB.net, not VBA. Either one has the power to get the job done; to say that one is more powerful than the other is largely a matter of personal preference.

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor