Visualizzazione post con etichetta Python. Mostra tutti i post
Visualizzazione post con etichetta Python. Mostra tutti i post

lunedì, agosto 22, 2016

Self-Redefinition in DesignScript

I just stumbled upon this interesting fact of the default language block you have in Code Blocks:

It looks kind of weird at first right? you would expect that the result is 1, not 2, if you do the same in a Python script you have right 1:



Note how there is only one output port on the Code Block, this is because the variable in play is called x on both lines, plus the default language block is Associative which means that each assignment is re-executed, some sort of recursion, to update all the variables values.

At first x = 0, on the second line the same variable x is then assigned to an expression x + 1, which returns x = 1, but since 1 is different form 0 it means that the value associated to x has changed so the Associativity kicks in and it re-executes the assignment that yields 1 + 1 = 2   which is totally correct in terms of DesignScript Associative language block context.

There are a couple of options to get the "standard" value 1 out of a Code Block:



Look at the number of output ports on the right side of these Code Blocks, just be thoughtful when you are using DesignScript because you need to know its own rules.



martedì, aprile 05, 2016

Delaunay Triangulation with Dynamo


I was reading a tweet by Dimitar Venkov and it caught my attention, how can you use Dynamo to create a triangular mesh from a list of points, here is the discussion on the forum.

I was looking at the same problem my self not too long ago, it is achievable in Dynamo too but there is a lot to learn about Delaunay Triangulation and the algorithms to solve it.

Searching on the internet I've found several examples, the one I decided to try to implement in Dynamo is this one.

Basically is what Revit does when it reads a LandXML file and converts it into a Topographic Surface, well... almost..., therefore some "ghost" triangles outside the true mesh are going to appear.
If it is possible to add an outline, like a polycurve, they could be removed with a little bit extra effort.
This is not yet a Constrained Delaunay Triangulation though, but it works.

To be honest I had to swap the Y and Z coordinates in this example ant then swap it back before creating the surfaces and get rid of an extra "construction" triangle in the latest while loop.

Using the same algorithm it is possible to derive the IndexGroups  and create a Dynamo Mesh from the same list of points, the graphical result is quite different and smooth.



Once again our Dynamo Swiss Knife saved the day.



giovedì, settembre 10, 2015

Setting Active View Temporarily Disabled


Sad news, thanks to Alex S. I ran into what appears to be a by-design limitation in Dynamo.

The idea was to duplicate a Legend View since it is not possible to create a new one from the API, rename the copy and use it to set the Active View property of the UIDocument.
Turns out it's not possible to do that in Dynamo, for now.
Here's the Python script I've used, maybe someone has already found a solution to that.


venerdì, settembre 05, 2014

Dynamo - Rooms Solids - Color Scheme for any parameter

This is a further development of previous Dynamo definition, now it can apply the color scheme for any parameter, there's a little bit of coding in there because I couldn't figure out why a cross product lacing over a List.FilterByBoolMask returned a null list for the In and Out output ports.
Anyway I did it myself using a very simple script in Python.
I'm trying to avoid them as much as I can, really, but when I'm tight on the dead line and I need  the get the job done, coding is always my best option, even if I don't feel particularly comfortable with Python, but I guess it's how my brain works, I know for a fact that amazing things are achievable just using the OutOfTheBox set of nodes, so I hope to have enough time to obtain the same thing using a "pure nodes" approach instead.

I guess that the beauty of Dynamo is that everybody can play with it and  make his own tools, no doubt about that.

Here's the code I've used to collect rooms in the project:


Here's the code I've used to retrieve indexes evaluating the elements of ListA against the elements of a ListB, the output is a list of integers, as long as ListA.
In this example ListA contains Department values for each room in the project (11 rooms gives 11 items) while ListB contains the same values but derived from the Color Scheme file (5 department entries gives 5 items).


The outcome of this python script is used to determine which color has to be used to override each one of  the solids derived from rooms.

Solid extraction and ListA:


Color override and ListB:


Here's a .Zip file containing the .Dyn, .Rvt and .Csv used in this example.
In action:






lunedì, gennaio 13, 2014

Dynamo - View Utilities

EDIT*: link to nodes definitions  copy to:

C:\Autodesk\Dynamo\Core\definitions




Ho fatto ancora qualche esperimento con Dynamo e ho scoperto un po' meglio come funzionano i nodi Python Script.
Cliccando con il tasto destro e poi su Edit si può modificare a piacere il funzionamento del nodo, purtroppo non conosco ancora bene la sintassi di Python e sono dovuto andare ad intuito.
Sono riuscito a scrivere qualche nodo personalizzato con pochissime righe di codice che possono essere d'aiuto per creare delle definizioni più complesse sulle viste.

Da prima ho ricavato i componenti per costruire il Transform della vista attiva (l'origine in coordinate assolute e i vettori della base che sono già normalizzati), nodi a sinistra della figura.
Successivamente ho unificato nel generico nodo Transform già presente in Dynamo i valori appena trovati per ottenere il Trasnform della vista attiva, nodo centrale della figura.
Da qui è stato possibile, utilizzando direttamente il ViewTransform appena creato e il suo Inverso, creare delle funzioni che restituissero le terne delle coordinate con riferimento assoluto o con riferimento locale per la vista, nodi a destra della figura.

Qui trovate la definizione ViewUtils.dyn

*Thanks to Julien Benoit

If you are happy with my code you can show me some gratitude paying what you want on PayPal:

puntorevit@gmail.com