Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

journal 1

Status
Not open for further replies.

vitulaaak

Automotive
Jul 5, 2007
70
0
0
US
How would you do following:

i have a part, and part drawing as separate file...
how would you do a part name attribute of part drawing ?

i would expect something like making the part work part, saving the name as variable, making the assembly work part, saving the variable as attribute... the thing, that i dont know is, how you make the part the work part and then the assembly
 
Replies continue below

Recommended for you

I think you are using NX-3. From your previous posts we established that answers for later versions may be easier.

This is the thing that we solved earlier after a fashion by writing a little journal file. It works well but I noticed at the time that it passes the value as text without creating an associative attribute.

I can and have mentioned that you can find the part name attribute for the part. Which is to say using a parts list or by creating an attribute with a relationship to the component object, using the annotation editor.
I found that you can declare an attribute such as "title" with the text value, "WIGWAM" as the string value. You do this in the part by the way. Then you add that part to a drawing and create an note using the annotation editor. You need to open the full version and use the relationships tab, and then Object Attribute, finally picking title off the list of attributes in that part. The result with be to place the text "WIGWAM" on the drawing, but in the annotation editor it was coded as <W!6520@TITLE> where the value 6520 is the object number of the component. If you change that string to read <W!6520@$PART_NAME> then the text on the face of the drawing becomes the name of the component part file. The object value varies greatly from one drawing file to the next, but usually though not always, if you decrease that value by 1, then the text will be (often) the name of the drawing file. i.e. <W!6519@$PART_NAME>. This does not always work as planned and on occasions when it fails you're left trying to guess the drawing's object number.

I think the journal method was more reliable.

I only found this by accident when trying to solve your earlier query. I think it is worth doing. UG used to have an assigned variable in earlier versions, pre-NX at least. I understand this has been re-instated above NX-4. I think it is a valid thing to want to do, and should be maintained as such.


Regards

Hudson

 
The command for setting an attribute is as follows:

theSession.Parts.Work.SetAttribute("DB_PART_NAME", Part_Name)

where the first parameter is the name of the attribute and the second is a variable or text string containing the value you want to put into the attribute.

You can ge the name of the work part
from
Dim part_name As String = thesession.Parts.Work.leaf


Mark Benson
Aerodynamic Model Designer
 
to Benson:

this is something, what i know...the problem is, how would you get the part name to the drawing file? I have tried the macro to make the part work part, assign its name to variable and then make the drawing file work again and sign the variable as attribute...the only problem is, that it was a recorded macro, so it works just for this one assembly because of the following sentence:

CType(theSession.Parts.Work.ComponentAssembly.FindObject("HANDLE O-22"), Assemblies.Component)


so unfortunatelly your replies dont really solve what I need.
 
Vitu,
In a journal:
If you get the attribute from the model part and store it as a variable then change work part to the drawing and then set the attribute in that part using the stored variable then you will get the part name of the model stored in an attribute in the drawing part.
Isn't that what you wanted? if not could you explain a little more?

Hudson,

This isn't GM specific. UG's out of the box attribute in TCEng for part name is what I used in the example. I could have called it "keith" but though I'd use a real world example :eek:).


Mark Benson
Aerodynamic Model Designer
 
to benson:

you wrote exactly what i wrote....the only thing is, that i can get working journal for one drawing file, but when i change the part, it doesnt work... its because its recorded macro and hence it is pointing to one exact part...i would need a macro, that goes into first level assembly and make the first level component work...because no matter how many components the part has, it will always be second level or more...i hope it is clear this way
 
Mark,

My Bad!
We don't use TCEng for much other than GM work, so I tend to forget about what I'm seldom forced to deal with as regards where the implementation starts and ends, as opposed to what came out of the box. It's probably off the track we started on, but it occurs to me that while DB_PART_NAME is still only an attribute, if you're working in TCEng then this or one of the other locked attributes may in fact effectively be the only answer. This being the case because the filename on disk is just a hash named record in the database. But in that case if the drawing is a manifestation of the item master then is DB_PART_NAME the same in both part and drawing or not? I'll check in our system later, but I'd be interested as to whether you make sense of these comments and have a similar or different system.

Regards

Hudson
 
The following journal will index through the children of a part and output their part name to a messagebox.


Assuming your drawing only contains 1 component (the model file) You can then use the name of the component and send it to your attribute as per my previous post. Just replace the messagebox line with that and "hey presto" you've got what you want.
If you have more than 1 component and cannot identify the master model by name then your going to have to get a bit clever (good luck on that one).


option strict off
Imports System
Imports NXOpen
Imports NXOpen.Assemblies
imports system.windows.forms

Module NXJournal

Dim thesession As Session = Session.GetSession()

sub Main
Dim thesession As Session = Session.GetSession()

Dim comp As ComponentAssembly = thesession.parts.work.ComponentAssembly
dim c as component = comp.rootcomponent
dim children as component() = c.getchildren
dim child as component
For Each child In children
dim prototype as part
if typeof child.prototype is part then
prototype = CTYPE(child.prototype,part)
messagebox.show(prototype.leaf)

end if
next
end sub

Hope that helps,


Mark Benson
Aerodynamic Model Designer
 
I have done this:

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Assemblies
Module NXJournal

Dim Session As Session = Session.GetSession()

public part_name as string

Sub Walk(c As Component, level As Integer)
Dim children As Component() = c.GetChildren()
Dim child As Component
Dim prototype As Part
dim part_name as string

select case level ' not listing the assembly

case 0
For Each child In children
Walk(child, level + 1)
Next

case 1

prototype = CType(c.Prototype, Part)
session.ListingWindow.WriteLine(New String(" "C, level) & prototype.FullPath & " " & prototype.Leaf & " " & c.Name)
part_name=prototype.leaf
msgbox(part_name)
Session.Parts.Work.SetAttribute("name",part_name)


end select

end sub


Sub Main
session.ListingWindow.Open
Dim part1 As Part



part1 = session.Parts.Work
Dim c As ComponentAssembly = part1.ComponentAssembly

Walk(c.RootComponent, 0)

Session.Parts.Work.SetAttribute("dwg_name",session.Parts.Work.leaf)




End Sub


End Module

and it works quite fine :eek:)
 
the problem is, that without the documentation i cant really do things i would like to...

could you please explain the followings:

dim c as component = comp.rootcomponent

prototype = CTYPE(child.prototype,part)

what exactly is rootcomponent and ctype

thanks
vit
 
Vit,

Not sure why you have so much code?

Didn't my version work (possibly with the addition of an "end module" added to it)?
Yours looks like it's trying to go down through multiple layers of sub assys. Is that really what you want?

first line you ask about is declaring a variable "c" as the root part of the component assembly "comp" this is actuallty the drawing file that contains the model component.

the prototype line is carried over from the UG example.

It's converting the type prototype, if the component is one, to a type part (not sure what the difference is). It may just be error catchment. Anyone feel free to help me out on this one.

I too have problems with the docs and tend to just try and work stuff out from examples I've managed to piece together.


Mark Benson
Aerodynamic Model Designer
 
hi.
i recorded a journal in JAVA.
but when i try to re-run it, selecting it in the jornal manager, the RUN command unavailable. but if i try to run a VB journal it works fine.
i try to set journal language to JAVA in the preferences/userinterface/journal, but it doesn't help
can anyone help me?

----
kukelyk
 

Hi vitulaak,

dim c as component = comp.rootcomponent

prototype = CTYPE(child.prototype,part)

In the above statements, the "comp" is an instance of the assembly and the root occurrence is retrieved in "C".
This is to get the child occurrences underneath it.

Child.prototype return "NXobject" which inturn has to be typecasted to "Part" type to access the desired properties/methods etc..

The "Ctype" is used to avoid the type casting errors and to make the application CLS( common Language specification) compliant in .NET runtime environment.


 
This could be a separate topic really....

However, yes you can add a custom button or menu to NX. It is something that the program provides for is a few ways, and they differ slightly depending on which version you're using. Customizations will usually be supported upwards compatibly perhaps with some minor modifications between versions.

Because I don't know what version you're on, and the explanation is detailed I would urge you to check out the documentation. To find what you're looking for start by searching for "Add custom button", or "Add custom menu", you should find several topics with detailed examples.

Following up on that you will likely find yourself writing menuscript files of one kind or another of which you will find several easy examples to copy if you search through the installation directories for files with similar extensions. If you do so please take care not to overwrite any of those files.

Good Luck

Hudson
 
Status
Not open for further replies.
Back
Top