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!

NX9 - VB Code for Attributes (Hope you like a challenge)

Status
Not open for further replies.

Kenja824

Automotive
Nov 5, 2014
949
We have to add this note to a lot of different drawing sheets we work on...
-BUILD EVENT: xxxxxxxxx
-KCDS DESIGNATION: STD CARE UNLESS OTHERWISE NOTED
-PE DISPENSE FILE: xxxxxxx/xxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-BEADS FOLLOW PRODUCT FEATURES UNLESS OTHERWISE NOTED
-PULL OUT STA NO: N/A

(The info in place of the xxxxxx will change from file to file that we work on.)

1) It doesnt make sense to have someone type this out every time. So i figured to make it a part file of its own that a button will import. Makes it simple. Hit a button, the entire note appears.

2) My bosses dont want to make people have to go into each note and type out the different info on each sheet it is needed. So I thought of adding three attributes to the poperties of a file and have the notes connect to the attributes. Like adding <W@PAINT_CODE> in place of the xxxx and creating a poperty attribute for PAINT_CODE. Then it only needs to be typed out once and every time we add the note, it will automatically complete.

I have code that works for importing files. What I dont know how to do is write .vb code that before importing the part file, it will check to see if three specific attributes are available, and if not, it will promp someone to fill out the info and then automatically create the attributes for them. Then it will import the note's part file.

I am pretty sure I am making this confusing. I have a bad habit of that. lol

 
Replies continue below

Recommended for you

try this:

-Put the notes into a blank drawing file and make the relations
-"Import Part" on the desired part
- see if it worked (atributes must be already created or else i thing it will not be "linked")

i do some things like what you are trying to do here, i will try to help you


NX8.5 - NX9 - NX 10 - NX11
 
Thanks vegetagaru

That was already my plan from what it sounds like. I have a folder where I keep part files that are nothing more than a note to be imported. In the above note, I want to place a bit of code (In place of the xxxx) so that it will read the attribute of whatever file I import that into.

My problem is creating the attribute to begin with. I know how to create attributes by going into File/Properties, but my boss does not want the inexperienced people having to do this right now. So I want to add VB code to the Import Note button I will make that will automatically create three attributes and prompt the user for the info for each attribute. Once they fill out the info and hit OK, it will finish creating the attributes then add the note.

Contrary to what I wrote before, my boss doesnt want it to look to see if the attributes are there already or not. He wants it to prompt them for the info each time they add the note in case they need to change the info.
 
i have a code that read the part atributes and let ur change them if not created it creates it (it opens a dialog with the desired atributes to change) if u want i can try to put it for your attributes but u will still need to import the note first (not very pro yet at journaling so)

NX8.5 - NX9 - NX 10 - NX11
 
Yes, if you can place the code here, I will try to use it. If nothing else it will be a starting point. I would appreciate it.
 
can you please post your atributes name i will arrange acording to that

NX8.5 - NX9 - NX 10 - NX11
 
Looking again, I broke one of the attributes in to two, so there are now four.

BUILD_EVENT
PE_DISPENSE_FILE
PE_DISPENSE_FILE_REV
PE_DISPENSE_FILE_NAME
 
Hey vegetagaru

I do appreciate all the work you are putting into helping me out. Unfortunately I am thinking this one may be waaayyyy over my head. lol

The only thing I really know about code is what I have learned here. I have gotten code from someone once and I have learned to manipulate it for similar tasks. When opening this file, I realize just how little I do know. I see there are several areas where I am supposed to add exception handling code. I looked it up and found it is also called exception error code. As to how to write the code for that or what it is for in any of these places in the code is beyond me. Heck, this is the first time I have seen a .DLX file and I have no idea what to do with that.

Either way, it is looking like doing this may be digging me much deeper into code than I am ready for. We should probably have to just teach people to add attributes manually. lol Even the bosses dont always get what they want. lol
 
ok i will try to help you out

the DLX its because im using Block Styler alonside with journaling (i think its correct to say this) im a bit noob on journaling aswell x)

u just need to put the dlx on the same folder as the .vb i already "programed" to your variables so you just need to run it.

first Test if it works: alt+F8 (i think the journal window will appear then browse the .vb file, select it and run it a box should appear (ive attached a print screen)

NX8.5 - NX9 - NX 10 - NX11
 
 http://files.engineering.com/getfile.aspx?folder=b785e0f7-ea20-465b-8f51-274c14a59ee2&file=checkatt.jpg
I placed both files, the .vb and the .dlx into a folder. Then I ran the .vb file. I got this error.

ERROR1_m2axsg.jpg
 
on the .vb file theres a line "
Code:
 Public Sub New()
        Try
            theDlxFileName = "checkAttributes.dlx"

edit and put the path of it ex if the files are on a folder called ATT on C:
Code:
 Public Sub New()
        Try
            theDlxFileName = "c:\ATT\checkAttributes.dlx"

try and tell-me if it worked

NX8.5 - NX9 - NX 10 - NX11
 
That helped. I saw the box appear asking for the four pieces of info.
For a test, I added...
11111
22222
33333
44444
And when I hit OK, it went away but didnt do anything that I can tell. I am guessing you didnt expect it to because you need to direct me on more code changes. :eek:)
 
the vb checks if those atributes are created
if they are created it returns the value on it, if they are not created, it creates the atribute upon ok/apply
and u can change the values

do you want a window to appear after you press the OK/APPLY ?

isnt this what u want ? the user to press a buton and access those atributes ?

NX8.5 - NX9 - NX 10 - NX11
 
I meant that it didnt seem to create any attributes. When I checked Properties, none of those four attributes exist still. It acts like it works. No errors now, but it doesnt seem to actually create any attributes either.
 
i will try to replicate i will give u feedback

NX8.5 - NX9 - NX 10 - NX11
 
ok i found the error(on the .vb file):

Code:
Private bodyPart As Part = Nothing

put it like this:
Code:
 Private bodyPart As Part = theSession.Parts.Display

now it will work Tested on 9 :)

NX8.5 - NX9 - NX 10 - NX11
 
Awesome! Worked perfect. I really appreciate the help. Can I ask one bit more of info from you? I know you have done a lot already.

I have this following code to add a note. Which is actually just importing a part file. How would I go about putting these two together, so that when someone adds the note, it will automatically have them create the attributes as well? ..... If I play with it for a while I think I can figure it out, but if its not hard to do, if you could just tell me where to add your attribute code to it, it would save me a lot of time.

' NX 9.0.2.5
' Journal created by kschonmeier on Wed Nov 04 12:37:44 2015 Eastern Standard Time
'
Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: File->Import->Part...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Import Part")

Dim partImporter1 As PartImporter
partImporter1 = workPart.ImportManager.CreatePartImporter()

partImporter1.FileName = "R:\hms_tools\NX9\Tooling\part\DISPENSE VISUAL AIDS\BUILD NOTE.prt"

partImporter1.Scale = 1.0

partImporter1.CreateNamedGroup = False

partImporter1.ImportViews = False

partImporter1.ImportCamObjects = False

partImporter1.LayerOption = PartImporter.LayerOptionType.Work

partImporter1.DestinationCoordinateSystemSpecification = PartImporter.DestinationCoordinateSystemSpecificationType.Work

Dim element1 As Matrix3x3
element1.Xx = 1.0
element1.Xy = 0.0
element1.Xz = 0.0
element1.Yx = 0.0
element1.Yy = 1.0
element1.Yz = 0.0
element1.Zx = 0.0
element1.Zy = 0.0
element1.Zz = 1.0
Dim nXMatrix1 As NXMatrix
nXMatrix1 = workPart.NXMatrices.Create(element1)

partImporter1.DestinationCoordinateSystem = nXMatrix1

Dim destinationPoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
partImporter1.DestinationPoint = destinationPoint1

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Import Part Commit")

Dim nXObject1 As NXObject
nXObject1 = partImporter1.Commit()

theSession.DeleteUndoMark(markId2, Nothing)

partImporter1.Destroy()

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module
 
insert the code under "Public Shared Sub Main()"

u have something like:
Code:
Public Shared Sub Main()
        Dim thecheckAttributes As checkAttributes = Nothing

put like this:

Code:
Public Shared Sub Main()
        
Dim partImporter1 As PartImporter
partImporter1 = workPart.ImportManager.CreatePartImporter()

partImporter1.FileName = "R:\hms_tools\NX9\Tooling\part\DISPENSE VISUAL AIDS\BUILD NOTE.prt"

partImporter1.Scale = 1.0

partImporter1.CreateNamedGroup = False

partImporter1.ImportViews = False

partImporter1.ImportCamObjects = False

partImporter1.LayerOption = PartImporter.LayerOptionType.Work

partImporter1.DestinationCoordinateSystemSpecification = PartImporter.DestinationCoordinateSystemSpecificationType.Work

Dim element1 As Matrix3x3
element1.Xx = 1.0
element1.Xy = 0.0
element1.Xz = 0.0
element1.Yx = 0.0
element1.Yy = 1.0
element1.Yz = 0.0
element1.Zx = 0.0
element1.Zy = 0.0
element1.Zz = 1.0
Dim nXMatrix1 As NXMatrix
nXMatrix1 = workPart.NXMatrices.Create(element1)

partImporter1.DestinationCoordinateSystem = nXMatrix1

Dim destinationPoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
partImporter1.DestinationPoint = destinationPoint1

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Import Part Commit")

Dim nXObject1 As NXObject
nXObject1 = partImporter1.Commit()

theSession.DeleteUndoMark(markId2, Nothing)

partImporter1.Destroy()

Dim thecheckAttributes As checkAttributes = Nothing


see if it works

NX8.5 - NX9 - NX 10 - NX11
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor