-
2
- #1
lsl49
Mechanical
- Sep 26, 2004
- 33
This is a follow-up on a subject that I got to work concerning using a grip program to clean-up text from AutoCAD in UG NX5. ((( Thanks to Amy from GTAC )))
Just goes to show you that you should never give up on something.
ENTITY/ obj, tn
STRING/ new_font(30)
STRING/ obj_text(10,132) $$ 10 is max lines per note
DATA/ max_lines, 10
DATA/ new_font, 'helios_bold_con'
$$ Create a temporary note to save the current global preferences
DRAW/OFF
tn = NOTE/0,0,'TEMP'
DRAW/ON
ASGNFT/new_font, 0 $$ Make sure that font is in the table
n = &FNTNUM(new_font) $$ Get the number where it is in the table
MASK/ 25, 27
INEXTE/ ALL
L100: obj = NEXTE/ IFEND, L300:
$$ Change the character font
DIMPAR/ obj
&CFONT = n
GENDIM/ obj
$$ Edit the text
DO/ L200:, ii, 1, 7
$$ Blank out all previously found text
DO/ L105:, jj, 1, max_lines
obj_text(jj) = &NULSTR
L105: $$ end do jj
$$ Read next text and show what it was before edits
obj_text = &DMTEXT(obj, ii, IFERR, L200
PRINT/'WAS', obj_text
$$ Perform edits as desired
DO/ L150:, jj, 1, max_lines
IF/ obj_text(jj) == &NULSTR, JUMP/L150:
last = jj
$$ Take out every <F1> and <F> and <F2> and <F3>
L110: y = LENF(obj_text(jj))
obj_text(jj) = REPSTR(obj_text(jj), '<F1>', '', 1)
obj_text(jj) = REPSTR(obj_text(jj), '<F>', '', 1)
obj_text(jj) = REPSTR(obj_text(jj), '<F2>', '', 1)
obj_text(jj) = REPSTR(obj_text(jj), '<F3>', '', 1)
IF/ LENF(obj_text(jj)) < y, JUMP/L110:
$$ Strip off all leading and trailing blanks
L120: y = LENF(obj_text(jj))
IFTHEN/ SUBSTR(obj_text(jj), 1, 1) == ' '
obj_text(jj) = SUBSTR(obj_text(jj), 2, y - 1)
JUMP/ L120:
ELSEIF/ SUBSTR(obj_text(jj), y, 1) == ' '
obj_text(jj) = SUBSTR(obj_text(jj), 1, y - 1)
JUMP/ L120:
ENDIF
$$ Take off leading/trailing 2122 which is not part of a no.
IFTHEN/ (y > 4)
x = FNDSTR(obj_text(jj), '2122', 1)
IFTHEN/ (x == 1)
t = ASCII(obj_text(jj), 5)
IF/ (t < 48) OR (t > 57), $
obj_text(jj) = SUBSTR(obj_text(jj), 5, 132)
ELSEIF/ (x == (y - 3))
t = ASCII(obj_text(jj), (y - 4))
IF/ (t < 48) OR (t > 57), $
obj_text(jj) = SUBSTR(obj_text(jj), 1, (y - 4))
ENDIF
IF/ LENF(obj_text(jj)) < y, JUMP/L120:
ENDIF
L150: $$ end DO jj
$$ show replacement text
EDTEXT/obj, obj_text(1..last), ii
PRINT/'NOW', obj_text
L200: $$ end DO ii
JUMP/ L100:
$$ Set the global preference back to original settings
L300: DIMPAR/ tn
DELETE/ tn
HALT
Larry Leonard
Senior Designer
Smith-Nephew Orthopaedics
Just goes to show you that you should never give up on something.
ENTITY/ obj, tn
STRING/ new_font(30)
STRING/ obj_text(10,132) $$ 10 is max lines per note
DATA/ max_lines, 10
DATA/ new_font, 'helios_bold_con'
$$ Create a temporary note to save the current global preferences
DRAW/OFF
tn = NOTE/0,0,'TEMP'
DRAW/ON
ASGNFT/new_font, 0 $$ Make sure that font is in the table
n = &FNTNUM(new_font) $$ Get the number where it is in the table
MASK/ 25, 27
INEXTE/ ALL
L100: obj = NEXTE/ IFEND, L300:
$$ Change the character font
DIMPAR/ obj
&CFONT = n
GENDIM/ obj
$$ Edit the text
DO/ L200:, ii, 1, 7
$$ Blank out all previously found text
DO/ L105:, jj, 1, max_lines
obj_text(jj) = &NULSTR
L105: $$ end do jj
$$ Read next text and show what it was before edits
obj_text = &DMTEXT(obj, ii, IFERR, L200
PRINT/'WAS', obj_text
$$ Perform edits as desired
DO/ L150:, jj, 1, max_lines
IF/ obj_text(jj) == &NULSTR, JUMP/L150:
last = jj
$$ Take out every <F1> and <F> and <F2> and <F3>
L110: y = LENF(obj_text(jj))
obj_text(jj) = REPSTR(obj_text(jj), '<F1>', '', 1)
obj_text(jj) = REPSTR(obj_text(jj), '<F>', '', 1)
obj_text(jj) = REPSTR(obj_text(jj), '<F2>', '', 1)
obj_text(jj) = REPSTR(obj_text(jj), '<F3>', '', 1)
IF/ LENF(obj_text(jj)) < y, JUMP/L110:
$$ Strip off all leading and trailing blanks
L120: y = LENF(obj_text(jj))
IFTHEN/ SUBSTR(obj_text(jj), 1, 1) == ' '
obj_text(jj) = SUBSTR(obj_text(jj), 2, y - 1)
JUMP/ L120:
ELSEIF/ SUBSTR(obj_text(jj), y, 1) == ' '
obj_text(jj) = SUBSTR(obj_text(jj), 1, y - 1)
JUMP/ L120:
ENDIF
$$ Take off leading/trailing 2122 which is not part of a no.
IFTHEN/ (y > 4)
x = FNDSTR(obj_text(jj), '2122', 1)
IFTHEN/ (x == 1)
t = ASCII(obj_text(jj), 5)
IF/ (t < 48) OR (t > 57), $
obj_text(jj) = SUBSTR(obj_text(jj), 5, 132)
ELSEIF/ (x == (y - 3))
t = ASCII(obj_text(jj), (y - 4))
IF/ (t < 48) OR (t > 57), $
obj_text(jj) = SUBSTR(obj_text(jj), 1, (y - 4))
ENDIF
IF/ LENF(obj_text(jj)) < y, JUMP/L120:
ENDIF
L150: $$ end DO jj
$$ show replacement text
EDTEXT/obj, obj_text(1..last), ii
PRINT/'NOW', obj_text
L200: $$ end DO ii
JUMP/ L100:
$$ Set the global preference back to original settings
L300: DIMPAR/ tn
DELETE/ tn
HALT
Larry Leonard
Senior Designer
Smith-Nephew Orthopaedics