Jump to content
matteoluigi

if condition with wildcards in strings in python?

Recommended Posts

Posted (edited)

just a simple question:

 

I want to scan object styles.

for example "BA-I-BST-370-230-BFT" contains the letters *BST*

 

in a worksheet I would write sth like =if('stylename'='*BST'; yes;no)

 

in Python I tried (running in a foreach-procedure, it has to filter all slab styles, which names contain the letters BST): (i read somewhere that '.+' is the Asterisk equal for python)

if outValue == ('.+BST.+'):

 

however, it doesn't filter work, why?

Edited by matteoluigi

Share this post


Link to post

You’re thinking of a regex string, which still needs a function call in python. Do a web search for python strings. You should be able to find a substring call. I believe the keyword “in” will work as well (“BST” in outValue). 

  • Like 1

Share this post


Link to post
Posted (edited)
39 minutes ago, matteoluigi said:

in Python I tried (running in a foreach-procedure, it has to filter all slab styles, which names contain the letters BST): (i read somewhere that '.+' is the Asterisk equal for python)

if outValue == ('.+BST.+'):

 

however, it doesn't filter work, why?

 

If you want to use regular expressions, you have to use explicitly the module "re", the one handling regular expressions: https://docs.python.org/3.8/library/re.html

Be careful that in regular expressions .+ means "at least one character", which might not what you seem to want.

Edited by Nicolas Goutte
  • Like 1

Share this post


Link to post
14 hours ago, Nicolas Goutte said:

If you want to use regular expressions, you have to use explicitly the module "re"

that's to complicated, I solved it with a substring

(of course the letters 'ABB', 'BST' or 'NEU' always appear at the third place in the stylename which has to be separated by '-' 😉)

 

Quote

ok, outValue, outType, outMap  = vs.IFC_GetPsetProp2((HNDL),'IfcBeam','Name')
Style = vs.SubString(outValue, '-', 3)

if Style == 'BST':

     .......

 

Share this post


Link to post
Posted (edited)

You can achieve that easily by writing "if 'BST' in outvalue:" As long as it's okay that the string can be at any position in outValue.

Edited by Tobias Döngi
  • Like 1

Share this post


Link to post
1 minute ago, Tobias Döngi said:

As long as it's okay that the string can be at any position in outValue.

otherwise I can use a substring-function before :-), thanks!

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×
×
  • Create New...