Revit API - How to Access Family Parameters "Discipline" and "Type of Parameter" - revit-api

i am trying to filter my list of a family parameters by their Discipline.
But i do not know how to access it. The same goes for the "Type of Parameter" as you see in the image.
List<FamilyParameter> famParm_lst = FamMngr.GetParameters().Cast<FamilyParameter>().ToList();
List<FamilyParameter> famParm_PipeSize_lst = famParm_lst.Where(fp => fp.Definition.(Discipline) == (Pipe Size)).Select();
Any idea on how i can check for a Discipline of a value "Pipe Size" ?

Look at FamilyParameter Class → Definition Property
→ Definition Members.

So this is how I got the Discipline and the "Type of Parameter":
//tmpParam is a Family Parameter
string getDateTypeId = tmpParam.Definition.GetDataType().TypeId;
string Discipline = getDateTypeId.Split(':')[0].Split('.').Last();
string TypeOfParameter = getDateTypeId.Split(':')[1].Split('-')[0];

Related

Change family and type of an element with Revit API

I'm trying to build a script that changes the family and the type of an element from a selected element in the model in Revit. I've tried what I've been doing for the rest of the paramaters of the element:
from Autodesk.Revit.DB import Transaction
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
transaction = Transaction(doc, "Modify element")
transaction.Start()
gdict = globals()
max_elements = 100
if uidoc:
selection = [doc.GetElement(x) for x in uidoc.Selection.GetElementIds()]
for idx, el in enumerate(selection):
if idx < max_elements:
gdict['e{}'.format(idx+1)] = el
print(el.LookupParameter('Type').AsValueString())
update = el.LookupParameter('Type').SetValueString('ANG')
transaction.Commit()
This way I can access to the type parameter, but it's not changing at all (it's the same for the family parameter, but again, nothing changes after running the code).
I'm assuming this must be because of the relation between Type and Family. Do you have any idea how to change this?
Thank you in advance!
Yes.
Use the Element.ChangeTypeId method.

default values for PersistList on SQLite - Yesod

I would like to add a PersistList value into a user entity with a default value. My model file looks like this. And Models.hs file:
User
ident Text
password Text Maybe
UniqueUser ident
perms [Privileges] default=[PrvDemoOne]
deriving Typeable
data Privileges =
PrvDemoOne -- ^ what can be demo one...
| PrvDemoTwo -- ^ what can be demo two...
deriving (Show,Read,Eq)
derivePersistField "Privileges"
the code compiles but when a new user is added into the table save an empty array instead of an array with the default value.
1|google-uid:223344555661778819911||[]
The question is how I could save the column with the default value?
Have you read this? The value of the default field doesn't really have anything to do with the Haskell side per-se, it's being passed to set the "default value" description your DBMS. In this case [PrvDemoOne] is being passed directly to SQLite, which will interpret it as gibberish (because it's not a valid SQL expression) so this is either ignored or (what seems to be the case here) treated as if you hadn't set a default at all.
If you want a "Haskell side" default value you should just create a function for that, i.e. something like
defaultUser :: Text -> Maybe Text -> User
defaultUser i maybePw = User { ident = i, password = maybePw, perms = [PrvDemoOne] }
If you want a SQL side default you need to write the corresponding SQL expression for the value you're trying to represent.
On a non-Haskell related note: the 'normal' way to represent lists (or sets in this case, rather!) in SQL is via relations, so you'd normally have a many-to-many relationship mapping users to their privileges instead of a list field.

Generate field from association

I want to generate a field from association.
The problem that I have is that I'm using:
[for (p: Property | aClass.getAssociations().ownedEnd -> select(p: Property | p.type <> aClass)) separator('\n')]
[p.visibility/] [p.type.name/] [p.type.name.toLowerFirst()/];
[/for]
[for (p: Property | aClass.getAssociations().ownedEnd -> select(p: Property | p.type = p.getOtherEnd().type)) separator('\n')]
[p.visibility/] [p.type.name/] [p.type.name.toLowerFirst()/];
[/for]
So that checks for all associations and if the association type isn't the same ass class type it creates a field of that type.
And if the ends are the same type it creates a field of the same type as the class in which it is contained.
So basically if there is association A - B and A - A
For B create A, for A create B and A.
But there is a problem with second loop. It creates two fields instead of one, which is pretty logical. And here comes the question. How I can fix this? I'm not sure if I'm able to declare some kind of variable here and check %2. I can't just take one value, because there could be multiple associations.
Perhaps I did all the thing wrong? Maybe there is a way to iterate over the ends that would save me all those checks and two for loops?
[for (a: Association | aClass.getAssociations())]
[if a.ownedEnd.type = a.ownedEnd.getOtherEnd().type]
[a.visibility/] [a.endType.name/] [a.endType.name.toLowerFirst()/];
[else]
[for (p: Property | a.ownedEnd -> select (type <> aClass))]
[p.visibility/] [p.type.name/] [p.type.name.toLowerFirst()/];
[/for]
[/if]
[/for]
That seems to do the trick

ThisIsNotAObjectReference error when accessing component of returning parameter

I'm getting ThisIsNotAObjectReference syntax message when trying to handle a fully typed data reference expression like this:
method getDataReference.
rr_value = ref #( varStructure ).
endmethod.
data(lr_value) = object->getDataReference( )->structureComponent.
I understand the syntax is identical for retrieving object references but how to deal with fully typed data references in expressions?
You cannot chain method calls with reference component accesses. You should use auxiliary variable like here:
CLASS lcl_class DEFINITION.
PUBLIC SECTION.
METHODS: getdatareference RETURNING VALUE(rr_value) TYPE REF TO mara.
ENDCLASS.
CLASS lcl_class IMPLEMENTATION.
METHOD getdatareference.
DATA: ls_mara TYPE mara.
rr_value = REF #( ls_mara ).
SELECT SINGLE * FROM mara INTO rr_value->*.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA(lcl) = NEW lcl_class( ).
DATA(lv_mara) = lcl->getdatareference( ).
DATA(l_matnr) = lv_mara->matnr.
I'm kind of speculating about what you're trying to achieve here but as far as I know you'll need to dereference data reference before you can access their contents. The following extends the code you posted above.
report ztest.
class lcl_test definition.
public section.
methods getDataReference
returning value(rr_value) type ref to tadir.
private section.
data varStructure type tadir.
endclass.
class lcl_test implementation.
method getDataReference.
varstructure-author = sy-uname.
rr_value = ref #( varStructure ).
endmethod.
endclass.
start-of-selection.
data(object) = new lcl_test( ).
data(lr_value) = object->getDataReference( ).
field-symbols <structure> type tadir.
assign lr_value->* to <structure>. " This is the dereferencing step
write / <structure>-author.

F# attributes, typeof, and "This is not a constant expression"

EDIT: Added a more complete example, which clarified the problem.
Some .NET attributes require a parameter of type Type. How does one declare these parameters in F#?
For example, in C# we can do this:
[XmlInclude(typeof(Car))]
[XmlInclude(typeof(Truck))]
class Vehicle { }
class Car : Vehicle { }
class Truck : Vehicle { }
But, in F# the following...
[<XmlInclude(typeof<Car>)>]
[<XmlInclude(typeof<Truck>)>]
type Vehicle() = class end
type Car() = inherit Vehicle()
type Truck() = inherit Car()
...results in a compiler error: This is not a constant expression or valid custom attribute value.
You should address a circular type dependency introduced by forward usage of types in attributes. The snippet below shows how this can be done in F#:
// Compiles OK
[<AttributeUsage(AttributeTargets.All, AllowMultiple=true)>]
type XmlInclude(t:System.Type) =
inherit System.Attribute()
[<XmlInclude(typeof<Car>)>]
[<XmlInclude(typeof<Truck>)>]
type Vehicle() = class end
and Car() = inherit Vehicle()
and Truck() = inherit Car()
Can you try putting together a more complete example that gives the error? I just quickly tried something similar and it works fine (in F# 3.0 in Visual Studio 2012):
type Car = C
type XmlInclude(typ:System.Type) =
inherit System.Attribute()
[<XmlInclude(typeof<Car>)>]
let foo = 0
I guess there is some tiny detail somewhere that confuses the F# compiler for some reason - but it should understand typeof (which is, in reality, a function) and allow its use in attributes.

Resources