Select to view content in your preferred language

Converting a VB script into Python

13899
11
Jump to solution
10-24-2019 08:29 AM
SLouq
by MVP Alum
MVP Alum

I had some VB code in one of my Calculate Field modules in modelbuilder. I am trying to convert it to Python
Can anybody help me with this?

IF RTRIM([PRE_DIR]) = " " then

MyLabel = LTRIM([STR_NAME]) & " " & [SUF_FIX]

else

MyLabel = RTRIM([PRE_DIR]) & " " & LTRIM(RTRIM([STR_NAME])) & " " & [SUF_FIX]

end If

Thanks

0 Kudos
11 Replies
RobertBorchert
Honored Contributor

I have been able to accomplish some pretty cool things by exporting a model to python. 

I had to figure out a way to import 6 feature classes from 1400 file geodatabases that all had the same name that were exports from StakeOut (a software for marking utility lines)

So I made a model that would do it for one of the databases. Exported it to python.  Took the python script into MS Access and pasted it in to a Long Text Field.  I then put in the variations of the database names in another table and joined them together. Did a find replace to insert the variables, added the Del function at end.  Pasted the new script back into python and went from there.

So my next question is.  Is this a script that will run more than once?  If so you need add the Del function at the end of the script to reset the variables.

0 Kudos
SLouq
by MVP Alum
MVP Alum

Yes this is a script which I will have to run occasionally. I still have ArcMap 10.7 on my computer so I'm not completely devoid of using my old way of running the script in VB. I'm just slowly trying to learn how to do it in Python in case in the future I lose my connection with ArcMap and have to rely on using ArcGIS Pro.

Hopefully I never have to get that complex in scripting. That's a clever way of using other programs to figure out how to accomplish a complex task!

Cheers!

0 Kudos