Link DWGs in Drafting Views?

No filenames issues here: it works if I use Konrad’s code (with one file)

Could you make a custom node of it and use lacing to get there?

1 Like

Great, this works, thanks a lot! :slight_smile: (sorry but I will have to leave the solution of this thread where it was initially)

Totally fine. Im just happy you’re all set. :slight_smile:

Hey @Konrad_K_Sobon I am trying to understand this line of code:
linkedElem = clr.Reference[ElementId]()
I tried googling and it seems that in some cases the variables must be initialized to set some sort of “value field” (in this case an ElementId). But why and when does this happen?
Furthermore what should be done with “linkedElem” to show as a “revit element” output in dynamo?Does it have to do with wrapping?
Thanks

@GregX
This is often confusing because it has to do with a language feature that exists in C#/.Net but not in Python.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ref
Ref values (or out, which is similar) is explained above. It basically means that instead of the function getting an argument and returning a value,
you first create a reference, then pass it to the function. A value for the reference object is then set_within_ the function, instead of returned. The function may return other values, but the reference (ref parameter) will always be set within it and not returned.
Since this is.net specific, you must use the clr module to create this type of object (typed reference object)

The returned value and ref value are explained here:
http://www.revitapidocs.com/2016/f3112a35-91c2-7783-f346-8f21d7cb99b5.htm

Details on the Ironpython implementation of ref and out (similar to ref) here:
http://ironpython.net/documentation/dotnet/dotnet.html#ref-and-out-parameters

Edit: clarity

4 Likes

http://revitapisearch.com/html/f3112a35-91c2-7783-f346-8f21d7cb99b5.htm24

Working Link

Thanks for the explanation! I am trying to get a hold of python but everytime there is (luckily?) something new to learn and understand!

I tried this in the simplified version provided above and in the latest version by Konrad and it doesn’t work. The later version will create the drafting views but that’s it. What are you all doing to make this script work?

Hmm. I dont know… If your lists of views and paths are the same length it should work fine.
Check what errors the python nodes give.
Maybe something changed in the latest api?

This is the error I am seeing.

The script tries to get the length ‘len()’ of the list of views ‘In[1]’ to iterate for all views.
This means that your input is not a list. Looks like you have connected the wrong node.
IN[0] = List of dwg file paths
IN[1] = List of Drafting views

If both lists are the same length it will import all dwgs on the views.
If for some reason you want to put all the dwgs on one view, use ‘list of repeated item’ to make a list the same length with the single view.

Should be connected something like this;

So I got it working. I can’t take credit though. An associate Jason Boehning from our training content provider Cad learning pointed out a case error between “LinkedElem” and “linkedElem”. Once that was corrected it works.

Hey Gui,

Sorry to resurrect an old post here, but I’ve been working for hours and feel like I’m so so close here. If I could get a little assistance I think I’d be there. I’m trying to take the code to import in CAD files and have the output be the linked file (either the elementID or the element itself). As you explained in your post above, the clr.Reference as I understand it acts as a function reference, so you can’t pull values out of it by itself.

I’m following the posts you linked above and feel like I’m close, but I can’t quite get it. I’m getting the boolean to fall out, but I can’t get it “True”, much less get a value from it. I’m very new to python so I’m trying to figure all this out. Any assistance or advice would be greatly appreciated.

@Konrad_K_Sobon thanks for your code,

It’s possible ton add in your python script, a out parameter with instance of dwg ?

i would like attribute a workset in a dwg file after link.

thanks for all

Best,

Hi Rémy,

One possible way is to change the output to provide Filepath.
And with a string contain and a boolean mask you will obtain the ImportInstance.

Drafting View.dyn (13.5 KB)

2 Likes

Ok thanks @Alban_de_Chasteigner Alban, I thought there would be a more direct solution.

What is the package for a node Passtrough ?

Passthrough is from Clockwork.
ImportInstance is not a commun Revit Categorie so it’s no easy to manipulate in python but more skilled users should have a better solution.

1 Like

Ok thanks, clockwork is a great package !

Hi
I have tried running your script but can’t work out why the visibility isn’t showing ? Do I perhaps need to redefine the options.x in the python script? I’m trying to run this in Revit 2018 so not sure if the API has much differences in these settings?


It appears in my manage links - in my VG settings though it doesn’t, I checked under the Imports in Families and it isn’t displaying any layers relating to the CAD link either ? it’s only showing the already imported not the import from the script

Once I look at my view I also can’t see the CAD link appearing in my view? but Revit is telling me it has been linked - I have already done everything I can think of in that regard of making sure the setting view range etc are correct. I tried manually linking to make sure it wasn’t the dwg file and it came in fine.

If you know why this may be happening please don’t hesitate to let me know! I’ve been investigating for hours and I haven’t been able to identify the issue - need another perception