Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Get Name of component in VB when selecting face 1

Status
Not open for further replies.

Twullf

Mechanical
Jan 24, 2012
196
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.
 
Replies continue below

Recommended for you

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


www.nxjournaling.com
 
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
 
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.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor