Flipped objects - help required with Python

Hi All,

I’m writing a small code block to determine whether an Element is Flipped. I’m basing my code on that contained within the DanEDU.Element.Flipped block, except that I would like the output as a basic Boolean version of the input list.

The Dan.EDU block outputs the actual element IDs into specific lists; but I’d rather avoid the graph gymnastics I would need to do to turn this back into a Boolean list, and just get the Boolean output. All credit to DanEDU for their module!

I’ll just state right here that I have very little experience with Python, and while I can pretty easily follow what a piece of Python code does, I don’t have much idea how to make it do what I want. I’m learning by doing…

The code I have written looks like this:

#Copyright(c) 2014-2016, DanEDU Dynamo
#Erik Falck Jørgensen, Technical University of Denmark (DTU)
#Modified (butchered?) by Adrian Esdaile

import clr
import Revit

#Inputs is stored in the IN variable
element = list(UnwrapElement(IN[0]))

#check if element is FacingFlipped
list0 = [ ( True if i.FacingFlipped else False ) for i in element ]

#Assign output to the OUT variable
OUT = list0

This works for one Element, but doesn’t work for a list, and I can’t work out why. I only get one single output, not a list of outputs. I have copied (cargo-cult style) ways of doing this from other Python code, but the way Dynamo obscures what the Python is or isn’t doing makes working out what I’m doing wrong very difficult.

Could someone please point out what I’m doing wrong here?


I read the suggested similar topic which had another method of building a list, and wrote the following code based on that example. it works even worse; the output is null. I can’t work out why, because the code I based it on does work.

import clr
import Revit

#Inputs is stored in the IN variable
element = list(UnwrapElement(IN[0]))
list0 = []

for i in element
	if i.FacingFlipped == True

#Assign output to the OUT variable
OUT = list0

Inlcuded DYN file: Is_It_Flipped.dyn (3.6 KB)

Strangely I copy-and-paste your first code and it works…

Can you post the error message?

Thats the problem - it don’t get any error messages; it just either results in ‘null’ for the second code block; or for the first it works, but only for the first element in the list. None of the subsequent elements get passed through the routine.

this is what the output looks like for me:

According to Dynamo it’s running without error (not yellow or red) but the output isn’t a list.

Now here’s the weird thing: I have followed the Python code almost exactly, but it doesn’t work. It’s frustrating; I really can’t work out why it’s failing. See this screenshot comparing my code to the example code. I’m declaring a list. I’m using exactly the same true/false FOR loop. I send the list to output - but I’m only getting the first entry.

I thought programming was logical - I can’t spot my obvious mistake. :sob:

For info, this is running Dynamo against Revit 2016 v16.0.1185.0 r20161004_0715(x64) - Update7 for R2

I’ve tried this from opening closing new files, save-as, unloading all Dynamo plugins, restarting entire computer - nothing.

I can see that someone else’s version works - great! But mine doesn’t. Even the code I based it on runs perfectly.

1 Like

Are you saying that the second one does not work? Well you are missing colon symbol after “for i in element”, “if…” and “else…”. For this syntax error, python evaluation will fail. Other than that it should work. Your logic and understanding are pretty solid.

I don’t have Element.FaceFlippedBool node. What package is it in? Or is it your custom node that has the second python code inside? Then maybe python fails inside that gives you null node output.

Btw, your second code can be as compact as one line - no import, list(), True/False, explicit for loop or anything needed. Just try this:

OUT=[i.FacingFlipped for i in UnwrapElement(IN[0])]

Thanks all!

I did finally get it to work, and my solution looked exactly like erfajo’s. Without the ‘:’ I might add!

It seems Dynamo, and Python Nodes in particular are very fussy about the copy source of your code. If I copy from Notepad++ with NP++ doing nice python formatting for me - it fails.

If I type it directly into the node - it works. I tried Unicode, UTF, ANSI formatiing - none work when the copy source is NP++.

It’s really hard to learn programming when a basic text editor I’ve been using for years suddenly doesn’t work because of ??? phase of moon? wrong kind of snow? I didn’t observe the correct rituals?

I have no idea; but when I typed it directly rather than pasting in as it worked first go. Maybe there is some quirky bug in Paste in Dynamo when your region is set EN-AU?

Anyone else have this problem using Notepad++?

And here’s my final code for this:

#Adrian Esdaile, 2015-2017, Billard Leece Partnership
#Package BLP
#Original idea from DanEDU package

import clr
import Revit

#uncomment two lines below for (primitive) audio feedback
#import winsound
#winsound.PlaySound("SystemExit", winsound.SND_ALIAS)

#Inputs is stored in the IN variable
element = list(UnwrapElement(IN[0]))

#check if element is HandFlipped and/or FacingFlipped
t0, t1, t2, t3 = [], [], [], []

t0 = [ (True if i.HandFlipped and i.FacingFlipped else False) for i in element ]

t1 = [ (True if i.HandFlipped and not(i.FacingFlipped) else False) for i in element ]

t2 = [ (True if i.FacingFlipped and not(i.HandFlipped) else False) for i in element ]

t3 = [ (True if not(i.HandFlipped) and not(i.FacingFlipped) else False) for i in element ]

#Assign output to the OUT variable
OUT = t0, t1, t2, t3

GetElementFlip.dyf (5.6 KB)

As it turned out, it DOES work with lists of lists; I just had to set the input nesting appropriately:
flips in action

Hi Erfajo,

thanks for the link…

I’m utterly lost trying that solution; as I don’t understand the ‘stubs’; what they are, where to find them, how to load them.

It might be that I’m a bit slow and all this is obvious; I’ve got both PyCharm and VSCode installed, and I can follow most of the instructions up to the parts where it says “just load the stubs” or “just copy the stubs”. Huh? What are they? Where do I copy them from?

EDIT: Having realized those loom links were videos being blocked by our firewall, I’ve got over that issue, but now I’m having another issue. I’m following the video step-by-step using VSC, but it’s not working. I can’t find the folders specified. I’ve downloaded and extract the Github repository, but it doesn’t contain the stub.min folder shown in the video. Am I downloading the right link?

@Adrian_Esdaile - notepad ++ failed for me as well.

I found it sometimes replaced ’ with a formatted ’ and a few other similar oddities which generally would be appreciated by most users, in addition to the indentation issues @erfajo noted. I was working around this to some extent by using regular notepad, or pasting into notepad from notepad++ before I started using code blocks or string nodes in dynamo directly.

I’m currently trying to set up VS Code based on the scattered links in the monster thread on Python autocomplete, and I’m just not having any luck at all. It looked like it would be easier than PyCharm, as PyCharm looks diabolically difficult to setup unless you happen to already be an expert coder (need to increase vm space for intellisense? oh yeah, obvious) :wink:

I’ve also just found the obvious mistake I made - the paths shown in the help video don’t mention that the paths in the repo are now different, so stub.min was a few paths further down. Well, obviously!

Rule One of learning to code "follow the typing examples exactly"
corollary: “except when you shouldn’t because they are obviously incorrect” :smiley:

So now I have parts of intellisense working, but I can see everyone else has revitpythonwrapper stubs, and when I go to the repo for that… same problem. Obviously I should know were to find the stubs or somehow create them myself.