<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Link DWG Files in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/link-dwg-files/m-p/8137482#M48680</link>
    <description>&lt;P&gt;Hey guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Should be a trivial question but I can't get this thing done and I can't understand why.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm trying to do is to link some DWG files inside of Revit project.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've seen from the SDK that now from Revit 2018 there's the API LoadFrom(string Path) and that looked like what I needed, right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But for some reason I can't use it in my program.&lt;/P&gt;&lt;P&gt;See the code:&lt;/P&gt;&lt;PRE&gt;            // Hardcode the path just for testing
            string path = @"C:\Users\atassera\ARC-2228-01.DWG[6].dwg";

            using (Transaction trans = new Transaction(doc))
            {
                trans.Start();

                CADLinkType.LoadFrom(path);
                
                trans.Commit();
            }&lt;/PRE&gt;&lt;P&gt;Ok the code is not much, I understand, but I thought this would have been pretty much it, considering that the LoadFrom method asks for a file path as a string...&lt;/P&gt;&lt;P&gt;The problem is that Visual Studio doesn't even give me .LoadFrom() as an option/suggestion and if I type it in, then it says "An object reference is required for the non-static field, method, or property....."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've also seen there's the&amp;nbsp;Link Method (String, DWGImportOptions, View, ElementId) from the Document class, but I don't want to link my DWG file to a view. I just want to normally link it as you would do from the Links Manager. That's why I didn't pursue that path.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So it's clear there's something missing but I can' understand what. Any revelation to share?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks everyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Andrea&lt;/P&gt;</description>
    <pubDate>Wed, 18 Jul 2018 08:15:38 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-07-18T08:15:38Z</dc:date>
    <item>
      <title>Link DWG Files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/link-dwg-files/m-p/8137482#M48680</link>
      <description>&lt;P&gt;Hey guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Should be a trivial question but I can't get this thing done and I can't understand why.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm trying to do is to link some DWG files inside of Revit project.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've seen from the SDK that now from Revit 2018 there's the API LoadFrom(string Path) and that looked like what I needed, right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But for some reason I can't use it in my program.&lt;/P&gt;&lt;P&gt;See the code:&lt;/P&gt;&lt;PRE&gt;            // Hardcode the path just for testing
            string path = @"C:\Users\atassera\ARC-2228-01.DWG[6].dwg";

            using (Transaction trans = new Transaction(doc))
            {
                trans.Start();

                CADLinkType.LoadFrom(path);
                
                trans.Commit();
            }&lt;/PRE&gt;&lt;P&gt;Ok the code is not much, I understand, but I thought this would have been pretty much it, considering that the LoadFrom method asks for a file path as a string...&lt;/P&gt;&lt;P&gt;The problem is that Visual Studio doesn't even give me .LoadFrom() as an option/suggestion and if I type it in, then it says "An object reference is required for the non-static field, method, or property....."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've also seen there's the&amp;nbsp;Link Method (String, DWGImportOptions, View, ElementId) from the Document class, but I don't want to link my DWG file to a view. I just want to normally link it as you would do from the Links Manager. That's why I didn't pursue that path.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So it's clear there's something missing but I can' understand what. Any revelation to share?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks everyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Andrea&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jul 2018 08:15:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/link-dwg-files/m-p/8137482#M48680</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-07-18T08:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: Link DWG Files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/link-dwg-files/m-p/8143073#M48681</link>
      <description>&lt;P&gt;Dear Andrea Tassera,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The LoadFrom method is not static, so you can not access from class CADLinkType directly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to call LoadFrom, you have to build one CADLinkType &lt;STRONG&gt;instance&lt;/STRONG&gt; firstly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Following code demonstrates how to import CAD firstly, and then use LoadFrom to load again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;// link CAD firstly
DWGImportOptions opt = new DWGImportOptions();
opt.Placement = ImportPlacement.Origin;
opt.AutoCorrectAlmostVHLines = true;
opt.ThisViewOnly = false; // not this view only
opt.Unit = ImportUnit.Default;
ElementId linkId = ElementId.InvalidElementId;
using (Transaction tran = new Transaction(RevitDoc, "Quick Link"))
{
	tran.Start();
    RevitDoc.Link(path , opt, RevitDoc.ActiveView, out linkId);
    tran.Commit();
}
//
// get the link instance and the CADLinkType
ImportInstance cadInst = RevitDoc.GetElement(linkId) as ImportInstance;
CADLinkType cadLinkType = RevitDoc.GetElement(cadInst.GetTypeId()) as CADLinkType;
cadLinkType.LoadFrom(new_path);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2018 03:07:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/link-dwg-files/m-p/8143073#M48681</guid>
      <dc:creator>JimJia</dc:creator>
      <dc:date>2018-07-20T03:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Link DWG Files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/link-dwg-files/m-p/8381901#M48682</link>
      <description>&lt;P&gt;Hello&lt;BR /&gt;I found the loadfrom&lt;BR /&gt;in vb.net&lt;BR /&gt;attached code in image.&lt;/P&gt;&lt;P&gt;the code consists of searching all the cadlinks of Revit&lt;BR /&gt;to then select a DWG for later&lt;BR /&gt;Change the cadlink in the textbox.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 926px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/565938iFF28DB74082BC79A/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Nov 2018 01:02:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/link-dwg-files/m-p/8381901#M48682</guid>
      <dc:creator>rodrigohbm</dc:creator>
      <dc:date>2018-11-06T01:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Link DWG Files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/link-dwg-files/m-p/8751795#M48683</link>
      <description>&lt;P&gt;How can we achieve the same function in API 2017 for backwards compatibility?&lt;BR /&gt;&lt;BR /&gt;Understand that there is a method to use write transmission data.&lt;BR /&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2011/10/using-the-writetransmissiondata-method.html" target="_blank"&gt;https://thebuildingcoder.typepad.com/blog/2011/10/using-the-writetransmissiondata-method.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;However specifically for CAD files, the externalFileReferenceType does not show a CADLink, rather it shows a KeynoteTable / AssemblyCodeTable?&lt;BR /&gt;&lt;BR /&gt;Are these the correct reference type for CAD files?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2019 03:58:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/link-dwg-files/m-p/8751795#M48683</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-25T03:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: Link DWG Files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/link-dwg-files/m-p/8751949#M48684</link>
      <description>&lt;P&gt;You should use Document.Link() method to archive that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.revitapidocs.com/2018.2/f3112a35-91c2-7783-f346-8f21d7cb99b5.htm" target="_blank"&gt;http://www.revitapidocs.com/2018.2/f3112a35-91c2-7783-f346-8f21d7cb99b5.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.youtube.com/watch?v=kPmDk2V1v9g" target="_blank"&gt;https://www.youtube.com/watch?v=kPmDk2V1v9g&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;def link_em(view, ref):

    options = DB.DWGImportOptions()
    options.Unit = DB.ImportUnit.Millimeter
    options.Placement = DB.ImportPlacement.Origin
    options.ColorMode = DB.ImportColorMode.Preserved
    options.CustomScale = 0.0
    options.AutoCorrectAlmostVHLines = False
    options.ThisViewOnly = False
    options.OrientToView = False
    options.VisibleLayersOnly = True

    try:
        msg = 'Attemting to link file {} to view {}'\
            .format(op.split(ref)[-1], view.Name)
        print msg

        doc.Link(
            ref,
            options,
            view,
        )
    except Exception as e:
        msg = 'Fail when attemting to link file {} to view {}'\
            .format(op.split(ref)[-1], view.Name)
        boyexcept.INFO(msg)&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Apr 2019 06:49:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/link-dwg-files/m-p/8751949#M48684</guid>
      <dc:creator>chinh.trieutien</dc:creator>
      <dc:date>2019-04-25T06:49:31Z</dc:date>
    </item>
  </channel>
</rss>

