×
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

Get Name of component in VB when selecting face

Get Name of component in VB when selecting face

Get Name of component in VB when selecting face

(OP)
I'm still doing research on this one but thought I'd ask before reinventing the wheel.

The idea is the user selects two groups of faces which will be checked against each other and data gathered and dumped in an external file for later perusal.

Is it possible when the user selects the first face to not only grab the face for use, but also the name of the component in the assembly, or the name of the part file if it is a work part, to be used as a file name?

So far I've had no luck finding anything to grab the name of the component, but I'm still looking.

Thanks.

RE: Get Name of component in VB when selecting face

I typically use a selected face to get its body. I then use the body to get the owning component. Finally I use the component to get the part.

Dim tempface As Face = "selected face"
Dim tempbody As Body = tempface.GetBody()
Dim tempcomp As Component = tempbody.OwningComponent
Dim temppart as part = CType(s.Parts.FindObject(tempcomp.Name), Part)

Frank Swinkels

RE: Get Name of component in VB when selecting face

(OP)
We have really long part names on the order of

##.##.##.##_Description_REV_Date

When using the above command I am only getting the last part of the name. Is there a way to increase the string length so the entire name is saved or at least the first part of the name rather than the last part?

Thanks

RE: Get Name of component in VB when selecting face

Does this happen to all the parts or just the ones with really long names? How many characters are in these long part names?

I have some code similar to Frank's:

CODE

Option Strict Off  
Imports System  
Imports NXOpen  
   
Module NXJournal  
Sub Main  
   
Dim theSession As Session = Session.GetSession()  
Dim workPart As Part = theSession.Parts.Work  
Dim displayPart As Part = theSession.Parts.Display  
Dim lw As ListingWindow = theSession.ListingWindow  
Dim mySelectedObject As NXObject  
Dim fileName as String = ""  
   
lw.Open  
   
'Continue prompting for a selection until the user
'  presses Cancel or Back.
Do Until SelectAnObject("Select a face", _  
                       mySelectedObject) = Selection.Response.Cancel  
'   lw.WriteLine("Object Tag: " & mySelectedObject.Tag)
'   lw.WriteLine("Object Type: " & mySelectedObject.GetType.ToString)
'   lw.WriteLine("")
	if mySelectedObject.IsOccurrence Then  
		fileName = mySelectedObject.OwningComponent.Prototype.OwningPart.FullPath  
		lw.writeline(fileName)  
		lw.writeline(io.path.getfilenamewithoutextension(filename))  
	End if  
Loop  
   
lw.Close  
   
End Sub  
   
    Function SelectAnObject(prompt As String, _  
               ByRef selObj As NXObject) As Selection.Response  
   
       Dim theUI As UI = UI.GetUI  
       Dim cursor As Point3d  
       Dim typeArray() As Selection.SelectionType = _  
           {   Selection.SelectionType.Faces}  
   
       Dim resp As Selection.Response = theUI.SelectionManager.SelectObject( _  
               prompt, "Selection", _  
               Selection.SelectionScope.AnyInAssembly, _  
               False, typeArray, selobj, cursor)  
   
       If resp = Selection.Response.ObjectSelected Or _  
               resp = Selection.Response.ObjectSelectedByName Then  
           Return Selection.Response.Ok  
       Else  
           Return Selection.Response.Cancel  
       End If  
   
    End Function  
   
End Module 

www.nxjournaling.com

RE: Get Name of component in VB when selecting face

If you are talking about part file names then the following applies:

"Filename Lengths: Unless otherwise stated, filename lengths are limited
to UF_CFI_MAX_FILE_NAME_LEN characters which includes
any periods or extensions. This includes directory names
and part file names. Pathnames are limited to
UF_CFI_MAX_PATH_NAME_LEN characters. Valid characters
for a filename depend on the operating system."

On my system

#define UF_CFI_MAX_FILE_NAME_LEN 128

Frank Swinkels

RE: Get Name of component in VB when selecting face

(OP)
Is that a command added at the beginning of a vb program or is that a command that is in the environmental variables?

I found a file in the UGOpen folder called uf_cfi.h but I don't see a place to set the variable length.

From what I see when I run my program the length is currently set the 30 characters and I would like to lengthen it if I can.

Thanks.

RE: Get Name of component in VB when selecting face

(OP)
If I can get some help with where to find where I can modify this value.

#define UF_CFI_MAX_FILE_NAME_LEN 128

my code to attempt to change this value in vb is:

UFConstants.UF_CFI_MAX_FILE_NAME_LEN = 128

And receive the error:
Constant cannot be the target of an assignment

I have tried to find an environmental variable but I don't see it there. I have been trying to find a file that contains the information, but I haven't had any luck, though I did find one that references it it does not contain any place to modify it.

Any help is appreciated.

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