Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Python script runs twice

$
0
0

Hi,
I’ve written a Python script as a command in the Rhino Python Editor.

When I run it in debug mode it runs great.
but if I run it from a Rhino command it runs twice.
Interestingly at the end of the first run it prints the ‘Finished…’ message, but not at the end of the seconf time round.
I have exited, rebooted and tried all permutations of -zBldID, or '-’ or just ‘-’ or ‘_’ or nothing.
I have also changed the position of ver= and True/False etc etc.
I am just not seeing the wood for the trees…
Any ideas?

Thanks and regards,
Zoltan

import rhinoscriptsyntax as rs

commandname = “zBldID”
def RunCommand( is_interactive ):
job = rs.DocumentName().split(‘.’)[0]
blds = rs.ObjectsByLayer(‘Building’, False)
n_blds = len(blds)
n_bld = 0
for bld in blds:
n_bld += 1
oldid = rs.GetUserText(bld, “#0", False)
if oldid == None:
oldid = ‘z’ + '
{0:06d}'.format(n_bld)
bldid = job + ‘_{0:06d}’.format(n_bld)
rs.UnselectAllObjects()
rs.Command(”_SelBoundary _SelectionMode=Crossing selid {} _Enter".format(str(bld)), False)
rfps = rs.SelectedObjects()
rs.UnselectAllObjects()
n_rfps = len(rfps)
if n_rfps > 0:
print(‘{0:6d}’.format(n_bld) + ’ of {0:6d}‘.format(n_blds) + ’ Changing {0:6d}’.format(n_rfps) +
’ rooftops from ’ + oldid.rjust(15) + ’ to ’ + bldid.ljust(15))
bld_bool = rs.SetUserText(bld, “#_0”, bldid)
for rfp in rfps:
rfp_bool = rs.SetUserText(rfp, “#_0”, bldid)
del oldid
if n_blds > 0:
rs.DocumentModified(True)
return 0

ver = ‘2.6’ # 20230925 1st deployment
RunCommand(True)
print(‘Finished running TRUE ’ + commandname + ’ v’ + ver)

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles