Create CAD Link

Create CAD Link

pmeigneux
Advocate Advocate
846 Views
3 Replies
Message 1 of 4

Create CAD Link

pmeigneux
Advocate
Advocate

Hi,

 

How Create DGN Link ?

 

this code don't work..

 

if (Suffix == ".dgn")
{
    DGNImportOptions DGNopt = new DGNImportOptions();
    if (Doc.ActiveView != null)
        Doc.Link(NewDocPathname, DGNopt, Doc.ActiveView, out ElemId);
    else
    {
        TaskDialog.Show(EnoviaAddPanel.ErrorText, EnoviaAddPanel.InsertNOView);
        ParentTransaction.RollBack();
        return Autodesk.Revit.UI.Result.Failed;
    }
}

 

How Create SKP Link ?

 

this code don't work..

 

if (Suffix == ".skp")
{
    SKPImportOptions SKPopt = new SKPImportOptions();
    if (Doc.ActiveView != null)
        Doc.Link(NewDocPathname, SKPopt, Doc.ActiveView);
    else
    {
        TaskDialog.Show(EnoviaAddPanel.ErrorText, EnoviaAddPanel.InsertNOView);
        ParentTransaction.RollBack();
        return Autodesk.Revit.UI.Result.Failed;
}

 

Philippe.

0 Likes
847 Views
3 Replies
Replies (3)
Message 2 of 4

aricke59
Enthusiast
Enthusiast

The code you have shown looks like it should work.

 

I would check to make sure the file referred to by newDocPathname exists (perhaps try something really simple).

 

Of course make sure the transaction "ParentTransaction" has been started and correctly committed. Depending on the release of Revit transactions are no longer automatic and need to be fully defined.

 

Also make sure that "Doc" is correctly defined.

 

I use VB so I would also consider putting in a try/catch around the doc.link command.

0 Likes
Message 3 of 4

pmeigneux
Advocate
Advocate

no , don't work..

sorry.

 

Philippe.

0 Likes
Message 4 of 4

pmeigneux
Advocate
Advocate

Hi,

 

This work for all link except DGN Link...

 

Please help me.

 

               Transaction ParentTransaction = new Transaction(Doc);
               ParentTransaction.Start("Create Link");
               // Create Linked
               try
               {
                   String Suffix = Path.GetExtension(NewDocPathname).ToLower();
                   ElementId ElemId;
                   if ((Suffix != ".rvt") && (Suffix != ".ifc"))
                   {
                       if (Doc.ActiveView != null)
                       {
                           if (!Doc.ActiveView.CanBePrinted)
                           {
                               TaskDialog.Show("error", "NoPrintableView");
                               ParentTransaction.RollBack();
                               return Autodesk.Revit.UI.Result.Failed;
                           }
                       }
                       else
                       {
                           TaskDialog.Show("Error"t, "InsertNOView");
                           ParentTransaction.RollBack();
                           return Autodesk.Revit.UI.Result.Failed;
                       }
                       if ((Suffix == ".dwg") || (Suffix == ".dxf"))
                       {
                           DWGImportOptions DWGopt = new DWGImportOptions();
                           if (!Doc.Link(NewDocPathname, DWGopt, Doc.ActiveView, out ElemId))
                           {
                               TaskDialog.Show("Error","ErrorInsert");
                               ParentTransaction.RollBack();
                               return Autodesk.Revit.UI.Result.Failed;
                           }
                       }
                       else if (Suffix == ".dgn")
                       {
                           DGNImportOptions DGNopt = new DGNImportOptions();
                           DGNopt.DGNModelViewName = Path.GetFileName(NewDocPathname) + "-Model";
#if false
                           DGNopt.AutoCorrectAlmostVHLines = true;
                           DGNopt.ColorMode = ImportColorMode.Preserved;
                           DGNopt.Unit = ImportUnit.Default;
                           DGNopt.CustomScale = 1.0;
                           DGNopt.OrientToView = true;
                           DGNopt.Placement = ImportPlacement.Origin;
                           DGNopt.IgnoreUnsupportedElementWarning = false;
                           DGNopt.ThisViewOnly = false;
#endif
                           if (!Doc.Link(NewDocPathname, DGNopt, Doc.ActiveView, out ElemId)) <== Return always False
                           {
                               TaskDialog.Show("Error", "ErrorInsert");
                               ParentTransaction.RollBack();
                               return Autodesk.Revit.UI.Result.Failed;
                           }
                       }
                       else if ((Suffix == ".dwf") || (Suffix == ".dwfx"))
                       {
                           if (Doc.ActiveView.ViewType == ViewType.DrawingSheet)
                           {
                               IList<ElementId> ListView = new List<ElementId>();
                               ListView.Add(Doc.ActiveView.Id);
                               DWFImportOptions DWFopt = new DWFImportOptions(ListView);
                               Doc.Link(NewDocPathname, DWFopt);
                           }
                           else
                           {
                               TaskDialog.Show("Error", "InsertNOView");
                               ParentTransaction.RollBack();
                               return Autodesk.Revit.UI.Result.Failed;
                           }
                       }
                       else if (Suffix == ".sat")
                       {
                           SATImportOptions SATopt = new SATImportOptions();
                           Doc.Link(NewDocPathname, SATopt, Doc.ActiveView);
                       }
                       else if (Suffix == ".skp")
                       {
                           SKPImportOptions SKPopt = new SKPImportOptions();
                           Doc.Link(NewDocPathname, SKPopt, Doc.ActiveView);
                       }
                   }
                   else
                   {
                       ModelPath mp = ModelPathUtils.ConvertUserVisiblePathToModelPath(NewDocPathname);
                       RevitLinkOptions rlo = new RevitLinkOptions(true);
#if !RVT_2018
                       RevitLinkLoadResult linkType;
#else
                       LinkLoadResult linkType;
#endif
                       if (Suffix == ".ifc")
                       {
                           String NewDocRevitPathname = NewDocPathname + ".RVT";
                           Document DocIFC = revit.Application.Application.OpenIFCDocument(NewDocPathname);
                           SaveAsOptions SaveOpt = new SaveAsOptions();
                           SaveOpt.OverwriteExistingFile = true;
                           DocIFC.SaveAs(NewDocRevitPathname, SaveOpt);
                           DocIFC.Close();

#if !RVT_2018
                           RevitLinkLoadResult LoadlinkType = RevitLinkType.CreateFromIFC(Doc, NewDocPathname, NewDocRevitPathname, true, rlo);
#else
                           LinkLoadResult LoadlinkType = RevitLinkType.CreateFromIFC(Doc, NewDocPathname, NewDocRevitPathname, true, rlo);
#endif
                           RevitLinkInstance instance = RevitLinkInstance.Create(Doc, LoadlinkType.ElementId);
                       }
                       else
                       {
                           linkType = RevitLinkType.Create(Doc, mp, rlo);
                           RevitLinkInstance instance = RevitLinkInstance.Create(Doc, linkType.ElementId);
                           RevitLinkType rvtType = Doc.GetElement(instance.GetTypeId()) as RevitLinkType;

                           rvtType.AttachmentType = AttachmentType.Attachment;
                       }
                   }
                   Doc.Regenerate();

                   ParentTransaction.Commit();
               }
               catch (Autodesk.Revit.Exceptions.ArgumentNullException e)
               {
                   TaskDialog.Show("Error", "ErrorInsert  :" + e);
                   ParentTransaction.RollBack();
                   return Autodesk.Revit.UI.Result.Failed;
               }
               catch (Autodesk.Revit.Exceptions.ArgumentException e)
               {
                   TaskDialog.Show("Error", "ErrorInsert :" + e);
                   ParentTransaction.RollBack();
                   return Autodesk.Revit.UI.Result.Failed;
               }
               catch (Autodesk.Revit.Exceptions.ModificationForbiddenException e)
               {
                   TaskDialog.Show("Error", "ErrorInsert :" + e);
                   ParentTransaction.RollBack();
                   return Autodesk.Revit.UI.Result.Failed;
               }
           }

 

Doc.Link(NewDocPathname, DGNopt, Doc.ActiveView, out ElemId)) <== Return always False

 

Philippe.

0 Likes