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!

GRIP program to read points coordinates and output to file

Status
Not open for further replies.

AndersSande

Industrial
Jul 1, 2005
18
Hi,
Anyone who could help me with some source code for compiling a program to be used in NX3 or NX4?

The function should be like this:
The 3D-model part file contains some points, witch is visible on the drawing.
These points is manually selected, one by one, from the drawing.
The grip program should output the X, Y and Z coordinates to a text file.
Numbering of the points ( P1, P2.. ) shall be the same as the selecting order of the points.

Formatting of the file should be like this:
-------------------
P1
X <coords>
Y <coords>
Z <coords>

P2
X <coords>
Y <coords>
Z <coords>

P3
X <coords>
Y <coords>
Z <coords>

P4
X <coords>
.....and continuing to the last point.

-------------------

 
Replies continue below

Recommended for you

You want to select the points from the model view, not the drawing view. Drawing views are translated and scaled and may not give you the proper coordinates.

"Wildfires are dangerous, hard to control, and economically catastrophic."

Ben Loosli
Sr IS Technologist
L-3 Communications
 
Yes, the points is selected in a model view. This is done in the GM Toolkit. But in this toolkit the point coordiantes is output to a table on the drawing. Or, it isn't really a table, it is notes in a rectangular pattern with lines between. I would like to do the same coordiantes readout, but save the walues to a file saved on a selected location.
 
Try this one!

$$
$$
$$
$$ SUBPROGRAM : SortProximityPoints.grs
$$
$$ RELEASE HISTORY :
$$ 03-Jan-07 : Initial submission to library.
$$
$$
$$ AUTHOR : Zarko Smiljanic
$$ TITLE : Structural Designer
$$ COMPANY : Nika Inc
$$ 46 Lothian Ave
$$ Toronto, Ontario M8Z 4K1
$$ Tel : 416.231.8373
$$
$$
$$ SUBROUTINE :
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
$$ Variable Definition
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

NUMBER/ X(3)
NUMBER/ Y(3)
NUMBER/ V(3)
ENTITY/ SLIN
ENTITY/ SPTN
ENTITY/ PTS(1000)
ENTITY/ TL(1000)

STRING/ IMAG(2,80)
STRING/ NAME(132)
STRING/ GDE(132)

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
$$ Data Definition
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

DATA/IMAG,' No , X , Y , Z ',$
'#@@@,#@@@.@@@@,#@@@.@@@@,#@@@.@@@@'
DATA/ GDE,'C:\Program Files\Microsoft Office\Office11\EXCEL.exe'

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
$$ Select Points
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

LOOPA: MASK/2
IDENT/'Select Points',PTS,CNT,IPTS,RESP

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
$$ Select Start Point
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

IFTHEN/RESP>2
IDENT/'Select Start Point',SPTN,RESP
IF/RESP==1,JUMP/LOOPA:
IFTHEN/RESP>2 AND SPTN<>&NULENT
DO/LOOPB:,I,1,IPTS
RAST=DISTF(PTS(I),SPTN)
IFTHEN/RAST==0
SPTN=PTS(1)
PTS(1)=PTS(I)
PTS(I)=SPTN
JUMP/ LOOPC:
ENDIF
LOOPB:
PTS(I+1)=PTS(1)
PTS(1)=SPTN
IPTS=IPTS+1

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
$$ Sort Points By Proximity
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

LOOPC: DO/LOOPD:,I,1,IPTS
&NAME(PTS(I))=ISTR(I)
LOOPD:

DO/LOOPE:,I,1,IPTS-2
C_DIST=DISTF(PTS(I),PTS(I+1))
K=I+1
DO/LOOPF:,J,I+2,IPTS
T_DIST=DISTF(PTS(I),PTS(J) )
IFTHEN/T_DIST<C_DIST
C_DIST=T_DIST
K=J
ENDIF
LOOPF:
SPTN=PTS(I+1)
PTS(I+1)=PTS(K)
PTS(K)=SPTN
LOOPE:



$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
$$ Data Output
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

RPAINT
CREATE/TXT,1
WRITE/1,IMAG(1)
DO/LOOPG:,I,1,IPTS
X=&POINT(PTS(I))
WRITE/1,USING,IMAG(2),I,X
CRTWRT/ISTR(I),&POINT(PTS(I))
IF/I<IPTS,TL(I)=LINE/PTS(I),PTS(I+1)
LOOPG:
MESSG/ 'Press Any Key ..'

DO/LOOPH:,I,1,IPTS
&NAME(PTS(I))=ISTR(I)
LOOPH:
DELETE/TL(1..IPTS-1)
NAME=TIME
NAME=REPSTR(NAME,':','_',1)
NAME='C:\TEMP\Vector'+NAME+'.csv'
FETCH/TXT,3,NAME,IFERR,ENDE:
FDEL/NAME,IFERR,ENDE:
ENDE: FILE/TXT,1,NAME
FTERM/TXT,1
XSPAWN/CONCUR,GDE,NAME
RPAINT
JUMP/LOOPA:
ENDIF
ENDIF

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
$$ Program End
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

END: HALT
 
Correct program

$$
$$ PROGRAM: PointCoordinates.grs
$$
$$ RELEASE HISTORY :
$$ 12-Jan-01 : Initial submission to library.
$$
$$ AUTHOR : Zarko Smiljanic
$$ TITLE : Structural Designer
$$ COMPANY : McDonnell Douglas CANADA
$$ 6972 Airport Road
$$ Mississauga, Ontario, L5P 1B6
$$ Toronto, Ontario M8Z 4K1
$$ Tel : 416.231.8373
$$
$$
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
$$ Variable Definition
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

NUMBER/ X(3)
NUMBER/ Y(3)
NUMBER/ Z(3)
NUMBER/ U(3)
NUMBER/ V(3)
NUMBER/ W(3)
NUMBER/ ILEN(3)
NUMBER/ IDECPL

ENTITY/ ENTY
ENTITY/ KSYS
ENTITY/ ENT
ENTITY/ LABELA(500)

STRING/ WVIEW(30)
STRING/ STATION(4,20)
STRING/ NOTA(10,30)

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
$$ Data Definition
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

DATA/STATION,'X #@@@.@@@@@@@@@@@@',$
'Y #@@@.@@@@@@@@@@@@',$
'Z #@@@.@@@@@@@@@@@@',$
'#@@@@@@@@@@@@@@@@@@@'


$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
$$ Active Part Check
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

IFTHEN/&ACTPRT==1
MESSG/'You don''t have an active part !'
HALT
ENDIF


$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
$$ Read/Setup System Variables
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

IWLAYER = &WLAYER
IFONT = &FONT
ILWIDTH = &LWIDTH
ITLWID = &TLWID
ITEXTOR = &TEXTOR
ITDENS = &TDENS
ITXJUST = &TXJUST
IVTXJST = &VTXJST
IENSITE = &ENSITE
ICFONT = &CFONT
ICSIZE = &CSIZE
IDSIZE = &IDSIZE

&WLAYER = 201
&FONT = &SOLID
&LWIDTH = &NORMAL
&TLWID = &NORMAL
&TEXTOR = &TXBANG
&TDENS = &NORMAL
&TXJUST = &LEFT
&VTXJST = &TOP
&ENSITE = &MIDC
&CFONT = 1
&CSIZE = .1250
&IDSIZE = .500
ILABELA = 0
IDECPL = 3

&FILARW = 1
&ARIANG=20.
&ASIZE=.2
&TLWID=&THIN
&TEXTOR=&TXBANG
&ENSITE=&MIDC
&TDENS=&THIN
&VTXJST=&TOP
IRED=0


$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
$$ Create Point Coordinate Label
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

LOOPA: &VWCURS = &ANY
&WCS = &ABS
&DECPL = IDECPL
MASK/2,3
IDENT/'Select Entity',ENT,CURSOR,X,MEMBER,OFF,RESP
JUMP/END:,END:,,RESP
&VWCURS=&ANY
WVIEW=&VWSEL
IFTHEN/ENT<>&NULENT
ITYPE=&TYPE(ENT)
X=MAP/X,FROM,WVIEW,TO,&CURDRW
IFTHEN/ITYPE==2
OBTAIN/ENT,Z
ELSE
OBTAIN/ENT,Z,U
ENDIF

&VWCURS=&WORK
POS/'Locate Label Origin',Y,RESP
JUMP/LOOPA:,LOOPA:,RESP

CREATE/TXT,8
DO/LOOPD:,N,1,3
NOTA(N)=SUBSTR(STATION(N),1,9+IDECPL)
WRITE/8,USING,NOTA(N),Z(N)
LOOPD:
RESET/8
READ/8,USING,STATION(4),NOTA(1)
READ/8,USING,STATION(4),NOTA(2)
READ/8,USING,STATION(4),NOTA(3)
FTERM/TXT,8

ILABELA=ILABELA+1
IFTHEN/Y(1)>X(1)
LABELA(ILABELA)=LABEL/LEFT,Y(1),Y(2),$
ENT,VIEW,WVIEW,NOTA(1..3)
ELSE
LABELA(ILABELA)=LABEL/RIGHT,Y(1),Y(2),$
ENT,VIEW,WVIEW,NOTA(1..3)
ENDIF

IRED=IRED+1
PRINT/'P'+ISTR(IRED)
PRINT/NOTA(1)
PRINT/NOTA(2)
PRINT/NOTA(3)
ENDIF
JUMP/LOOPA:


$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$
$$ Reinstate System Variables
$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

END: &WLAYER = IWLAYER
&FONT = IFONT
&LWIDTH = ILWIDTH
&TLWID = ITLWID
&TEXTOR = ITEXTOR
&TDENS = ITDENS
&TXJUST = ITXJUST
&VTXJST = IVTXJST
&ENSITE = IENSITE
&CFONT = ICFONT
&CSIZE = ICSIZE
&IDSIZE = IDSIZE
HALT

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor