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!

Extract XYZ points from a Journal file. 2

Status
Not open for further replies.

snakemaster

Automotive
Apr 5, 2010
10
I have already spent a great deal of time searching the forum, but I have not found a solution. We use NX 7.5.

I’m creating a tube drawing (a vacuum line w/several bends). I have a point and the start and at the intersections and at the end. I placed the WCS and the start point (labeled “A” and so on). I would like to execute a Journal file to retrieve the XYZ coordinates of the points, and if possible, also retrieve the bend radii (labeled as “A1”, “B1”, etc…). Whereby this information would be the input for a xls table.

Any suggestions would be greatly appreciated!
 
Replies continue below

Recommended for you

Have you looked at the Routing modules available with NX? They already provide this sort of capability, and much more:


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.
 
What distinguishes the points that you want to extract this information from? Is it all the points in the file, all the points on a certain layer(s), all points in a certain group, all points of a certain color, etc? Have you created arcs to represent the bends, and if so how do you distinguish those (layer, color, name, etc)?

What format would you like to see the output? Perhaps upload an example file, and/or post some example data.
 
I Know there is a GRIP program out there someplace that will do what you need.
I used it many years ago (pre V10) when I worked for a company that made automotivr exhausts.
 
Here is some code that might get you started. It looks on a specified layer for all the arc and point objects and returns information (point coordinates, arc radii). It seems to return the objects in created order, which may not be desirable. To determine what info goes with what object, I added some code to look for an attribute named NM (originally it was named NAME, but I didn't want to confuse that with the actual name of the object). By giving each object an attribute, you can also add 'smart notes' to your drawing to label each point and arc (notes that reference the attribute value and change automatically when the attribute value changes).

 
 http://files.engineering.com/getfile.aspx?folder=5e65c962-a696-438b-8500-ce69562a54a6&file=point_arc_info.vb
Is there any way to have this info automatically placed in an .xls file and delimited instead of the information window?
 
There are a few options here.
[ol]
[li]You'll notice that the output to the listing window is separated by commas (aka comma separated values). You can do a File -> Save As... from the listing window then change the file extension from .txt to .csv and open the file directly in Excel.[/li]
[li]You can add code to output a .csv file directly, bypassing the listing window entirely.[/li]
[li]You can use a database connection object to export information to an existing database (Excel can accept such a connection). I have done this with an old database (Lotus Approach) so I know the method works, but I have never used it to connect to Excel, though I'm 95% sure it could be made to work.[/li]
[li]If you have some form of Microsoft Visual Studio installed (even the free 'express' version should work), you can link in the Microsoft office libraries and work with Excel's object model directly (plain vanilla NX journaling is not linked to these libraries).[/li][/ol]
 
If the data was exported directly to a .csv file, could it go directly to an excel file connected to the part currently being worked in. As an example, if I had a spreadsheet connected to the part file that was set up to delimit by commas, could i send these values directly to that spreadsheet?

What I am looking to do is get XYZ coordinate data for points on a specific layer (Usually between 8 and 12 points) to input into a table in the part drawing. Ideally, this would be completely automated, but what I am asking above would be a pretty good stopgap and require a fairly small amount of user-input.
 
Cowski Your program is great! I have one request - make that a couple. 1) Everytime I execute the program I get "<no 'NM' attribute>", I'm having trouble assigning the NM attribute. 2) How do I obtain the distance from PTA 2 PTB & PTB 2 PTC, etc. 3) And is it possible to obtain the included angle of ABC, BCD, etc.

Man if you can answer this I owe you a beer!!
 
snakemaster,
Below is a quick update to the code, it now also reports the distance from the last point (starting at point #2) and the angle the 3 points make (starting at point #3). The name attribute thing is optional, if the 'created by' order is working we can eliminate it. My concern is, if you later edit the pipe by adding more points/arcs in the middle, it will throw off the reported list. I have an idea that I'll explore tomorrow, if it looks feasible I'll post back.

kfraysur,
Sorry, didn't mean to ignore your last post, it just fell off my radar. I'm not sure it is possible to add it directly to the part spreadsheet, I'll have to look into that.

Updated code:
Code:
[COLOR=blue]Option[/color] [COLOR=blue]Strict[/color] [COLOR=blue]Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] System.Collections  
[COLOR=blue]Imports[/color] System.Collections.Generic  
[COLOR=blue]Imports[/color] NXOpen  
[COLOR=blue]Imports[/color] NXOpenUI  
[COLOR=blue]Imports[/color] NXOpen.UF  

[COLOR=blue]Module[/color] NXJournal  

    [COLOR=blue]Dim[/color] ufs [COLOR=blue]As[/color] UFSession [COLOR=blue]=[/color] UFSession.GetUFSession()  

    [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] myMeasure [COLOR=blue]As[/color] Measu  [COLOR=green]reManager = workPart.MeasureManager[/color]

 [COLOR=green]'layer to interrogate[/color]
        [COLOR=blue]Dim[/color] layerNumber [COLOR=blue]As[/color] [COLOR=blue]Integer[/color] [COLOR=blue]=[/color] 1  

        [COLOR=blue]Dim[/color] lw [COLOR=blue]As[/color] ListingWindow [COLOR=blue]=[/color] theSession.ListingWindow  
        [COLOR=blue]Dim[/color] allObjects [COLOR=blue]As[/color] NXObject()  
        [COLOR=blue]Dim[/color] pointXYZ [COLOR=blue]As[/color] Point3d  
        [COLOR=blue]Dim[/color] arcObject [COLOR=blue]As[/color] Arc  
        [COLOR=blue]Dim[/color] myPoints [COLOR=blue]As[/color] [COLOR=blue]New[/color] List(Of Point)  
        [COLOR=blue]Dim[/color] myArcs [COLOR=blue]As[/color] [COLOR=blue]New[/color] List(Of Arc)  
        [COLOR=blue]Dim[/color] pointName [COLOR=blue]As[/color] [COLOR=blue]String[/color]  
        [COLOR=blue]Dim[/color] arcName [COLOR=blue]As[/color] [COLOR=blue]String[/color]  
        [COLOR=blue]Dim[/color] i [COLOR=blue]As[/color] [COLOR=blue]Integer[/color] [COLOR=blue]=[/color] 0  
        [COLOR=blue]Dim[/color] unit1 [COLOR=blue]As[/color] Unit  
        [COLOR=blue]Dim[/color] myDistance [COLOR=blue]As[/color] MeasureDistance  
        [COLOR=blue]Dim[/color] myAngle [COLOR=blue]As[/color] MeasureAngle  

        [COLOR=blue]If[/color] workPart.PartUnits [COLOR=blue]=[/color] BasePart.Units.Inches [COLOR=blue]Then[/color]  
            unit1 [COLOR=blue]=[/color] CType(workPart.UnitCollection.FindObject("Inch"), Unit)  
        [COLOR=blue]Else[/color]  
            unit1 [COLOR=blue]=[/color] CType(workPart.UnitCollection.FindObject("MilliMeter"), Unit)  
        End [COLOR=blue]If[/color]  

        allObjects [COLOR=blue]=[/color] workPart.Layers.GetAllObjectsOnLayer(layerNumber)  
        lw.Open()  
        [COLOR=blue]For[/color] [COLOR=blue]Each[/color] someObject [COLOR=blue]As[/color] NXObject [COLOR=blue]In[/color] allObjects  
            [COLOR=blue]If[/color] [COLOR=blue]TypeOf[/color] someObject [COLOR=blue]Is[/color] NXOpen.Point [COLOR=blue]Then[/color]  
                myPoints.Add(someObject)  
            End [COLOR=blue]If[/color]  
            [COLOR=blue]If[/color] [COLOR=blue]TypeOf[/color] someObject [COLOR=blue]Is[/color] NXOpen.Arc [COLOR=blue]Then[/color]  
                myArcs.Add(someObject)  
            End [COLOR=blue]If[/color]  
        [COLOR=blue]Next[/color]  

 [COLOR=green]'myPoints.Sort[/color]

 [COLOR=green]'info dump, not guaranteed to be in any specific order[/color]
        lw.WriteLine("Point Name,Point X,Point Y,Point Z")  
        [COLOR=blue]For[/color] i [COLOR=blue]=[/color] 0 [COLOR=blue]To[/color] myPoints.Count [COLOR=blue]-[/color] 1  
            pointXYZ [COLOR=blue]=[/color] myPoints(i).Coordinates  
            pointXYZ [COLOR=blue]=[/color] Abs2WCS(pointXYZ)  
 [COLOR=green]'pointName = pointObject.Name[/color]
            [COLOR=blue]Try[/color]  
                pointName [COLOR=blue]=[/color] myPoints(i).GetStringAttribute("NM")  
            [COLOR=blue]Catch[/color]  
 [COLOR=green]'attribute does not exist[/color]
pointName [COLOR=blue]=[/color] "<no  [COLOR=green]'NM' attribute>"[/color]
            End [COLOR=blue]Try[/color]  
            [COLOR=blue]If[/color] i > 1 [COLOR=blue]Then[/color]  
                myDistance [COLOR=blue]=[/color] myMeasure.NewDistance(unit1, myPoints(i), myPoints(i [COLOR=blue]-[/color] 1))  
                myAngle [COLOR=blue]=[/color] myMeasure.NewAngle(unit1, myPoints(i [COLOR=blue]-[/color] 1), myPoints(i [COLOR=blue]-[/color] 2), myPoints(i), [COLOR=blue]True[/color])  
                lw.WriteLine(pointName [COLOR=blue]&[/color] "," [COLOR=blue]&[/color] Math.Round(pointXYZ.X, 3) [COLOR=blue]&[/color] "," [COLOR=blue]&[/color] Math.Round(pointXYZ.Y, 3) [COLOR=blue]&[/color] "," [COLOR=blue]&[/color] Math.Round(pointXYZ.Z, 3) [COLOR=blue]&[/color] "," [COLOR=blue]&[/color] myDistance.Value [COLOR=blue]&[/color] ", " [COLOR=blue]&[/color] myAngle.Value)  
            [COLOR=blue]ElseIf[/color] i > 0 [COLOR=blue]Then[/color]  
                myDistance [COLOR=blue]=[/color] myMeasure.NewDistance(unit1, myPoints(i), myPoints(i [COLOR=blue]-[/color] 1))  
                lw.WriteLine(pointName [COLOR=blue]&[/color] "," [COLOR=blue]&[/color] Math.Round(pointXYZ.X, 3) [COLOR=blue]&[/color] "," [COLOR=blue]&[/color] Math.Round(pointXYZ.Y, 3) [COLOR=blue]&[/color] "," [COLOR=blue]&[/color] Math.Round(pointXYZ.Z, 3) [COLOR=blue]&[/color] "," [COLOR=blue]&[/color] myDistance.Value [COLOR=blue]&[/color] ",")  
            [COLOR=blue]Else[/color]  
                lw.WriteLine(pointName [COLOR=blue]&[/color] "," [COLOR=blue]&[/color] Math.Round(pointXYZ.X, 3) [COLOR=blue]&[/color] "," [COLOR=blue]&[/color] Math.Round(pointXYZ.Y, 3) [COLOR=blue]&[/color] "," [COLOR=blue]&[/color] Math.Round(pointXYZ.Z, 3) [COLOR=blue]&[/color] ",,")  
            End [COLOR=blue]If[/color]  
        [COLOR=blue]Next[/color]  

        lw.WriteLine("")  

        lw.WriteLine("Arc Name, Radius")  
        [COLOR=blue]For[/color] [COLOR=blue]Each[/color] arcObject [COLOR=blue]In[/color] myArcs  
            [COLOR=blue]Try[/color]  
                arcName [COLOR=blue]=[/color] arcObject.GetStringAttribute("NM")  
            [COLOR=blue]Catch[/color]  
 [COLOR=green]'attribute does not exist[/color]
arcName [COLOR=blue]=[/color] "<no  [COLOR=green]'NM' attribute>"[/color]
            End [COLOR=blue]Try[/color]  
            lw.WriteLine(arcName [COLOR=blue]&[/color] "," [COLOR=blue]&[/color] arcObject.Radius)  
        [COLOR=blue]Next[/color]  

        lw.Close()  

    End [COLOR=blue]Sub[/color]  

 [COLOR=green]'**************************************************************************************************[/color]
 [COLOR=green]'function taken from GTAC example[/color]
    [COLOR=blue]Function[/color] Abs2WCS(ByVal inPt [COLOR=blue]As[/color] Point3d) [COLOR=blue]As[/color] Point3d  
        [COLOR=blue]Dim[/color] pt1(2), pt2(2) [COLOR=blue]As[/color] [COLOR=blue]Double[/color]  

        pt1(0) [COLOR=blue]=[/color] inPt.X  
        pt1(1) [COLOR=blue]=[/color] inPt.Y  
        pt1(2) [COLOR=blue]=[/color] inPt.Z  

        ufs.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, pt1, UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt2)  

        Abs2WCS.X [COLOR=blue]=[/color] pt2(0)  
        Abs2WCS.Y [COLOR=blue]=[/color] pt2(1)  
        Abs2WCS.Z [COLOR=blue]=[/color] pt2(2)  

    End [COLOR=blue]Function[/color]  
 [COLOR=green]'**************************************************************************************************[/color]
End [COLOR=blue]Module[/color]


 
Cowski - It works great (let me know where to ship the beer to) and the nxjournaling site helps as well. The problem I still having is I am not able to get it to read the attributes I have assigned to the points (that are part of the drawing) and reading the arcs (which are part of its component). The arcs I can live without but the rest of it is sweet!!
 
Are you using "dumb" points, or point features? In its current form, the journal looks for attributes assigned to point objects; if you are assigning the attributes to the feature, it will not be found. In the edit properties dialog box, you should see 3 tabs: [ul][li]Attributes[/li][li]Feature Attributes[/li][li]General[/li][/ul]if you don't see the Attributes tab, you've picked only the feature.


If you are using point features, it may be better if we change the journal to look for those. This way if you add points later to add a bend in the middle of the pipe, the journal could order the points by the timestamp of the feature and get the order correct (rather than looking for name attributes).

 
I was using point features, dumb points are fine. I have changed the accuracy on the xyz coords to 1 place. How do I change the accuracy of the angle and lengths to 1 place?
 
Since you don't want to drink with me :), I guess I just going to have to make a donation to this site. Just to say thanks, is not enough but thanks anyways!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor