The type initializer for 'Autodesk.LibG.LibGPINVOKE' threw an exception

My script requires the node Element.GetLocation but it’s giving me the error The type initializer for ‘Autodesk.LibG.LibGPINVOKE’ threw an exception. It is working on a local working place on my laptop, but this error happens when I try to run the script at my workplace where Revit, Dynamo and every file is located on a server. Is there a workaround to get this script working at my workplace without having to have a local c: drive with revit on it?

you can avoid using this node by just one line of code though.

elem = UnwrapElement(IN[0])
Out = elem.Location # it could be a LocationPoint or LocationCurve 

Similar thing happened to me once, same script just won’t work on only one of the computers at my office.

1 Like

How do I do that? I just add those lines in a python script node?

I had this a couple of days ago. I updated Dynamo and it fixed it.

Have you checked for updates?

It depends on your context.

elem = UnwrapElement(IN[0]) # one element only, UnwrapElement will reveal the inner Element object(Revit), IN[0] being your element(Dynamo)
OUT = elem.Location.Point # point location, for example, FamilyInstance
OUT = elem.Location.Curve # curve location, for example, Wall

or it could be a list of elements:

elems = [UnwrapElement(item) for item in IN[0]]

OUT = [e.Location.Point.ToPoint() for e in elems] # ToPoint() converts XYZ object (Revit) to Point (Dynamo), I suppose you need Dynamo Points to work with your downstream nodes.

So sum it up, it needs one line:
elem = UnwrapElement(IN[0]).Location.Point.ToPoint()

I’d suggest u go for @MartinSpence 's idea first. If update can solve it, then you don’t need any of code above.

Hey @jshial,

You don’t have to iterate UnwrapElement() anymore. The function works recursively :slightly_smiling_face:

1 Like

Thx! I didn’t know that! This is why I like the forum, I can always learn something new.:+1: @MartinSpence

1 Like

I tried that code in a python script for a list of elements, I get the error that the object is missing the attribute of ‘location’. What am I doing wrong?

you have a list of lists. Each sub-list is a collection of walls. if you don’t care about this structure, simply use List.Flatten to convert them into just a flat list of walls.

Now I’m getting this

Try this:

Location.Curve.ToProtoType(True)

image

I have no python programming experience at all, so I apologise if I’m being annoying.
But is this what the script should look like now?;

elems = [UnwrapElement(item) for item in IN[0]]
Location.Curve.ToProtoType(True)
OUT = [e.Location.Point.ToPoint() for e in elems]

Cause now it says NameError: name ‘Location’ is not defined. Same error if I use OUT= elem.Location.Curve

demo.dyn (7.1 KB)

There’s no need to apologize, here is demo script :point_up:

image

Location of Revit elements has different representation: Point or Curve. Wall has a LocationCurve whereas FamilyInstance like a desk has a LocationPoint.

Some good references here, there’s a lot of fun if you can put the Python Node to good use.
https://primer.dynamobim.org/en/10_Custom-Nodes/10-4_Python.html

The script seems to work on my laptop but on my workplace computer I get again the same error I used to get with the node Element.GetLocation;

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 51, in
File “”, line 51, in
SystemError: The type initializer for ‘Autodesk.LibG.LibGPINVOKE’ threw an exception.

*Edit: Eventhough it works on my laptop, it seems like the script takes ages to run now with the python code replacement. It used to run in about 20 seconds on a large project and now it takes about 20 minutes for some reason :face_with_raised_eyebrow:

Edit2: Nevermind the first edit, the reason why it runs so heavy now is cause of the flattening of the list. It needs to stay seperated cause the script is joining geometry based on location of each wall type instance.

That’s the thing, here at the workplace they are unwilling to update the dynamo version since they have a small database of existing scripts which they use and are afraid to have to fix/change nodes for some of them after updating.

Did some research just now, the error could happen when using native Dynamo geometry library. Some GitHub responses suggest the problem is not reproducible in latest build of Dynamo…Seems like an update is your only option…

Same thing here, but solved with an upgrade.

GitHub discussion:

Yeah it looks like it, I saw the discussion earlier aswell…
I am doing a research for my thesis and I don’t really need to use it at the workplace as long as I can provide the information on how to make the scripts work if they want to use it in the future. An update seems like the only way to make this script work at the workplace’s server.
Thank you for the great effort jshial, I am extremely grateful! You also made me more interested in learning Pyhton, seems like a very smart and efficient way to make the dynamo scripts work the way you want to and not be depended on custom nodes. This will definitely take me a lot of time and practice. :sweat_smile: