Peer-to-Peer Forum

2 of 2
2

Login Register    
scripting a -1
Posted: 27 May 2011 07:19 AM   [ # 16 ]  
Member
RankRankRank
Total Posts:  59
Joined  2009-05-18

Yes you can have quotations in your comments, just modify this line

      ok = mgSetComment(rec,“change this to your comment”)

to

      ok = mgSetComment(rec,”\“change this to your comment\”“)


Cheers

 
Posted: 27 May 2011 07:29 AM   [ # 17 ]  
Sr. Member
RankRankRankRank
Total Posts:  156
Joined  2007-09-27

BINGO!

A really eloquent piece of code ! 

And a real bunch of mundane data entry tasks out the window! 

really thanks very much

 
Posted: 27 May 2011 07:55 AM   [ # 18 ]  
Moderator
RankRankRankRank
Total Posts:  604
Joined  2008-07-02

I got a copy of the openflightdd yesterday afternoon.  Its so much better then inserting a letter into the code to see what the suggestions turn up!  ( Nothing in there about mgSetComment though.)

Ah… hunting for record codes in the Script Editor (while useful) is not the best way to know which attribute to pick. The data dictionary lists all the attribute codes with their associated node types.  But you won’t see any reference to API functions here.

However in OpenFlight API 4.2 Data Dictionary fltComment was added to all applicable node records.  So, you can still use mgGetComment and mgSetComment to get or set the comment on any applicable node but now you CAN use mgGetAttList and mgSetAttList to get or set the comment - just like any other field using the fltComment attribute.

 
Posted: 27 May 2011 08:08 AM   [ # 19 ]  
Sr. Member
RankRankRankRank
Total Posts:  156
Joined  2007-09-27

this is one area where it is obvious that Im in over my head.  Looking in the right resource definetly would help as you say.  Its also obvious how powerful scripting can be.

Even as Johns script is fab,  it walks the whole db, and I need it to only walk a list of selected polygons.  I hate asking and asking.  I’ll try to find that OpenFlight API 4.2 Data Dictionary

 
Posted: 27 May 2011 08:48 AM   [ # 20 ]  
Moderator
RankRankRankRank
Total Posts:  604
Joined  2008-07-02

I’ll try to find that OpenFlight API 4.2 Data Dictionary

It’s not good enough just to find the OpenFlight API 4.2 Data Dictionary… you have to use OpenFlight API 4.2 (or in your case Creator 4.2).  If you are using 4.2, you can simply use fltComment in mgGet/SetAttList.  If you are using an earlier version, Creator won’t know what fltComment means if you try to use it.

 
Posted: 27 May 2011 08:58 AM   [ # 21 ]  
Moderator
RankRankRankRank
Total Posts:  604
Joined  2008-07-02

Even as Johns script is fab,  it walks the whole db, and I need it to only walk a list of selected polygons.  I hate asking and asking. 

You can certainly reuse bits of John’s script to apply to individual selected polygons.  Try the Edit>Code Snippet tool in the Script Editor and choose Select List Iterator.  This will insert skeleton code you can fill in with your custom code.  With the code it produces, use the “rec” and apply John’s functions to “clear” the items you want on the polygons.

The following is an example of how you could adapt John’s code easily (using the Code Snippet spit out) to process the select list instead of the whole database.  Programmer’s will cringe when they see how I’ve misused John’s original “Clear” function but this will work (but admittedly not very elegantly).

def ClearSMCIndex (dbparentreci):
  if (
mgGetCode(rec) == fltPolygon):
      
mgSetAttList (recfltPolySmc1)  
  return 
MG_TRUE
  
db 
mgGetCurrentDb()
selectList mgGetSelectList (db)
num mgGetRecListCount (selectList)

if (
num == 0):
    
mgSendMessage (MMSG_ERROR"Nothing selected")
else:
    print 
"Selected Nodes:"
    
for i in range (0num):
        
rec,mgGetNextRecInList (selectList)
        
ClearSMCIndex (NoneNonerecNone

If you wanted to be more elegant, you could refactor the Clear functions a bit as suggested here:

def ClearPolySMCIndex (rec):
    
mgSetAttList (recfltPolySmc1)  
    
def ClearSMCIndex (dbparentreci):
    if (
mgGetCode(rec) == fltPolygon):
        
ClearPolySMCIndex
    
return MG_TRUE
  
db 
mgGetCurrentDb()
selectList mgGetSelectList (db)
num mgGetRecListCount (selectList)

if (
num == 0):
    
mgSendMessage (MMSG_ERROR"Nothing selected")
else:
    print 
"Selected Nodes:"
    
for i in range (0num):
        
rec,mgGetNextRecInList (selectList)
        if (
mgGetCode(rec) == fltPolygon):
            
ClearPolySMCIndex (rec
 
Posted: 27 May 2011 10:51 AM   [ # 22 ]  
Sr. Member
RankRankRankRank
Total Posts:  156
Joined  2007-09-27

cool !

Thanks!  I’ll look at that

what I did was take Johns code (with some more attributes) and instead of

MWALK_NOREADONLY


I used

MWALK_ON  where I hid the polys I didn’t want modified to those values


Your addition works great Steve!  Woohooo!  Its like the weekends arrived already!  Added in the whole list of attributes and comments and it works like a charm.  then set up some default “genres” and it helps for the majority of model types


thanks

 
Posted: 27 May 2011 11:29 AM   [ # 23 ]  
Moderator
RankRankRankRank
Total Posts:  604
Joined  2008-07-02

Rock on with MWALK_ON!

 



2 of 2
2