Hi

it is possible to do that, no problem, but as Geordie points out it can be 
quit tricky

attatched is an exampel illustrating 2 ways to do it, when I use tcl to set 
an attribute I will normaly use version b - in most cases version a is 
working but if you have some off the special cases like \$() etc. in the 
return value it can give you some problems.

If you plan to use tcl alsoe study the other FME_... function in tcl, they 
give you a lot of power manipulating not only attributes but alsoe 
manipulating the geometry

The null2null.fme mapping file is extremy useful when writing tcl - or 
testing othrer functions - i use it a lot

To get the value off a fme global variable in tcl you can use this command

set myGlobal [ FME_Execute GlobalVariable varName ]

to put am MACRO into a global a tcl global varibale put this in your mapping 
file

Tcl2 set globalFromMacro $(myMacro)

NB are you sure you have to use tcl for this my first choise would be to use 
the @Lookup() or @Realte()  functions to get the value from a table, with 
the @Realte() you can set all mapinfo style attributes in one function call, 
and best off all if we get a new feature all we have to do is update the 
table we dont have to cahnge the code/mapping file

have fun
Peter Laulund


>From: Geordie Hobart <[EMAIL PROTECTED]>
>Reply-To: [email protected]
>To: [email protected]
>Subject: Re: [fme] Re: Output from TCL in a Function
>Date: Tue, 09 May 2006 16:18:11 -0700
>
>Chris.
>That should work as Mark has recommended.
>TCL can be very useful but also frustrating ... the TCL error messages
>can be very misleading  and sometimes have no relevance to the actual
>error:.
>
>
>A couple of gotcha's to watch out for when programming in TCL
>
>1) What spaces are your friend. Because the language is interpreted you
>need white spaces to parse your code correctly.
>I have burned many times by this especially with function declarations
>
>Do not do this ->    proc myproc{}{
>
>It should be ->       proc myproc { } {  #NOTE THE EXTRA SPACES
>
>Rule of thumb when in doubt add white spaces.  It will save much pain
>and anguish.
>
>
>2) The opening bracket of a function or control structure should be on
>the same line  ...  NOT THE NEXT LINE!!!!!!
>
>For example  -   THIS will work
>
>proc myproc { } {
>...
>      for { set i 0 } { $i < $list_length } { incr i } {
>            ...
>           if {$distance > $bridgeDistance} {
>             .....
>           }
>     }
>...
>}
>
>This WILL NOT WORK , although it is far more readable.
>
>
>proc myproc { }
>{     # this bracket is on the wrong line
>...
>      for { set i 0 } { $i < $list_length } { incr i }
>     {  # bracket on the wrong line
>            ...
>           if {$distance > $bridgeDistance}
>          {  # bracket on the wrong line
>             .....
>           }
>     }
>...
>}
>
>Generally the TCL interpreter's error messages are misleading.  It is
>best to have a small data set to use during development and run the TCL
>code often.  If your TCL script breaks just remove the newest lines of
>code that you have added until you pinpoint the issue.  Good luck
>
>Geordie Hobart,
>GIS Analyst/ Programmer
>[EMAIL PROTECTED]
>
>Refractions Research Inc.
>www.refractions.net
>300-1207 Douglas St.
>Victoria, BC.
>Canada, V8W 2E7
>phone 250-383-3022
>fax  250-383-2140
>
>
>mark2atsafe wrote:
> > Hi Chris,
> > I'm not a mapping file expert but I think this should be possible.
> >
> > Try...
> >
> > @SupplyAttributes(mapinfo_brush_foreground,@Tcl2(myTCLfunction))
> >
> > and then within the function retrieve any attribute with the line
> > "FME_GetAttribute myAttributename". I'm not sure how you'd retrieve a
> > global within a Tcl procedure.
> >
> > Make sure you use @Tcl2 and not @TCL2 (shouldn't be all upper case).
> >
> > If you use @TCL instead of @Tcl2 then you'd need the line "global
> > FME_Attributes" to make the attributes available to you.
> >
> > Hope this is useful; if you're still having problems then I think
> > you'll need to post your files for us to check out, plus a bit more
> > info on exactly what error messages you receive.
> >
> > Regards,
> >
> > Mark
> >
> > Mark Ireland, Product Support Engineer
> > Safe Software Inc. Surrey, BC, CANADA
> > [EMAIL PROTECTED] http://www.safe.com
> > Solutions for Spatial Data Translation, Distribution and Access
> >
> > --- In [email protected], "christweekie" <[EMAIL PROTECTED]> wrote:
> >
> >> Hello
> >>
> >> Part of my FME file to create style MapInfo TAB files has this
> >>
> >> @SupplyAttributes(mapinfo_brush_foreground,16755370)
> >>
> >> Is it possible to call a TCL function with parameters to get the value
> >> ? Something like this
> >>
> >> @SupplyAttributes(mapinfo_brush_foreground,@myTclFunction(&param))
> >>
> >> where myTclFunction is my own TCL procedure INCLUDEd in the mapping
> >> file and &param is some parameter derived from the source table or a
> >> global variable
> >>
> >> I have tried using @TCL2 and @TCL but can't get it to work.
> >>
> >> Thanks anyone !
> >>
> >> Chris
> >>
> >>
>
>
>
>
>
>Get the maximum benefit from your FME, FME Objects, or SpatialDirect via 
>our Professional Services team.  Visit www.safe.com/services for details.
>Yahoo! Groups Links
>
>
>
>
>
>
>

_________________________________________________________________
Få de bedste søgeresultater med MSN Search:  http://search.msn.dk


Get the maximum benefit from your FME, FME Objects, or SpatialDirect via our 
Professional Services team.  Visit www.safe.com/services for details. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/fme/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 
set comment {
===============================================================================

  Navn          : Peter Laulund, KMS

  Oprettet dato : 03 februar 2005 - 09:56

  Beskrivelse   :

=============================================================================}

# ============================================================================= # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
proc a {param} {

    switch -- $param {
       1      {set retVal 12345 }
       2      {set retVal 23456 }
     default  {set retVal 34567 }
    }
    return $retVal
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
proc b {} {
  FME_SetAttribute myAttr "some value"
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # =============================================================================

/* ============================================================================

  Navn          : Peter Laulund, KMS

  Oprettet dato : 2 februar 2005

  Beskrivelse   :

============================================================================*/

# ============================================================================= # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#FME_DEBUG MAPPING_FILE

READER_TYPE NULL
READER_KEYWORD INPUT
INPUT_DATASET nullin

WRITER_TYPE NULL
WRITER_KEYWORD OUTPUT
OUTPUT_DATASET nullout

Tcl2 source $(FME_MF_DIR_UNIX)/null.tcl

# ============================================================================= # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FACTORY_DEF * CreationFactory \ FACTORY_NAME "Create Some Features" \ 2D_GEOMETRY 0.01 0.01 \ NUMBER_TO_CREATE 1 \ OUTPUT FEATURE_TYPE someFeature \ @SupplyAttributes(newAttribute, @Tcl2( "a 2" )) \ @Tcl2( b ) \
     @Log("start", 1, 1)

# =============================================================================
INPUT *

OUTPUT *

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # =============================================================================

Reply via email to