Hi,
In order to avoid typing the name, the following line needs to be modified:
ret,namePattern = mgPromptDialogString (None, 30, "Enter Name Pattern", "root_%d")
This line as written will put up the prompt dialog you are seeing. Instead of prompting, you can just hard code the name like this:
namePattern = 'Hidden'
The next trick is to use the mgSetNameUnique function. This will automatically make the name unique for you so you don't have to worry about appending numbers etc.
nice! thank you...
here it is for whoever stumbles across it later.
class counter_wrapper:
count = 0
# this list "collects" the faces we want to delete
match_list = []
# Function finds polygons that have Hidden Polygon set to true.
def findHiddenPolys ( db, parent, rec , counter):
type = mgGetCode (rec)
if ( type == fltPolygon ):
outs = mgGetAttList (rec, fltPolyHidden)
if (outs[2] == 1):
counter.match_list.append (rec) #append polygon name to list of changed polygons
counter.count = counter.count + 1 #this counts the number of polygons changed
return MG_TRUE
def project_polys (counter):
for face in counter.match_list:
namePattern = 'hidden'
oldName = mgGetName(face)
newName = namePattern
b = mgSetNameUnique(face,newName)
mgSelectOne(face)
mgExecute("Project",None)
b,i,j,k = mgGetPolyNormal(face)
if k == 1:
mgExecute("Reverse Face",None)
return MG_TRUE
db = mgGetCurrentDb()
mgWalk(db,findHiddenPolys, None, counter, MWALK_NEXT)
project_polys(counter)
del counter.match_list[:]
counter.count = 0
mgWriteDb(db)
mgCloseDb(db)
John
I was trying to change the name of a polygon that is under a footprint group. Using the mgSetName(or trying to)
i see the name must be unique to the database...I am using a script that selects the polygons(by hidden face) and just simply want to rename it hidden, hidden1.....
i found this digging around: and applied it within a script. it works for me except that I have to type the name hidden every time the script hits a new file.
is there an easier solution to just rename the face?
class counter_wrapper:
count = 0
# this list "collects" the faces we want to delete
match_list = []
# Function finds polygons that have Hidden Polygon set to true.
def findHiddenPolys ( db, parent, rec , counter):
type = mgGetCode (rec)
if ( type == fltPolygon ):
outs = mgGetAttList (rec, fltPolyHidden)
if (outs[2] == 1):
counter.match_list.append (rec) #append polygon name to list of changed polygons
counter.count = counter.count + 1 #this counts the number of polygons changed
return MG_TRUE
def project_polys (counter):
for face in counter.match_list:
ret,namePattern = mgPromptDialogString (None, 30, "Enter Name Pattern", "root_%d")
oldName = mgGetName(face)
newName = namePattern
b = mgSetName(face,newName)
mgSelectOne(face)
mgExecute("Project",None)
b,i,j,k = mgGetPolyNormal(face)
if k == 1:
mgExecute("Reverse Face",None)
return MG_TRUE
db = mgGetCurrentDb()
mgWalk(db,findHiddenPolys, None, counter, MWALK_NEXT)
project_polys(counter)
del counter.match_list[:]
counter.count = 0
mgWriteDb(db)
mgCloseDb(db)