Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Jornal Programming Newbie 1

Status
Not open for further replies.

Twullf

Mechanical
Jan 24, 2012
196
First we don't yet have CAST, it is in process of being purchased/installed. However I still have work that needs completing. We are setting UG NX7.5 up for what we hope in the future will be many users, I have been through many posts both here and on the Siemens web site and find I am lacking a lot of basic knowledge for a lot of this.

I am looking at the Sample Title block creation and need help deciphering. I like that it prompts the user for information but I would rather it applies those values to attributes, such as DB_PART_DESC or DB_PART_REV, or even a basic value I can have a note reference to fill in the previously created title block, as well as creating them in a part that hasn't had any set yet.

Rather than do this/ do that, can someone give me a place to get the basics I need. At least until CAST arrives and I can go through their information where I can only pray the information I need can be found.
 
Replies continue below

Recommended for you

I would not waste a lot of time on this if you're planning on moving to NX 8.0 anytime soon.

NX 8.0 introduces a new set of functions for defining and using standard drawing boarders and title blocks which can include a combination of both automatic and system-prompted manual entries which will be placed in their proper place on your drawings.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
UG/NX Museum:
To an Engineer, the glass is twice as big as it needs to be.
 
As the company only JUST got NX7.5 I don't think there will be an upgrade anytime soon.
 
How familiar are you with NX?
From your question, it appears that you are setting up the environment for a new install of NX. If so, you may want to spend some time setting up your preferences/standards and get familiar with what NX offers out of the box then look at what journals/custom code can do for you. The title block program you mention is a cool little example of a journal application, but it is not required to set up title blocks, there is some other useful stuff you can do by pulling attributes from files and filling in text automatically without using journals.
 
I've used NX extensively in many forms and have a really good idea what it can do. That being said I have never had to actually set up the environments. It is true I could just import a part containing the Title block every time, but the company is looking at massive growth and I need to have an environment set up complete with standard drawing requirements as well as a working title block that future employees will be able to quickly use without altering it.

I am also using this program as a stepping stone, as I understand title blocks extremely well and figure by the end of this program I can start the more difficult process of making a program to bring in a spline using data points from a spline, putting points on the spline using preset expressions and putting datum planes on these points in the correct direction. A process needed with nearly every model which can be tedious and time consuming, with up to 30 points per spline.
 
Good to hear.

So for this first journal, you want to check for a specific attribute and retrieve the value, if the attribute does not exist add it with a default value? Do you use the master model method?
 
I don't think I'm using master model. Most of this was set up for me when I've worked before.

What I have so far, activate journal receive a box to manually enter values, these values are set to attributes, then imports a preset border and title block file which retrieves attributes for title block information.

So far so good. I don't like the fact that the date is automatically updating every time the journal is run, which means to update the sheet due to later revision requiring sheet size change will have to be a different macro. Plus adding revision notes later is a bit of a pain.

This is great for new drawings but not so great for revisions. Learning a lot though, but it is taking to long to dummy my way through which is why I am asking for a site for basic UG commands in VB. For instance, a way to take the information from a previously set attribute and set it to a variable in the program in order to reference it, such as in a case where you have the sheet being revised and you want the current value of the attribute to show in the drop box when it comes up for a sheet change or what not.
 
Here is a code snippet from a journal I wrote a while back, it check to see if there is an attribute named JobNumber. If the value is blank or the attribute doesn't exist it will prompt for a value to be assigned.
Code:
	Try
		strJobNumber = workPart.GetStringAttribute("JobNumber")
		[COLOR=green]'the attribute exists, assign the value to a variable[/color]
		strJobNumber = Trim(strJobNumber)
		Do Until isnumeric(strJobNumber)
			strJobNumber = InputBox("Enter Job Number", "Job Number", " ")
			if strJobNumber = "" then
				[COLOR=green]'null string means cancel was pressed, exit journal[/color]
				exit sub
			end if
		Loop
		strJobNumber = Trim(strJobNumber)
		workPart.SetAttribute("JobNumber", strJobNumber)
	Catch ex As Exception
		[COLOR=green]'the attribute does not exist, prompt for a value and assign the title/value to the work part[/color]
		strJobNumber = Trim(strJobNumber)
		Do Until isnumeric(strJobNumber)
			strJobNumber = InputBox("Enter Job Number", "Job Number", " ")
			if strJobNumber = "" then
				[COLOR=green]'null string means cancel was pressed, exit journal[/color]
				exit sub
			end if
		Loop
		strJobNumber = Trim(strJobNumber)
		workPart.SetAttribute("JobNumber", strJobNumber)
	end try

The code isn't optimized, there is some repetition in the try and catch blocks, but I hope it helps you out.
 
Master model is the term for when the model file and drawing file are separate. You add the model as a component to a new file and use that new file as the drawing.

When you start retrieving/adding attributes, you'll need to know if you are adding them to the work part, the component, or the component part. All of them have their uses depending on what you need to accomplish.
 
The program is very useful, and I appreciate it, but I'd rather have some place I can go to answer questions like that rather than having to ask them every time they come up.

As for Master Models, currently we don't use a master, but they are looking into installing Team Center and that may change, but probably not.
 
Alright cowski I need more help, here is the code area:

If openFileDialog1.ShowDialog() = DialogResult.OK Then
Dim session As Session = Session.GetSession()
Dim sr As StreamReader = new StreamReader(openFileDialog1.FileName)
Dim line As String
Dim realScaleNum As Integer
Dim realScaleDen As Integer

realScaleNum = workPart.GetStringAttribute("SH_SHEET_SCALE_NUMERATOR")
realScaleDen = workPart.GetStringAttribute("SH_SHEET_SCALE_DENOMINATOR")

I am trying to bring in the scale data, I have tried, GetRealAttribute, GetIntegerAttribute and I keep getting an error cannot find attribute.

What am I missing?

Is it the workpart portion of the callout? Is there something specific to the sheet?
 
After spending more than an hour on the phone with UG Support we found that the documentation included with each UG license was missing from my install. They were able to provide me with the necessary information to install and point me to where such commands can be found.

From UG I went to Help -> NX Help

This pulled up a web browser with the help documentation, here I went to

automation -> NX Open -> Open for .NET

This asked to download a file, which I did. This opens to an entire textbooks worth of info, but I was able to use the index option to search, use * to make sure it doesn't separate words needing to stay together. *getscale* for instance insures it looks for get scale and not entries with "get" and "scale" in them.

Hope this helps other people
 
Here's some code to return the scale of the sheets in a drawing.
Code:
Option Strict Off
Imports System
Imports NXOpen

Module NXJournal

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

[COLOR=green]'***********************************************************************[/color]

Sub Main

Dim dwgs as Drawings.DrawingSheetCollection
dwgs = workPart.DrawingSheets
Dim sheet As Drawings.DrawingSheet
Dim sheetScaleNumerator as Double
Dim sheetScaleDenominator as Double
Dim i as integer
Dim lw as ListingWindow = theSession.ListingWindow

lw.Open
i = 0
For Each sheet in dwgs
	sheet.GetScale(sheetScaleNumerator, sheetScaleDenominator)
	lw.WriteLine("Sheet Name: " & sheet.name)
	lw.WriteLine("  Scale Numerator: " & sheetScaleNumerator)
	lw.WriteLine("  Scale Denominator: " & sheetScaleDenominator)
	i = i + 1
Next
	
if i = 0 then
	lw.WriteLine("This part has no drawing sheets")
end if

lw.Close

End Sub

End Module
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor