×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

C++ or Python Journal

C++ or Python Journal

C++ or Python Journal

(OP)
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

RE: C++ or Python Journal

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?

www.nxjournaling.com

RE: C++ or Python Journal

(OP)
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
www.team-eng.com

RE: C++ or Python Journal

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

RE: C++ or Python Journal

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

RE: C++ or Python Journal

(OP)
Legend Cowski! Thanks a million :)

Best regards

Simon

NX7.5 NX8.5 NX9 NX10
NX Consultant
www.team-eng.com

RE: C++ or Python Journal

Cowski,
of curiosity,: Why Python ?

Regards,
Tomas

RE: C++ or Python Journal

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

RE: C++ or Python Journal

ah.
the title.
that little detail...

smile

RE: C++ or Python Journal

python only on NX11 or prior right?

NX8.5 - NX9 - NX 10 - NX11

RE: C++ or Python Journal

Python is supported on NX 10 or later. The journal above was tested on NX 10.

www.nxjournaling.com

RE: C++ or Python Journal

what u think of it cowski ? is a way to go over VB (working with NX)?

NX8.5 - NX9 - NX 10 - NX11

RE: C++ or Python Journal

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

RE: C++ or Python Journal

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

RE: C++ or Python Journal

python is easier and more powerful then vba and much easier then c++, it's a very good choice.

RE: C++ or Python Journal

the problem is that python is only for nx10+

anyway thanks :)

NX8.5 - NX9 - NX 10 - NX11

RE: C++ or Python Journal

Quote (loki3000)

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources

White Paper: Industrial Control Basics: Contactors
A contactor is an electrical device used for switching an electrical circuit on or off. Considered to be a special type of relay, contactors are used in applications with higher current carrying capacity, while relays are used for lower current applications. Download Now
Research Report: State of IoT Adoption in Product Development 2019
This research report, based on a survey of 234 product development professionals, examines the current state of Internet of Things (IoT) adoption by product design teams, its perceived importance, and what features and capabilities teams consider important when making decision about adding IoT functionality to their products. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close