Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Using Grip To Edit Text In NX Drafting 5

Status
Not open for further replies.

lsl49

Mechanical
Sep 26, 2004
33
0
0
US
Due to UG not having True Type Font in Drafting, I currently bring AutoCAD artwork files into UG. The text will appear like this in the UG Annotation Editor: <F1>1000-1234<F>. We assign a new font (helios_bold_con) to the text. In order for the system to recognize the new font, you must edit the text and remove the <F1> & <F>.
Can anyone help me write a grip program to strip this from each piece of text on a drawing? There may be 20-100 occurrences on a drawing that needs editing.


Larry Leonard
Senior Designer

Smith-Nephew Orthopaedics
 
Replies continue below

Recommended for you

Editting text strings with GRIP has always been hard as that function is not supported by GRIP.

Try to mask/25 for text entities, pick it with an ident statement, delete the existing string, edit the string, then create a new note with the revised string in the old location.


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

Ben Loosli
Sr IS Technologist
L-3 Communications
 
You might have to be a little more specific. I'm very limited in my Grip programming knowledge.
Could we come up with a program that would let me pick a text string then delete the first 4 characters and the last 4 characters of that text string then let me pick another without terminating, and maybe Cancel or Esc if I want to terminate the program.

Larry Leonard
Senior Designer

Smith-Nephew Orthopaedics
 
lsl49,

Yes...it's possible, just depends on what you want. You could write a routine that will cycle through all dwg sheets and notes removing the offending chars without user input, or you could have the user pick each note individually. Each has advantages and disadvantages... If your likely to have text strings with these chars that you will want to keep, then I'd go with having the user select them. Otherwise, I'd have it go globally and take the chance of a user error (missing one) out of the equation. You could even set it up to cycle through the notes automatically and give the user a choice on whether or not to edit it or go to the next one...


Regards,
SS
CAD should pay for itself, shouldn't it?
 
This sounds like what I might want. Can you give any help on getting started?

Larry Leonard
Senior Designer

Smith-Nephew Orthopaedics
 
And now for some code:
Code:
ENTITY/L
NUMBER/ORIG(3),LNS,RSP
STRING/NTXT(132),RTXT(132)

L1:
  MASK/25  $$DRAFTING OBJECTS
  IDENT/'INDICATE NOTE',L,RSP
  JUMP/L1:,L1:,,RSP
  $$ SAVE ORIGIN OF NOTE,
  $$ SINCE WE WILL HAVE TO DELETE THE OLD NOTE
  $$ AND PLACE A NEW ONE
  ORIG(1..3)=&ORIGIN(L)

  $$ RETRIEVE TEXT OF OBJECT
  NTXT=&DMTEXT(L)

  $$ REPLACE TEXT IN NOTE
  RTXT=REPSTR(NTXT,'<F1>','',1)
  RTXT=REPSTR(RTXT,'<F>','',1)
  $$ CREATE NEW NOTE
  NOTE/ORIG(1),ORIG(2),RTXT
  $$ DELETE OLD NOTE
  DELETE/L

  HALT

Bear in mind that this is only to get you started, it does not do any error checking and could use improvements. For instance, it only runs once (easily fixed with a loop), it only checks for <F1> and <F> (if there is <F2> or <F3>,etc it will miss them), and it does not check for multi line notes.

All of the above shortcomings are fixable and you will probably want to change it so that it runs with no user intervention to minimize missed notes.
 
YES THIS IS A GOOD START HOWEVER I DO NEED THE LOOP, MULTIPLE LINE CHECK AND WITH NO USER INTERCENTION.

Larry Leonard
Senior Designer

Smith-Nephew Orthopaedics
 
Thought I better try this again.............

Yes this is a very good start however I do need the LOOP, MULTIPLE LINE CHECK and NO USER INTERVENTION if at all possible. This text is placed in one the model for a visual check against the associated AutoCAD file. Since you must be in Drafting to EDIT text, there will be only one drawing per part.

Larry Leonard
Senior Designer

Smith-Nephew Orthopaedics
 
In addition to the following POST, I need the font set to helios_bol_con.

thanks

Larry Leonard
Senior Designer

Smith-Nephew Orthopaedics
 
Instead of grip take a look at the sample applications that ship with NX (C:\Program Files\UGS\NX 3.0\UGOPEN\SampleNXOpenApplications) They have some vb sample applications that will get you started. VB would be easier to understand since it has been around for so long and there are tons of examples on the web. The only disconnect you may have is applying that to the NX/Open object model.

PLM Exchange
 
I'd be glad to refine the program for you, however things are busy at the moment. I did find this in the grip library, it may do the trick. I have not tried it myself so I cannot comment on its use or how well it works.

Code:
$$ PROGRAM: REPLACE_TEXT.GRS
$$
$$ KEYWORDS:
$$
$$ ABSTRACT: A search and replace program that globally replaces
$$           existing note text with new keyed-in text.
$$
$$ RELEASE HISTORY:
$$   19-NOV-86 INITIAL RELEASE, DEWAYNE EVANS
$$   15-JUN-87 REVISION 0, DEWAYNE EVANS
$$   01-AUG-87 SUBMITTED TO LIBRARY
$$
$$ Required Subroutines: (None)
$$
$$ AUTHOR: DEWAYNE EVANS
$$ TITLE:
$$ COMPANY: McDonnell Douglas M & E
$$          Santa Clara, CA
$$          408-727-6990
$$
$$ SYSTEM TYPE:
$$
NUMBER/CCF,CCS,CEC,CES,CTA,CTD,CTJ,CWL,DAD(23),DFV,DLV,EL(3),EP,FS
NUMBER/NEP,NSP,QE,RSP,SDLV,SL,SP,SSDLV,TS
ENTITY/CWCS,ENT(1000),N
STRING/ITXT(132),NT(132),NTXT(132),OT(132)
    DATA/SP,1,EP,0,DFV,2
$$
$$
$$  ENTITY VARIABLES:
$$  ENT = ENTITY, N = NOTE
$$
$$  STRING VARIABLES:
$$  OT = OLD TEXT, NT = NEW TEXT
$$  ITXT = INITIALIZE TEXT, NTXT = NOTE TEXT
$$
$$  NUMBER VARIABLES:
$$  QE = QUANTITY OF ENTITIES, SP = START POSITION, EP = END POSITION
$$  LNT = LENGTH OF NEW TEXT, SL = STRING LENGTH, FS = FIND STRING
$$  NEP = NEW END POSITION, DAD = DRAFTING AID DATA
$$  EL = ENTITY LOCATION, DLV = DO-LOOP VARIABLE, DFV = DEFAULT VALUE
$$  SDLV = SUB-DO-LOOP VARIABLE, SSDLV = SECOND SUB-DO-LOOP VARIABLE
$$  NSP = NEW START POSITION, TS = TERMINATION SWITCH
$$
$$
    CWL=&WLAYER  $$ CURRENT WORK LAYER
    CCF=&CFONT   $$ CURRENT CHAR FONT
    CCS=&CSIZE   $$ CURRENT CHAR SIZE
    CWCS=&WCS    $$ CURRENT WCS
    CEC=&ENTCLR  $$ CURRENT ENTITY COLOR
    CTJ=&TXJUST  $$ CURRENT TEXT JUSTIFICATION
    CES=&ENSITE  $$ CURRENT ENTITY SITE
    CTD=&TDENS   $$ CURRENT TEXT DENSITY
    CTA=&TXANGL  $$ CURRENT TEXT ANGLE
$$
$$
IA05:
    CHOOSE/'READ HELP FILE',$
           'YES',           $
           'NO',            $
    DEFLT,DFV,RSP
    JUMP/IA05:,TERM:,,,HELP10:,IA10:,RSP
$$
$$
IA10:
    TS=1         $$ TERMINATION SWITCH ON
    DFV=1
    TEXT/'ENTER OLD TEXT',OT,RSP
    JUMP/IA05:,TERM:,IA10:,,IA20:,RSP
$$
$$
IA20:
    TS=2         $$ TERMINATION SWITCH OFF
    TEXT/'ENTER NEW TEXT',NT,RSP
    JUMP/IA10:,TERM:,IA20:,,IA30:,RSP
$$
$$
IA30:
    PARAM/'SEARCH POSITIONS',$
          'START',INT,SP,    $
          'END',INT,EP,RSP
    JUMP/IA20:,TERM:,,RSP
    IF/SP-1,EM10:,,
    JUMP/IA40:
$$
$$
EM10:
    MESSG/'START VALUE','MUST BE > 0'
    JUMP/IA30:
$$
$$
IA40:
    MASK/25
    &WCS=CSYS/&WVIEW
    IDENT/'SELECT TEXT',ENT,CNT,QE,RSP
    JUMP/IA30:,TERM:,DL10:,RSP
$$
$$
DL10:            $$ SEARCH AND REPLACE TEXT STRINGS
    MESSG/TEMP,'SEARCHING'
    DO/DLL10:,DLV,1,QE
    IF/&SUBTYP(ENT(DLV))-1,,,DLL10:
    ITXT=&DMTEXT(ENT(DLV))
    SL=LENF(ITXT)
    IF/SP-SL,,DLL10:,DLL10:
    FS=FNDSTR(ITXT,OT,SP)
    IF/FS+0,,DLL10:,
    NTXT=REPSTR(ITXT,OT,NT,FS)
    IF/SP-EP,DL30:,ID10:,DL20:
$$
$$
DL20:            $$ SEARCH ENTIRE TEXT STRING
    DO/DLL20:,SDLV,1,132
    NSP=FS+LENF(NT)
    FS=FNDSTR(NTXT,OT,SP)
    IF/FS+0,,ID10:,
    NTXT=REPSTR(NTXT,OT,NT,FS)
  DLL20:
$$
$$
DL30:            $$ SEARCH UP TO END POSITION
    DO/DLL30:,SSDLV,1,132
    NSP=FS+LENF(NT)
    NEP=LENF(NTXT)-LENF(ITXT)+EP
    FS=FNDSTR(NTXT,OT,NSP)
    IF/FS+0,,ID10:,
    IF/NSP-NEP,,ID10:,ID10:
    NTXT=REPSTR(NTXT,OT,NT,FS)
  DLL30:
$$
$$
ID10:            $$ REPLACE TEXT STRINGS
    &WLAYER=&LAYER(ENT(DLV))
    &ENTCLR=&COLOR(ENT(DLV))
    OBTAIN/ENT(DLV),DAD
    &CSIZE=DAD(1)
    &CFONT=DAD(3)
    &TXJUST=DAD(2)
    &ENSITE=DAD(19)
    &TDENS=DAD(4)
    &TXANGL=DAD(5)
    EL=&ORIGIN(ENT(DLV))
    DELETE/ENT(DLV)
    N=NOTE/EL(1),EL(2),NTXT
  DLL10:
    JUMP/IA10:
$$
$$
HELP10:
    PRINT/'THIS PROGRAM REPLACES EXISTING NOTE TEXT WITH NEW'
    PRINT/'KEYED IN TEXT.'
    PRINT/''
    PRINT/'FIRST, KEY IN THE OLD TEXT (THE TEXT TO BE REPLACED).'
    PRINT/''
    PRINT/'SECOND, KEY IN THE NEW TEXT (REPLACEMENT TEXT).'
    PRINT/''
    PRINT/'THIRD, INDICATE THE START POSITION. THE START'
    PRINT/'POSITION TELLS THE PROGRAM AT WHAT CHARACTER WITHIN'
    PRINT/'THE NOTE TO BEGIN LOOKING FOR THE OLD TEXT. (A START'
    PRINT/'POSITION OF 1 WOULD INDICATE THE BEGINING OF A NOTE).'
    PRINT/''
    PRINT/'FOURTH, INDICATE THE END POSITION. THE END POSITION'
    PRINT/'TELLS THE PROGRAM AT WHAT CHARACTER WITHIN THE NOTE'
    PRINT/'TO STOP SEARCHING FOR THE OLD TEXT. AN END POSITION'
    PRINT/'OF 0 TELLS THE PROGRAM TO SEARCH THE ENTIRE NOTE.'
    PRINT/''
    PRINT/'NOTE: THIS PROGRAM EDITS NOTE ENTITIES ONLY. THE NEW TEXT'
    PRINT/'IS CREATED IN THE CURRENT WORK VIEW. ALSO, IT DOES NOT'
    PRINT/'ACCOMODATE NOTES WITH MULTIPLE LINES OF TEXT.'
    JUMP/IA10:
$$
$$
TERM:
    IF/TS-1,,,IA10:
    &WLAYER=CWL
    &WCS=CWCS
    &ENTCLR=CEC
    &CFONT=CCF
    &CSIZE=CCS
    &TXJUST=CTJ
    &ENSITE=CES
    &TDENS=CTD
    &TXANGL=CTA
    HALT
 
OK, I would greatly appreciate it. I will also be working on it at this end.

PS: The above program works fine but does not do what I want and requires user intervention which we can not have (user error factor).

Here are the factors to consider:
1-Removing <F1> and <F>
2-Remove any brackets containing <K??> and <K>. (example: <K46> )
3-Text string may be multiple lines of text so consider when writing the code.
(example: <F1><U>ABC
DEFG HIJK
1234-5678<F><U>

(Note: This text is underlined which I want to keep so only remove <F1> and <F>.)
4-Origin of text should remain the same as original text.
5-Set text font to helios_bold_con.
6-Cycle through whole drawing without user intervention.

This would be an extra if not to much trouble:

7-Remove all occurrences of digits 2122 from text strings when they follow text characters (example: ABC2122).
(This is a diamond character in AutoCAD but comes in as numbers in UG).

This is all I can think of at this time.

thanks,

Larry Leonard
Senior Designer

Smith-Nephew Orthopaedics
 
Strike through #2-Remove any brackets containing <K??> and <K>. (example: <K46> ).
This actually assign color to the text and this is OK.
One thing I did forget on the list was to keep existing properties like color, character size and origin.
I'm learning as I go here about what is going on from AutoCAD into UG so other things may change.

thanks,


Larry Leonard
Senior Designer

Smith-Nephew Orthopaedics
 
cowski,
Need the new text to be same size, color and origin as old text and be helios_bold_con.

Larry Leonard
Senior Designer

Smith-Nephew Orthopaedics
 
Well... what have you done so far? Perhaps posting the areas of code your having trouble with would help. If, on the otherhand, your expecting Cowski or others to create a routine for you then you'll likely be waiting for a good long time. Your original post asked for help writing the code, implying that you would do the coding and you just needed a nudge or two in the right direction to overcome a problem or two. So far, this thread reads like your expecting Cowski to (out of the goodness of his heart when he's got nothing better to do) design, code, debug, and tweak as desired a program.

If you want someone to take the time and effort to write a code for you, then just ask around and I'm sure some arrangeements can be made. If nobody around here is interested, just hit the web and there's a number of companies out there that will be happy to help you out.

Hope this helps....

Regards,
SS
CAD should pay for itself, shouldn't it?
 
Below you will see what I have so far. It looses the properties of the original text. Someone from told me I should try edit text (EDTEXT) which would retain the properties. I do not know how to incorporate this into this existing program.

$*********************************************************
ENTITY/L, ents(1000)

NUMBER/ORIG(3),LNS,RSP, cntr, spot
STRING/NTXT(132),RTXT(132)

data/ cntr, 0

inexte/ all

MASK/25 $$DRAFTING OBJECTS

L1:
spot = -1
L = nexte/ ifend, Z99:
if/ L == &nulent, jump/ z99:

ORIG(1..3)=&ORIGIN(L)

$$ RETRIEVE TEXT OF OBJECT

$$ COPY SETTINGS $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

E_CLR=&ENTCLR
W_LAY=&WLAYER
C_SIZ=&CSIZE
C_FNT=&CFONT
E_SIT=&ENSITE
T_JUS=&TXJUST

NTXT=&DMTEXT(L)

spot = FNDSTR(NTXT,'<F1>',1)

ifthen/ spot >= 1
cntr = cntr + 1
ents(cntr) = L

$$REPLACE TEXT IN NOTE
RTXT=REPSTR(NTXT,'<F1>','',1)
RTXT=REPSTR(RTXT,'<F>','',1)
$$CREATE NEW NOTE
NOTE/ORIG(1),ORIG(2),RTXT
$$ DELETE OLD NOTE
$$ DELETE/L $$ we can't delete while cycling
endif

jump/ L1:

Z99:

$$ done cycling, so now delete all the old notes
ifthen/ cntr > 0
delete/ ents(1..cntr)
endif

print/ 'CNTR: ', cntr

HALT

$***************************************************

lsl49


 
You need to get the settings from your original string of text, use those values for your current settings, then write your note.


What is happening is the new note is being written at the default settings, not the original settings.

Add a section at the top of your code to capture the default settings.
E_CLR_0=&ENTCLR
W_LAY_0=&WLAYER
C_SIZ_0=&CSIZE
C_FNT_0=&CFONT
E_SIT_0=&ENSITE
T_JUS_0=&TXJUST

Change the section you have where you are saving the settings to save them from the string instead of global settings.
E_CLR=&ENTCLR(L)
W_LAY=&WLAYER(L)
C_SIZ=&CSIZE(L)
C_FNT=&CFONT(L)
E_SIT=&ENSITE(L)
T_JUS=&TXJUST(L)

Now set your system to these values.
&ENTCLR=e_clr
&WLAYER=w_lay
&CSIZE=c_siz
&CFONT=c_fnt
&ENSITE=e_sit
&TXJUST=t_jus

Write your note.

Then reset the values to the system defaults.
&ENTCLR=e_clr_0
&WLAYER=w_lay_0
&CSIZE=c_siz_0
&CFONT=c_fnt_0
&ENSITE=e_sit_0
&TXJUST=t_jus_0

This will reset the system back to the way it was before you executed your program.

ALWAYS cleanup after yourself!



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

Ben Loosli
Sr IS Technologist
L-3 Communications
 
Status
Not open for further replies.
Back
Top