×
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

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

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

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

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

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

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

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

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

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

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

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

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

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

can you please post your atributes name i will arrange acording to that

NX8.5 - NX9 - NX 10 - NX11

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

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

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

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

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

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

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

(OP)
I placed both files, the .vb and the .dlx into a folder. Then I ran the .vb file. I got this error.

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

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

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

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

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

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

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

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

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

i will try to replicate i will give u feedback

NX8.5 - NX9 - NX 10 - NX11

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

(OP)
Thanks

You have gone far and above

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

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

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

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

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

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

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

(OP)
I get the following error.... the top and the bottom line showing are what gets hi-lighted if I select the two errors


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

(OP)
I think I see it. I read the are above that I saw I may not have the DLX file in the right place. Let me see how that does.

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

can u post ur prt so i can test it here and try discover the problem ?

the DLX its like Style Sheet

NX8.5 - NX9 - NX 10 - NX11

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

i think i found your problem its because main its declared as public shared

i will try to make a buton fo your import and call the function thru there, i will send it on monday

NX8.5 - NX9 - NX 10 - NX11

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

(OP)
ok thanks

I do appreciate it all. Hope you have a great weekend.

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

Try the files attached and tell-me the result

(dont forget to put the path to the DLX, and the PRT)

CODE

theDlxFileName = "PATHTODLX:\checkAttributes.dlx" 

CODE

partImporter1.FileName = "PATHTOPRT.prt" 

to import the prt press the "no title" button

NX8.5 - NX9 - NX 10 - NX11

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

(OP)
Hey Vegetagaru

Sorry I didnt reply yesterday. Bosses were pushing for specific things to get done yesterday and I never even had a chance.

So I tried these files. When I played back the VB code file, it brought up the attribute box and I filled that out and hit OK. It disappeared and then that was it. No note ever appeared. For now I have set up separate buttons that work fine. One button to add the attributes and one to bring in the note's .prt file.

I matched the code from the working vb file that brings in the note to the same section in your new vb file. They seem to be exactly the same, so to test it, I coppied the one to the other and tried it. Same results. No note prt file was imported.

Not understanding what it all means enough, I wonder about the location of the .dlx file still. There is a section in the code stating where the dlx file needs to be and I asked our IT person where UG launches from. But I question if it is possible they gave me the wrong location and that is the problem? Is there a specific file that this DLX file should be in the same folder with?

I will be honest with you. If it is not difficult to figure out what is wrong, that would be great to have it working with one button. But if it is something you would have to study and spend much time on, the two button way of things works okay. You have helped me immensely. The attribute code alone is awesome. I do not wish to put you through a hassle just to combine two buttons if the two are working.



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

sorry i was away, family problems, i will try to "see" your reply today

NX8.5 - NX9 - NX 10 - NX11

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

can u attach the prt that contains the tabble ? (the one that you import)

NX8.5 - NX9 - NX 10 - NX11

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

(OP)
Here is my file. You will find it is not just a note but a note turned into a symbol. Boss man wanted this because the people working on this area are very inexperienced and in doing this they cant accidentally change it. I doubt that will make any difference to you, but I figured I would explain it so you dont look at it and wonder why the heck we would make a note a symbol. lol

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

np :) i will try here then i will post feedback asap

i dont mind taking the challenge because i want to be better @ journaling and understand it, so this is perfect :) thank you

NX8.5 - NX9 - NX 10 - NX11

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